Twilio 寻线组,使用 Twilio 函数。 (又名 FindMe )

Hunt Group for Twilio, using Twilio Functions. (aka FindMe )

我正在尝试使用 Twilio Twiml 设置寻线组

是否必须为寻线组中的每个号码设置不同的 twimlbin?

或者有没有办法将所有这些连接到一个 Twimlbin 中?

Twimlbin 1:
<Response>
    <Dial 
         action="http://www.ourapp.com/webhook;FailUrl=/Twimlbin 2" 
         timeout="10" 
         callerId="555-555-5555">
         NUMBER1
    </Dial>
</Response>


Twimlbin 2:
<Response>
    <Dial 
         action="http://www.ourapp.com/webhook;FailUrl=/Twimlbin 3" 
         timeout="10" 
         callerId="555-555-5555">
         NUMBER2
    </Dial>
</Response>

... Repeat N times for each agent ...

谢谢 :-)

这里是 Twilio 开发人员布道者。

TwiML Bins 非常适合 TwiML 的静态位,但您的用例需要的不止于此。

我建议您查看 Twilio Functions which allow you to run Node.js code in Twilio's infrastructure. I've built and tested a version of this that works with Twilio Functions

以下是对其工作原理的解释:

从你的数字数组开始:

const numbers = [...];

然后在函数中,检查callstatus是否完成,如果是则挂断。

exports.handler = function(context, event, callback) {
  const response = new Twilio.twiml.VoiceResponse();
  if (event.DialCallStatus === "complete" || event.finished) {
    // Call was answered and completed or no one picked up
    response.hangup();
  } else {

如果不是,我们会计算出下一个要呼叫的号码。如果你有URL中的下一个数字。如果你确实将它保存到一个变量中,否则选择数组中的第一个数字:

    const numberToDial = event.nextNumber ? event.nextNumber : numbers[0];

然后,从数组中指定要拨打的下一个号码。

    let url;
    const currentNumberIndex = numbers.indexOf(numberToDial);
    if (currentNumberIndex + 1 === numbers.length) {
      // no more numbers to call after this.
      url = "/hunt?finished=true";
    } else {
      const nextNumber = numbers[currentNumberIndex + 1];
      url = "/hunt?nextNumber=" + encodeURIComponent(nextNumber);
    }

然后生成 TwiML 以拨打下一个号码并传递 URL 作为操作。您可以添加自己的 URL 作为 statusCallbackUrl 以跟踪状态。

    const dial = response.dial({ action: url });
    dial.number({ statusCallback: "https://yourapp.com/statuscallback" }, numberToDial);
  }

  callback(null, response);
}

我不能保证这会奏效,但我希望你明白我要用它做什么。让我知道是否有帮助。