Search code examples
twilioserverlesstwilio-taskrouter

Twilio TaskRouter Serverless Reservation Function


Has anyone completed or found a guide on routing/ accepting a task router reservation?

Example flow:

Call # > picked up by Twilio Studio and enqueued to TaskRouter Workspace with attributes > task router workflow associates to a taskrouter queue and finds available agent > [i need to connect this call to the workers attribute which is their sip:phonenumber

I'm trying to avoid an aws server and lambda while keeping this entire orchestration native to twilio via function.


Solution

  • Twilio developer evangelist here.

    The docs on dealing with the TaskRouter reservation callback are here. When you receive the callback you need to respond with JSON describing the action you want to do.

    The simplest instruction to connect the call from task to the worker that receives the reservation is to use the dequeue instruction. In a Twilio Function that would look like this:

    exports.handler = function (context, event, callback) {
      callback(null, {
        instruction: "dequeue"
      });
    }
    

    To make this connect, your worker needs a contact_uri attribute that points to their address, in this case their SIP phone number. Alternatively, you can add a to attribute to the dequeue instruction with the address.