简体   繁体   English

如何使用Twilio功能重复消息?

[英]How to use Twilio function to repeat the message?

Here is my code 这是我的代码

exports.handler = function(context, event, callback) {
  let twiml = new Twilio.twiml.VoiceResponse();
  twiml.gather({ numdigit:"1", tiemout:"5"}).say("some message , press 9 to repeat");

  if(event.numdigit === 9)
  {
      twiml.repeat;
  }
  else if(event.numdigit != 9){
      twiml.say("soory");
  }
  callback(null, twiml);
};

I am new to twilio functions. 我是twilio函数的新手。 I have gone through the docs but cannot find anything regarding this. 我已经浏览了文档,但是找不到任何有关此的内容。

When ever I am calling to the number "some message, press 9 to repeat" this is said but I want to repeat the message when 9 is pressed and should play sorry when number other then 9 is pressed 每当我打给电话号码“某些消息,请按9重复”时,都会这样说,但是我想在按9时重播消息,而在按9以外的数字时应该打抱歉

Currently if I pressed number other then 9 then also the same message is playing. 当前,如果我按数字以外的数字,然后按9,则还会播放相同的消息。 If i do press any thing then it goes to "sorry" 如果我确实按了任何东西,那么它将变成“对不起”

Can anyone suggest the solution 谁能建议解决方案

Twilio developer evangelist here. Twilio开发人员布道者在这里。

What may be confusing here is that this Function is actually called twice as part of your call. 在这里可能令人困惑的是,此函数实际上是在调用过程中被两次调用的。

<Gather> works like this: when the user enters the digit Twilio makes a new HTTP request with the Digits parameter to either the <Gather> action attribute or by default to the same URL as the current response. <Gather>工作方式如下:当用户输入数字时,Twilio使用Digits参数将新的HTTP请求发送给<Gather> action属性,或者默认情况下使用与当前响应相同的URL。 In your case, this means it will request the same Twilio function again. 在您的情况下,这意味着它将再次请求相同的Twilio函数。

There is no TwiML to repeat, so we need to say the same thing again. 没有重复的TwiML,所以我们需要再说一遍。 Here's an example of how to achieve that, by returning the same TwiML for the initial request and for any request where the Digits parameter is not "9": 这是如何通过为初始请求和Digits参数不是“ 9”的任何请求返回相同的TwiML来实现此目的的示例:

exports.handler = function(context, event, callback) {
  const message = "some message , press 9 to repeat";
  const gatherOptions = { numdigit:"1", tiemout:"5"};
  let twiml = new Twilio.twiml.VoiceResponse();

  if (event.Digits) {
    if(event.Digits === '9') {
      twiml.gather(gatherOptions).say(message);
    } else {
      twiml.say("sorry");
    }
  } else {
    twiml.gather(gatherOptions).say(message);
  }
  callback(null, twiml);
};

Let me know if that helps. 让我知道是否有帮助。

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

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