0

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.

Chris W.
  • 37,583
  • 36
  • 99
  • 136

1 Answers1

1

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
Dharman
  • 30,962
  • 25
  • 85
  • 135
philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks for the help. This is the solution which I ended up using. But it certainly would be nice to be able to query the nested structures! – Chris W. Nov 23 '20 at 21:34