0

This question is similar to this one I previously asked, in that I want the task to perform a Target Worker Expression check on a list of WorkerSids that I've added as one of the task's attributes. But I think this problem is different enough to warrant its own question.

My goal is to associate a "do not contact" list of WorkerSids with a Task; these are workers who should not be assigned the task (maybe the customer previously had a bad interaction with them).

I have the following workflow configuration:

{
        "task_routing":{
            "filters":[
                {

                    "filter_friendly_name":"don't call self",
                    "expression":"1==1",
                    "targets":[
                        {
                            "queue":queueSid,
                            "expression":"(task.caller!=worker.contact_uri) and (worker.sid not in task.do_not_contact)",
                            "skip_if": "workers.available == 0"
                        },
                        {
                            "queue":automaticQueueSid
                        }
                    ]

                }
            ],
            "default_filter":{
                "queue":queueSid
            }
        }
    }

When I create a task, checking the Twilio Console, I can see that the task has the following attributes:

{"from_country":"US","do_not_contact":["WORKER_SID1_HERE","WORKER_SID_2_HERE"],

... bunch of other attributes...
}

So I know that the task has successfully been assigned the array of WorkerSids as one of its attributes.

There is only one worker who is Idle and whose attributes match the queueSid TaskQueue. That worker's SID is WORKER_SID1_HERE, so the only available worker is ineligible to receive the task reservation. So what should happen is that the first target expression worker.sid not in task.do_not_contact returns false, and the task falls through to the automaticQueueSid TaskQueue.

Instead, the task remains in queueSid unassigned. The following sequence of Taskrouter events are logged:

task-queue.entered
Task TASK_SID entered TaskQueue QUEUESID_QUEUENAME

task.created
Task TASK_SID created

workflow.target-matched
Task TASK_SID matched a workflow target

workflow.entered
Task TASK_SID entered Workflow WORKFLOW_NAME

What do I need to change to get the desired workflow behavior?

sigil
  • 9,370
  • 40
  • 119
  • 199

1 Answers1

0

Changing the skip_if to

"skip_if": "1==1"

solved the problem.

Per Twilio developer support, the worker.sid not in task.do_not_contact returns true for workers who are unavailable but are also not in do_not_contact, so the target expression still returns a set of workers, and then the "skip_if": "workers.available==0" returns false because technically there is one "available" worker--the one who is ineligible due to the do_not_contact list.

What's needed is for the skip_if to always return true, so when the first target processes the task without assigning it, the skip_if then passes it to the next target, as discussed in Taskrouter Workflow documentation:

"TaskRouter will only skip a routing step in a Workflow if:

  • No Reservations are immediately created when a Task enters the routing step
  • The Skip Timeout expression evaluates to true"
sigil
  • 9,370
  • 40
  • 119
  • 199