使用 Twilio Functions 的 Twilio 寻线组.(又名 FindMe ) [英] Hunt Group for Twilio, using Twilio Functions. (aka FindMe )

查看:30
本文介绍了使用 Twilio Functions 的 Twilio 寻线组.(又名 FindMe )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to set up a hunt group with Twilio Twiml

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

Do I have to set up a different twimlbin for each number in the hunt group?

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

Or is there a way to join all this together into a single 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 开发人员布道者在这里.

Twilio developer evangelist here.

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

TwiML Bins are great for static bits of TwiML, but your use case needs a bit more than that.

我建议您查看 Twilio Functions,它允许您在 Twilio 的基础架构中运行 Node.js 代码.我已经构建并测试了一个适用于 Twilio Functions 的版本.

I recommend you check out 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.

以下是其工作原理的说明:

Here's an explanation of how it works:

从你的数字数组开始:

const numbers = [...];

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

Then, in the function, check if the callstatus is completed and hang up if it is.

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 中有下一个数字.如果你确实将它保存到一个变量中,否则选择数组中的第一个数字:

If it's not, we work out the next number to call. If you have the next number in the URL. If you do save it to a variable, otherwise pick the first number in the array:

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

然后,从阵列中分配下一个要拨打的号码.

Then, assign the next number to dial from the array.

    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 以跟踪状态.

Then generate the TwiML to Dial the next number and pass the URL as the action. You can add your own URL as the statusCallbackUrl to keep a track of the statuses.

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

  callback(null, response);
}

我不能保证这会奏效,但我希望你明白我的打算.如果有帮助,请告诉我.

I can't promise this will work, but I hope you see where I'm going with it. Let me know if it helps at all.

这篇关于使用 Twilio Functions 的 Twilio 寻线组.(又名 FindMe )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆