2

I'm using Twilio's TasksRouter.

I have 3 TaskQueues in my workspace and new tasks are being forwarded to the correct TaskQueue but I would also like them to be offered to a specific worker in that queue.

I thought that the task attributes are supposed to do that but even when my task has attributes such as {user_id: 123} the task is still offered to a worker with attributes like {user_id: 999}

Is that the correct approach? How else can I offer a task to a specific worker?

Thanks!

Leo
  • 900
  • 1
  • 11
  • 26
  • 1
    Hey Leo, have you put a condition in your [workflow](https://www.twilio.com/docs/taskrouter/lifecycle-task-workflows-and-assignment) to assign tasks based on a `user_id` attribute? – philnash Oct 28 '18 at 23:22
  • I totally missed that! Thanks a lot for pointing this out. Please submit an answer if you'd like - I'll mark it accepted. – Leo Oct 29 '18 at 08:30

3 Answers3

3

Twilio developer evangelist here.

In order to send a task to a specific worker you need to set up a condition in your TaskRouter workflow based on the user_id attribute that you have given the task. You can set it to match the attribute and direct the task to a queue that is manned by just that worker.

philnash
  • 70,667
  • 10
  • 60
  • 88
0

I did it by using the reservation.created event. I use the standard workflow and task queue and then programatically reject all reservations until the reservation is done with the right agent, then I accept it.

In the TaskRouter UI in the Twilkio console I added a webhook on the reservation.created event, pointing to my server. The request is then handles as follows:

@app.route('/hook/reservation', methods=['POST'])
def fn_th_reservation():

    task_attributes = json.loads(request.form['TaskAttributes'])
    channel_sid = task_attributes["channelSid"]
    worker_sid = request.form['WorkerSid']
    reservation_sid = request.form["ReservationSid"]
    workspace_sid = request.form["WorkspaceSid"]
    task_sid = request.form["TaskSid"]

    # implement app specific logic here. you can use channel_sid and
    # worker_sid to compare them to a mapping from you database for instance
    is_right_worker = ...

    reservation_status = 'accepted' if is_right_worker else 'rejected'

    client = Client(account_sid, auth_token)
    # accept or reject reservation
    reservation = client.taskrouter.workspaces(workspace_sid) \
        .tasks(task_sid).reservations(reservation_sid) \
        .update(reservation_status=reservation_status)

    print(reservation.worker_name)
    print(reservation.reservation_status)

    return('200')

just make sure that you don't create an inifinite loop by rejecting every worker

0

This also can be achieved by using known worker filter in your task workflow

Known Worker can be used if the Worker who should be targeted here is already known. Choose whether the Worker is identified by Worker friendly name or Worker SID. Provide the field in the Task attributes that holds the relevant information (e.g. “task.worker_friendly_name”).

enter image description here

pwaterz
  • 658
  • 5
  • 11