0

I'm trying to create a POC for a friend using twilio. The POC consists of 2 things

1

Present text box for phone number Call number using Twilio Record and transcribe call for 10 seconds Present transcription and link to recording on web page End

2

Present text box for phone number Call number using Twilio Listen for digits (DTMF) Display digits pressed on web page End

I think I have #1 but im kind of stuck on #2. So i have a webform proj that has 1 webform page with a textbox and a submit button that calls twillio.

Code

 protected void btnSubmit2_Click(object sender, EventArgs e)

    {
        var twilio = new TwilioRestClient(AccountSid, AuthToken); 

        var options = new CallOptions();

        options.Url = "http://servername/TwilioHandler.ashx"; // this needs to get replaced by DB Public url

        options.From = "+17143505676"; // Number that its calling from

        options.To = txtBox2.Text; // Number that its calling to

        options.Record = true;

        var call = twilio.InitiateOutboundCall(options);
      
        if (call.RestException == null)
            lblStartTime.Text = string.Format("Started call: {0}", call.Sid);
        else
            lblEror.Text = string.Format("Error: {0}", call.RestException.Message);
    }

the code above basically makes a call to my cell phone.

The TwilioHandler.ashx code

public void ProcessRequest(HttpContext context)
{
        context.Response.ContentType = "application/xml";

        TwilioResponse twiml = new TwilioResponse();
        twiml.Say("Hi Jeff Berney, Please enter something.");

        string digits = context.Request["Digits"] ?? String.Empty;
       
        if (digits == String.Empty)
        {
            twiml.BeginGather(new
            {
                action = "http://servername/Twilio.aspx",
                numDigits = "1",
                method = "GET"
            });
            twiml.Say("To check the status of an order, press one");
            twiml.Say("To receive automated status updates via text message, press two");
            twiml.Say("To speak with a customer service representative, press three");
            twiml.EndGather();
            twiml.Say("Goodbye");
            twiml.Hangup();
        }

        if (digits == "1")
            twiml.Redirect("Twilio.aspx?Digits=1", "GET");
            //twiml.Say("you pressed one");
        if (digits == "2")
            twiml.Redirect("Twilio.aspx?Digits=2", "GET");
           // twiml.Say("you pressed two");
        if (digits == "3")
            twiml.Redirect("Twilio.aspx?Digits=3", "GET");
            //twiml.Say("you pressed three");
        if (digits == "4")
            twiml.Redirect("Twilio.aspx?Digits=4", "GET");
            //twiml.Say("you pressed four");
        if (digits == "5")
            twiml.Redirect("Twilio.aspx?Digits=5", "GET");
            //twiml.Say("you pressed five");
   
        context.Response.Write(twiml.ToString());
    
    }

This code listens for the user input from the phone and send it back to Twilio.aspx page..My problem is that I need to display that Digit back to the Twilio.aspx page ...but i cant. I tried refreshing the page but that doesnt work.

Any guidance will be helpful.

Community
  • 1
  • 1
  • Hi, Twilio developer evangelist here. Are you able to check that Twilio is indeed making the requests to your pages passing the `Digits` argument when the numbers are dialed? If so, what is in `Twilio.aspx`? – Marcos Placona Aug 18 '15 at 09:49
  • Hi Marcos Placona - Yes im able to check and I see that it makes the request to Twilio.aspx... On the page load event it checks if the Request["Digits"] is not null..then it parses the digits and binds it to the label control. – jberney22 Aug 18 '15 at 14:59
  • Ok, so you just described what I thought it wasn't doing. Can you please be a bit more specific as to what you want it to do? I though the whole "On the page load event it checks if the Request["Digits"] is not null..then it parses the digits and binds it to the label control" wasn't happening. – Marcos Placona Aug 18 '15 at 15:38
  • All i want it to do is just display the digits that was pressed. – jberney22 Aug 18 '15 at 20:45

0 Answers0