Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now


Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

TaskRouter Expressionsの使用

TaskRouter uses a SQL-like expression syntax for binding Workers to TaskQueues and filtering Tasks into TaskQueues in a Workflow configuration. Expressions are composed of constants, JSON keys, as well as logical and comparison operators.

たとえば、TaskQueueのTargetWorkers Expressionは次のようになります。

(skills HAS 'support') AND (languages HAS 'english')


customer_value == 'Gold' AND type == 'ticket'


Expressionは、定数や JSON キーの単純比較をかっこや論理演算子でグループ化することによって構成されます。


  • 1 == 1
  • 0 != 1
  • "apple" != "orange"
  • key > 1
  • object.param != "apple"
  • language IN ["en", "es"]
  • (condition_a == true) OR (condition_b == true)
  • (language == "en" OR language == "fr") AND skill_rating >= 5.1


次の 3 つのタイプの定数がサポートされています。

  • 文字列。一重引用符または二重引用符で囲まれたテキストのブロックとして表されます。"string" または 'string'
  • 数。整数または浮動小数点数として表されます。
  • boolean。引用符で囲まない true または false として表されます。



References to JSON object keys can also exist in the expression. These are resolved against the JSON document (Worker or Task attributes), and the value from the JSON is substituted. Keys are used as unquoted strings, using dot notation to reference sub-properties and square brackets to reference array indices. If the document does not contain the requested key, it resolves to NULL.


    "string_const": "foo",
    "object": {
        "array": ["a","b","c"],
        "attr": "bar"


  • string_const - 文字列。次の値に解決されます。 "foo"
  • object.array - 配列。次の値に解決されます。 [1,2,3]
  • object.array[2] - 文字列。次の値に解決されます。 "c"
  • object.attr - 文字列。次の値に解決されます。 "bar"


Comparison operators compare two constants and return true or false. Comparisons between different types should be avoided. Scalar operators can compare two scalar values (i.e. not arrays). Array operators can have Arrays as one side of the operation.


  • > greater than
  • >= greater than or equal to
  • == equals
  • != does not equal
  • <= less than or equal to
  • < less than
  • CONTAINS - 左辺のスカラー値に右辺のスカラー値が含まれます。


  • HAS - 左辺の配列の要素として右辺の値を追加します。
  • IN - 左辺のスカラー値が右辺の配列に存在するかどうかを表します。
  • NOT IN 左側のスカラー値は右辺の配列に含まれません。

Using scalar operators on Arrays results in false. Using array operators on two scalar values also returns false.


Compares the results of sub-expressions to the left and right and return true or false based on the operand. Parenthesis can be used to group sub-expressions.


  • AND - if both the left and right subexpressions are true, resolves to true; otherwise false
  • OR - if one or both of the left or right subexpressions are true, resolves to true; otherwise false

Queue, Matching Tasks, and Matching Workers Expressions

Expressions are used in three primary places to manage the assignment of Tasks to Workers:

  1. The definition of a TaskQueue
    • Evaluates against all Workers in a Workspace
  2. A Workflow filter to find matching Tasks (filter: in a Workflow configuration JSON)
    • Evaluates against a single Task processing through a Workflow
  3. A routing step expression to match Workers to a Task (target.expression: in a Workflow configuration JSON)
    • Evaluates against a single Task and all Workers in the routing step's queue
    • All attributes must be prefixed by task. or worker.
Rate this page:


誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。