.NET Quickstart: Replying to Text Messages By Name

Ok, we've said "Hello" to the mobile monkey, but what if the monkey wants to say, "Thanks" back? Let's lookup the sender, and thank them for sending us a message by name if we can:

@using Twilio;
    // make an associative array of senders we know, indexed by phone number
    var people = new Dictionary<string,string>() { 
        {"+14158675309","Curious George"},

    // if the sender is known, then greet them by name
    // otherwise, consider them just another monkey
    string name = "Monkey";
    if (!string.IsNullOrEmpty(Request["From"]))
        name = people[Request["From"]];

    // now greet the sender
    Response.ContentType= "text/xml";
<?xml version="1.0" encoding="UTF-8"?>
    <Message>@name, thanks for the message!</Message>

If you add your phone number and name to the people Dictionary you will get a personalized SMS thank-you from your app.

Next: Sending SMS and MMS Messages via the REST API »

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.