Home > Uncategorized > Handling inbound voice calls & inbound #SMS with #Twilio

Handling inbound voice calls & inbound #SMS with #Twilio

twilio

For $1 a month, you can “buy” a phone number from twilio, and with that, you can intercept inbound SMS AND voice calls to that number. I’ve only started to experiment with this, but I set up a web hook and captured the Querystring to see what happens when you SMS the number, and when you call it.

These are the querystring variables (I’ve put XXXX on some sensitive data)

SMS:

?ToCountry=US
&ToState=FL
&SmsMessageSid=SM3cabdc50b56a945867a5ff92bd663797
&NumMedia=0
&ToCity=
&FromZip=
&SmsSid=SM3cabdc50b56a945867a5ff92bd663797
&FromState=
&SmsStatus=received
&FromCity=
&Body=Test+inbound+sms
&FromCountry=GB
&To=%2B123930xXXXX
&ToZip=
&NumSegments=1
&MessageSid=SM3cabdc50b56a945867a5ff92bd663797
&AccountSid=AC84d144631d43d12966be8c03e2c6a640
&From=%2B44786XXXXXXX
&ApiVersion=2010-04-01

VOICE:

?Called=%2B123XXXXXXX
&ToState=FL
&CallerCountry=GB
&Direction=inbound
&CallerState=
&ToZip=
&CallSid=CAd8a28a1a98844f1c38d8ea68ce2ef8f6
&To=%2B12393XXXXXX
&CallerZip=
&ToCountry=US
&ApiVersion=2010-04-01
&CalledZip=
&CalledCity=
&CallStatus=ringing
&From=%2B44786XXXXXX
&AccountSid=AC84d144631d43d12966be8c03e2c6a640
&CalledCountry=US
&CallerCity=
&Caller=%2B447866XXXXXX
&FromCountry=GB
&ToCity=
&FromCity=
&CalledState=FL
&FromZip=
&FromState=

Sending SMS via C# is easy done via their library, but If you want to use WebClient, or an older version of .NET, you can use a HTTP post as follows;

However, of course you’d always prefer to use www.freebiesms.co.uk ! 🙂

/*https://www.twilio.com/docs/api/rest/sending-messages*/
string strUrl = “https://api.twilio.com/2010-04-01/Accounts/” + username + “/Messages.json”;
string strPostdata = “To=” + HttpUtility.UrlEncode(“+” + To);
strPostdata += “&From=12XXXXXXXX”;
strPostdata += “&Body=” + ISOEncode(Message);
WebClient wc = new WebClient();
wc.Headers[“Content-Type”] = “application/x-www-form-urlencoded”;
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + “:” + password));
wc.Headers[HttpRequestHeader.Authorization] = string.Format(
“Basic {0}”, credentials);
string strStatus = “”;
try
{
strStatus = wc.UploadString(strUrl, strPostdata);
}
catch (WebException ex)
{
strStatus = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: