-6

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"?

svick
  • 236,525
  • 50
  • 385
  • 514
  • 3
    var guid = Guid.NewGuid(); Joking aside; seems like you might want to do some more research before asking this question. In my opinion, this is fairly basic knowledge. (String concatination and generating a random of some kind). – Nicklas Pouey-Winger Mar 11 '15 at 07:45
  • 3
    This is indeed a very basic question. You really should spend some time learning the basics of C#. Take a look at https://msdn.microsoft.com/en-us/vstudio/hh341490.aspx and http://www.learncs.org/ or read some C# book. Btw the code to generate such a message: var mssage = String.Format( "Hey this is your access code {0}", new Random().Next( 100000, 1000000 ) ); (If possible always use the same instance of the random class.) Be carefully random numbers are not really random numbers! – musium Mar 11 '15 at 08:40
  • 1
    @user2384352 Well if this is not a question about how to get such a string/message, but how to use an API, you should not add a C# tag to the question. Btw. Take a look at https://www.twilio.com/docs/quickstart/csharp/sms/sending-via-rest they do exactly the same. Do your homework, learn some C# basics and read the docs. – musium Mar 11 '15 at 15:07

1 Answers1

0

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:

<Response>
    <Message>Hey this is your access code [YOUR_RANDOM_NUMBER]</Message>
</Response>

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.

Devin Rader
  • 10,260
  • 1
  • 20
  • 32
  • It seems using in `android` app we can [auto](https://developers.google.com/identity/sms-retriever/overview) detect `OTP` and fill text box for two factor verification. Would like to know, is it possible using `Twilio` in wep app ? and can you answer [this](https://stackoverflow.com/questions/48201215/how-to-read-otp-from-mobile-website) question. – Shaiju T Jan 15 '18 at 05:25