Friday, 11 August 2017

asp.net mvc 3 - Generate random number using c# and send voice call through twilio




I know how to generate a random number in C#. I read some article, How to send voice mail in Twilio. But my problem needs to send the message like this



"Hey this is your access code 123456"



The number 123456 will be different for different user.



How do I generate dynamic "Hey this is your access code 123456"?


Answer




Twilio evangelist here.



How you do this depends on whether or not you are responding to an inbound text message or initiating a new message to send to a user.



If its the former, you can use TwiML to tell Twilio how to respond to the inbound message. IN your case that TwiML would look like this:




Hey this is your access code [YOUR_RANDOM_NUMBER]




If its the latter, you can use the Twilio C# helper library to send the message:



// instantiate a new Twilio Rest Client
var client = new TwilioRestClient(AccountSid, AuthToken);
client.SendMessage(
"YYY-YYY-YYYY", // From number, must be an SMS-enabled Twilio number
person.Key, // To number, if using Sandbox see note above
string.Format("Hey this is your access code {0}","[YOUR_RANDOM_NUMBER]")
);



I'd suggest checking out our Quickstarts which will walk you through the basics of sending and receiving SMS messsages and making and receiving phone calls using C#:



https://www.twilio.com/docs/quickstart/csharp/sms/hello-monkey



Hope that helps.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...