简体   繁体   English

twilio 如何在 10 秒后使用 c# 关闭呼叫

[英]twilio how to turn off a call after 10 seconds with c#

turn off a call after 10 seconds or 3 extension number -( if they enter the wrong number for 3 times) with c#使用 c# 在 10 秒或 3 个分机号码后关闭呼叫-(如果他们输入错误的号码 3 次)

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

someone can help ?有人可以帮忙吗?

Twilio evangelist here. Twilio 布道者在这里。

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:因此,为了确保我理解,您已经使用<Gather>要求用户输入一个 3 位数的代码,并且您想在发生以下任一情况时挂断电话:

  • No input from the user for 10 seconds 10 秒内没有用户输入
  • After three invalid entries在三个无效条目之后

Lets tackle the first problem of hanging up after 10 seconds of no input.让我们解决 10 秒没有输入后挂断的第一个问题。 The <Gather> verb includes a timeout attribute that you can use to tell Twilio how long to wait for input. <Gather>动词包含一个超时属性,您可以使用该属性告诉 Twilio 等待输入的时间。 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.如果在此期间未提供任何输入,Twilio 实际上不会调用操作URL,而是通过<Gather>并且如果在它执行之后还有另一个动词。 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.在此示例中,如果调用者输入数字,将请求 action 参数中指定的 url,并且 Twilio 将停止执行此响应中的任何其他 TwiML 动词。

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.但是,如果调用者没有输入任何数字,Twilio 将不会调用操作 URL,而是会移动到此响应中的下一个动词,即<Say>动词。

You could just as easily put the <Hangup> verb in the response in order to hang up on the caller:您可以轻松地将<Hangup>动词放在响应中以便挂断来电者:

<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.现在,只要允许来电者有 3 次机会输入正确的代码,那也很容易。 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.请注意,在代码片段中,我向操作 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:当用户输入数字并且 Twilio 调用我的操作 URL 时,它将包含此查询字符串值,如果我的应用程序确定调用者输入了错误的代码,我只需增加该计数器并在 TwiML 中发出新的计数器值,然后返回给 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.希望有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM