Friday, December 19, 2014

Twilio API Integration for sending SMS and List of Sent SMS


Now, you can send SMS using Twilio API easily by just following the few Steps:
Steps:
1.  Login in to the http://www.twilio.com and if you are not user then sign in.
2.  Now Open Visual Studio and start your project and download twilio and twilioML library from NuGet package installer.
3.  After Login in twilio it will gives you a “ACCOUNT SID” and “AUTH TOKEN” and also “TELEPHONE NUMBER”. Save this credentials and apply in our project as..
//you have to add namespace for twilio as like,
using twilio.com;
//and Now apply that Credentials in to our project..
String AccountSid  "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Account ID..
String AuthToken  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"; // Authentication Tocken.. 
String TelephoneNo  'NNNNNNNNNN'; // Telephone No from the message will sent.
Now, Create Instance of Twilio Rest Client..
var client newTwilioRestClient($AccountSid$AuthToken);
Now, Call the Method SendSmsMessage(“Sender No with country Code”, “Receiver No with Country Code”, “Message Body…”) for sending SMS. as like,
cvar sendsms = client.sendSmsMessage(from,to,msg);
Done…. Yuppp…
Your Project is Working…..
* Note:
You can also set Validation on that like “Message length should not be greater than 160 Characters.. etc.”

Now, You can easily manage sent message list..
as below,
public SMSMessage getMessageList(String to, String from)
{
String AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Account ID..
String AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"; // Authentication Tocken..
var client = new TwilioRestClient(AccountSid,AuthToken);
SmsMessageResult msgs = postMaster.ListSmsMessages();
List msg = msgs.SMSMessages;
foreach (var smsmsg in msgs.SMSMessages)
{
 if (smsmsg.Status == “received” && smsmsg.From == from && smsmsg.To == to)
{
  return smsmsg;
}
}
 return null;
}

1 comments:

Post a Comment