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

别来无恙 提交于 2019-12-29 02:08:10

问题


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

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

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 ...

Thank you :-)


回答1:


Twilio developer evangelist here.

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

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:

Start with an array of your numbers:

const numbers = [...];

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 {

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);
    }

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.



来源:https://stackoverflow.com/questions/45305060/hunt-group-for-twilio-using-twilio-functions-aka-findme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!