twiliotwilio-programmable-chattwilio-taskrouter

Twilio TaskRouter - ordering workers by assigned_tasks


I'm passing by an issue on my Twilio TaskRouter configuration. The thing is that I need to address an incoming task to the worker who has lesser tasks assigned to him/her, not to the longest idle worker (as is the default).

According to Twilio's multitasking documentation, each worker has an assigned_tasks attribute inside their channels. So, I have tried to use this attribute into my order_by clause but it seems not to be working.

{
  "task_routing": {
    "filters": [
      {
        "filter_friendly_name": "Worker Filter",
        "expression": "transferTargetType == 'worker'",
        "targets": [
          {
            "queue": "WQXXXXX",
            "expression": "worker.sid == task.targetSid",
            "timeout": 30,
            "skip_if": "workers.available == 0"
          },
          {
            "queue": "WQXXXXX",
            "timeout": 0,
            "skip_if": "workers.available == 0"
          }
        ]
      },
      {
        "filter_friendly_name": "Ordered",
        "expression": "1==1",
        "targets": [
          {
            "queue": "WQXXXXX",
            "order_by": "worker.channel.chat.assigned_tasks ASC",
            "skip_if": "workers.available == 0"
          }
        ]
      }
    ],
    "default_filter": {
      "queue": "WQXXXXX"
    }
  }
}

It's important to say that my first filter is not being triggered in this scenario because I'm not passing the transferTargetType attribute.

Any idea why this is not working?

Thanks :D


Solution

  • According to Twilio's Support, it's not possible to order my workers by their number of task assignments. Instead of this, they advised me to create lots of filter steps based on a specific value for this worker attribute.

    So, this is my workflow now:

    {
      "task_routing": {
        "filters": [
          {
            "filter_friendly_name": "Ordered",
            "expression": "1==1",
            "targets": [
              {
                "queue": "WQXXXXXXXXX",
                "expression": "worker.channel.chat.assigned_tasks == 0",
                "skip_if": "1==1"
              },
              {
                "queue": "WQXXXXXXXXX",
                "expression": "worker.channel.chat.assigned_tasks == 1",
                "skip_if": "1==1"
              },
              {
                "queue": "WQXXXXXXXXX",
                "expression": "worker.channel.chat.assigned_tasks == 2",
                "skip_if": "1==1"
              },
              {
                "queue": "WQXXXXXXXXX",
                "expression": "worker.channel.chat.assigned_tasks == 3",
                "skip_if": "1==1"
              },
              {
                "queue": "WQXXXXXXXXX",
                "expression": "worker.channel.chat.assigned_tasks == 4",
                "skip_if": "1==1"
              },
              ...
            ]
          },
          {
            "filter_friendly_name": "Anybody",
            "expression": "1==1",
            "targets": [
              {
                "queue": "WQXXXXXXXXX"
              }
            ]
          }
        ],
        "default_filter": {
          "queue": "WQXXXXXXXXX"
        }
      }
    }