Send Formatted messages through Twilio - twilio

I want to know that how I can send formated messages through twilio .net api
Using .net library
So my requirements are like. also can I make use of html tags?
TwilioRestClient client;
client = new TwilioRestClient(accountSID, authToken);
string msg="Hi dalvir,
//line break
Welcome to my website.....
....
//line break
Thanks
<b>Support Team<b>
";
// Send an SMS message.
Message result = client.SendMessage(....);

Use %0a
For example:
"Body=Here is my first line%0aHere is my second line"
When sending outbound messages via the REST API without using a helper library, it is best to encode a new line character using URL encoding. In URL encoding, a new line character is encoded as %0a.
Here’s an example cURL script:
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
-d "To=+13105551234" \
-d "From=+12125555555" \
-d "Body=Here is my first line%0aHere is my second line" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
This example sends an outbound message from the sender (212) 555-1234 (+12125551234) to the recipient at (310) 555-5555 (+13105555555), and includes the following message:
Here is my first line
Here is my second line

Twilio developer evangelist here.
You can absolutely add line breaks in SMS messages. You can do so in the way you would normally include line breaks within .NET.
SMS messages do not support HTML tags though, so making text bold is not possible.

Related

Twilio call next person from queue using PHP Laravel

I have this code in laravel
$client->calls->create(
array(
'from'=> '+6326263667',
'to'=> ???,
'url'=> 'twilio bin url'
)
);
I don't know what to put in the "to" array. I'm copying the node version of this like:
client.calls.create({
from: from,
to: process.argv[2],
url: url
})`
it there any other way if not like this?
Twilio Developer Evangelist here.
The to field is expecting the telephone number (in E.164 format) you wish to call.
In your Node example there, process.argv[2] is referring to the first argument passed to a command line operation.
If you want to learn more, I recommend you check out the Programmable Voice Quickstart for PHP.

Twilio Not doing anything when receiving SMS

I'm creating a sample application that will post alerts to the website in the event of a hurricane or service outage. I'm not using Laravel.
I set the URL of the page in my account settings. The first time I sent a message I received a HTTP error that it had timed out without being given a reponse. I edited the XML and tried again.
I'm not getting anything in the database and I'm not getting the response. I also wrote a sample page that posts a value to see if it would work and it did. It posted it into the database and showed correctly formatted XML.
<?php
$response = 'This number cannot handle automated replies...';
$twiml1 = '<response><sms>';
$twiml2 = '</sms></response>';
require_once '../settings/db.php';
if (isset($_POST['body'])) {
$body = strip_tags($_POST['body']);
$sql = "INSERT INTO alerts (message) VALUES ('$body')";
$result = $db->query($sql);
if ($result) {
$response = 'Thanks. Your message was posted on the website.';
} else {
$response = 'There was a query error.';
}
}
header('Content-type: application/xml');
echo $twiml1;
echo $response;
echo $twiml2;
Twilio developer evangelist here.
Parameters that are sent via webhooks from Twilio are case sensitive and start with a capital letter. The text for an incoming message is sent as the Body parameter so checking for $_POST['body'] won't work.
I'd update your conditional to:
if (isset($_POST['Body'])) {
$body = strip_tags($_POST['Body']);
// The rest
}
Also, just to note, the <Sms> element has been deprecated. I'd use the <Message> element instead. The tags are case sensitive too, so I'd update the TwiML section to this:
$twiml1 = '<Response><Message>';
$twiml2 = '</Message></Response>';
Let me know if that helps at all.

How to get youtube channel id using channel custom name?

My question is very similar to this one,
I want to get channel id using channel custom name.
The answer on the question mentioned above which is:
GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=annacavalli&type=channel&key={YOUR_API_KEY}
doesn't work on small channels, for ex. when I run it with this channel: https://www.youtube.com/AnnaShearerfashionfettish it returns nothing.
It's very easy, using curl and grep.
Command
channel_name='DOVASYNDROMEYouTubeOfficial' #change this as you like
curl --silent "https://www.youtube.com/c/${channel_name}/videos" |\
grep -o -P '(?<=canonical" href="https://www.youtube.com/channel/)[^"]*'
Output
UCq15_9MvmxT1r2-LLjtkokg
I didn't find a direct way to do this. I did a GET request to get the channel page HTML and parse it.
I used Jsoup to parse the html response.
val doc = Jsoup.parseBodyFragment(body)
val links = doc.select("link[rel=canonical]")
val channelUrl = links.first().attributes().get("href")
Did you try
https://www.googleapis.com/youtube/v3/channels?part=snippetforUsername={username}&key={your key}
Remember to change {your key} to your API key, and {username} to the desired username.

Slack Incoming Web Hooks - Send message #channel

I am working with Slack API recently and my motive is to send a channel wide message at a certain time by calling a web hook provided by Slack Incoming Web hooks.
I created a web hook and got code from Slack as below
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hey, Its time for meeting!! <#G5CERWGRG|hep_test>", "link_names" : 1}' HOOK_URL
But i cannot notify all in the team by just sending #channel in the message as like we do in normal slack channel chat. If i send #channel in the curl message, it shows as text message in chat, and not as #channel link.
I even tried sending slack channel id <#G5CERWGRG|hep_test>, as shown in the above curl request. But the message posted isn't notifying all in the group.
Note : I want to keep my channel notification preference as it is (Notify only on mentions)
Note
The correct syntax for sending #channel messages is <!channel>.
So the correct curl command for your example should read:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hey, Its time for meeting!! <!channel>", "link_names" : 1}' HOOK_URL
See also here for reference in the official documentation. You can also try this out in the message builder.
Note that in order to overwrite the default channel for your webhook you need to also add the additional property channel with the channel name. That will however only work for webhooks created through custom integration, not for webhooks created by Slack apps.
See here for an example on how to overwrite the channel name.
For anyone else struggling to get this working, if you are using blocks, it looks like you need to have the <!channel> in the block content, and not in the text content.
The text key shows up in the notification and doesn't allow formatting, while the blocks do.
The chat.scheduleMessage method (https://api.slack.com/methods/chat.scheduleMessage) will accomplish the same thing.
You can use "link_names": True in your payload and use #name :
slack_data = {
'text': 'Hi #user, this is for you',
"icon_emoji": self._icon,
"username": sender,
"link_names": True
}

Twilio Response Class not found

I am new to Twilio. To learn the basics, I followed the instructions here:
https://www.twilio.com/docs/howto/walkthrough/click-to-call/php/laravel#12
At first, my phone would ring, and I would receive a generic message. Impressed, I upgraded my account. Now I receive a call where a voice says "We're sorry an application error has occurred."
I checked my Alerts in Twilio, and found Error: 12100 - Document parse failure
So I checked the url of my outbound.php and realized that there is a PHP error here. The error is
Fatal error: Class 'Response' not found in
/home/......./outbound.php on line 16
After some searching, I can't find anyone else discussing this same problem. Finally, the worst part, I can't even find any reference to a Response class in the Twilio Helper Library.
Here is my entire code block for the page in question.
<?php
error_reporting(E_ALL);
require_once 'twilio-library/Services/Twilio.php';
// A message for Twilio's TTS engine to repeat
$sayMessage = 'Thanks for contacting our sales department. If this were a
real click to call application, we would redirect your call to our
sales team right now using the Dial tag.';
$twiml = new Services_Twilio_Twiml();
$twiml->say($sayMessage, array('voice' => 'alice'));
// $response->dial('+12345675309');
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
?>
If I change this file to static, well formatted XML then the error stops.
Twilio developer evangelist here.
The tutorial you were following was based within the Laravel framework, which is where the Response class was expecting to come from.
If you are using the PHP TwiML builder in just a plain PHP file, you should be able to just print the $twiml. I'd probably add a Content-Type of text/xml as well, just to be safe. Like this:
<?php
error_reporting(E_ALL);
require_once 'twilio-library/Services/Twilio.php';
// A message for Twilio's TTS engine to repeat
$sayMessage = 'Thanks for contacting our sales department. If this were a
real click to call application, we would redirect your call to our
sales team right now using the Dial tag.';
$twiml = new Services_Twilio_Twiml();
$twiml->say($sayMessage, array('voice' => 'alice'));
// $twiml->dial('+12345675309');
header('Content-type: application/xml');
print $twiml;
?>
Let me know if this helps at all!

Resources