Domanda

turn off a call after 10 seconds or 3 extension number -( if they enter the wrong number for 3 times) with c#

if (Request.Form["Digits"] == null || Request.Form["Digits"] == "")
{
   response += twimlGatherDigits("nothing was entered"));
}

someone can help ?

È stato utile?

Soluzione

Twilio evangelist here.

So just to make sure I understand, you've used a <Gather> to ask the user to enter a 3-digit code and you want to hang up the call if either of the following happens:

  • No input from the user for 10 seconds
  • After three invalid entries

Lets tackle the first problem of hanging up after 10 seconds of no input. The <Gather> verb includes a timeout attribute that you can use to tell Twilio how long to wait for input. If during that period, no input is provided, Twilio will actually not call the action URL, instead we fall through the <Gather> and if there is another verb after it execute that. For example:

<Response>
    <Say>Please enter your three digit code:</Say>
    <Gather timeout="10" action="http://example.com/login/process" />
    <Say>I didn't here that.  Can you try entering you code again?</Say>
    <Redirect>http://example.com/login/start</Redirect>
</Response>

In this example, if the caller enters digits the url specified in the action parameter will be requested and Twilio will stop executing any other TwiML verbs in this response.

However if the caller does not enter any digits, Twilio will not call the action URL, and will instead move on to the next verb in this response, which is the <Say> verb.

You could just as easily put the <Hangup> verb in the response in order to hang up on the caller:

<Response>
    <Say>Please enter your three digit code:</Say>
    <Gather timeout="10" action="http://example.com/login/process" />
    <Say>I didn't here that.  Goodbye</Say>
    <Hangup />
</Response>

Now, as far as only allowing the caller three chances to enter a correct code, thats pretty easy as well. You can use querystring values to carry a counter value between each attempt. For example:

<Response>
    <Say>Please enter your three digit code:</Say>
    <Gather timeout="10" action="http://example.com/login/process?attempt=0" />
    <Say>I didn't here that.  Goodbye</Say>
    <Hangup />
</Response>

Notice in the snippet I've added a querystring value named attempt to the action URL. When the user enters digits and Twilio calls my action URL, it will include this querystring value and, if my app determines caller entered an incorrect code, I simply increment that counter and emit the new counter value in the TwiML I return to Twilio:

if (Request.Form["Digits"] != "123")
{
     int attempts = int.Parse(Request["attempt"]);
     attempts++;

     //generate the Gather TwiML and append the value
     // of the attempts variable to the action URL         
}

Does that make sense?

Hope that helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top