问题
I'm using Twilio Task Routing to route calls to available Workers
with a custom app UI built using TaskRouting.js.
Let's say I have 2 Idle Workers and a call comes in.
- UI shows a screen Accept or Reject on both workers' screens
- Worker 1 hits reject
- Worker 2 hits reject
- At this point, the task apparently goes back into the task routing queue and steps 2 and 3 are repeated.
After all workers rejected a call, how do I redirect it to voicemail instead?
回答1:
Twilio developer evangelist here.
I would achieve this by adding a new array attribute to your Task to record the SIDs of the workers that rejected the task. Then, when a worker rejects the reservation, adding to that attribute on the task.
Then you can add to your target expression:
worker.sid NOT IN task.rejected_workers
Once the task fails that expression, move it to a new queue that has one idle worker that rather than accepting reservations, just redirects the call off to some TwiML to <Record>
the voicemail.
Let me know if that helps at all.
Edit
Turned out that wasn't exactly the right way to achieve this as, even if the target worker expression doesn't match any workers the Task will wait until there's a timeout at the filter level they have got to. The way I've described is really useful if you want to ensure that the call isn't directed to the same worker twice.
So, instead I recommend you still keep the list of workers that have rejected the task and each time there is another rejection, evaluate the workers in the queue and whether your Task's attribute now covers all the workers, ie it has been rejected by everyone. If so, set another attribute, something like "totallyRejected": true
. Then, add to your original filter expression:
totallyRejected == false
Then, when a task has been totally rejected it will fail the expression and go on to the next filter.
来源:https://stackoverflow.com/questions/46044542/redirect-twilio-call-to-voicemail-if-all-workers-explicitly-rejected-the-reserva