Twilio Twiml 使用 gather, say 和 redirect 问题

Twilio Twiml use gather, say and redirect question

我正在尝试循环 a 并给客户 5 秒,然后再次重复提示,等待 5 秒,然后重定向到我的错误处理程序。文档中不清楚如何执行此操作。

我发现的是对当前 url 执行 then 的解决方案,但这只会不断循环,而不是我们想要的。我们需要在 n 次后停止。

 gather.say(
        'Please enter or say your 10 Digit Account number.',
            {voice: 'alice', language: 'en-GB'}
    );

    gather.pause({
        length: 5
    });

    twiml.redirect({
        method: 'POST',
    }, '/ivr/wager/account');

如果您打算使用 Twilio Studio,可以使用设置变量小部件作为计数器以及 Liquid Syntax 来递增计数器,否则您将需要维护自己的递增计数器,使用附加到您的重定向 URL 的 URL 查询参数。请参阅下面的 Twilio Function 代码。

Set Variables

exports.handler = function(context, event, callback) {
  
  let twiml = new Twilio.twiml.VoiceResponse();
  let counter = event.count || 0;
  
  if (counter < 3) {
    counter ++;
    let gather = twiml.gather({action: `https://anonymous-1234.twil.io/gatherLoopCheck`, input: ' dtmf',
    timeout: 3,
    numDigits: 1})
    .say("Please enter a digit");
    twiml.redirect(`https://anonymous-1234.twil.io/gatherLoopCheck?count=${counter}`);
  return callback(null, twiml);
  } else {
    twiml.say("You've reached the limit!");
    return callback(null, twiml);
  }
};