twiliotwilio-apitwilio-taskrouter

Matching expressions for Twilio TaskRouter workers on data in objects in arrays


I've got Twilio Taskrouter workers with attributes that look like as follows:

{
  "name": "Bob",
  "id": "45",
  "roles": [
    { "id": "19", "name": "Foobar" },
    { "id": "20", "name": "Foobaz" }
  ]
}

I'd like to write a queue expression to only match Workers with roles with an id of 20. How would I do that?

It would look something like...

"20" in roles.id

...but this doesn't work. As it seems Taskrouter is not smart enough to "unroll" the ids and match within them (like using a tool like jq). I am not able to find a solution in the Twilio Taskrouter expression docs.


Solution

  • Twilio developer evangelist here.

    I can't find a solution for you with the data like that. A workaround I just considered would be to add an array of, for example, role_ids to your worker as well. You can keep the existing array of roles, but add a simpler data type to use in the expression matching.

    So, the attributes would look like this:

    {
      "name": "Bob",
      "id": "45",
      "roles": [
        { "id": "19", "name": "Foobar" },
        { "id": "20", "name": "Foobaz" }
      ],
      "role_ids": ["19", "20"]
    }
    

    And you could then use the expression:

    "20" in role_ids