会話型アクションのサポートは 2023 年 6 月 13 日に終了しました。詳細については、
会話型アクションの廃止をご覧ください。
Conditions
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
次の値を使用して、シーンで条件付きロジックを実行できます。
データモデル オブジェクト。以降のセクションでは、
指定する必要があります。
論理演算子
演算子 |
説明 |
&& |
論理 AND。内部式は反復的に評価され、
いずれかの式が false と評価された場合、評価は省略されます。 |
|| |
論理 OR。内部式は反復的に評価され、
いずれかの式が true と評価された場合、評価は短絡されます。 |
! |
論理 NOT。内部の式の評価は否定されます |
数値演算子と文字列演算子
次の数値演算子と文字列演算子がサポートされています。
演算子 |
説明 |
+ |
数値または文字列の連結を追加する |
- |
引き算を行う |
* |
かけ算をする |
/ |
割り算をする |
ブール値
次の定数ブール値がサポートされています。
定数 |
説明 |
true |
小文字でなければなりません |
false |
小文字でなければなりません |
!false |
true と評価されます。小文字のみを使用できます。 |
比較演算子
次の比較演算子が用意されています。
演算子 |
説明 |
== |
等しい |
!= |
等しくない |
< |
次より小さい |
<= |
次の値以下 |
> |
次より大きい |
>= |
次の値以上 |
リストとマップ
session.params.myList
という名前のリストがあるとします。
構文 |
説明 |
x in session.params.myList |
値 x が次の場所にある場合に true を返します。
session.params.myList |
myList[x] |
myList のインデックス x の値を返します |
size(session.params.myList) |
リストのサイズを返します |
session.params.myMap
という名前のマップがあるとします。
構文 |
説明 |
session.params.myMap == {"one": 1, "two":2} |
マップが等しい場合は true を返します。 |
session['params']['myMap']['one'] |
指定されたキーの値を返します |
size(session.params.myMap) |
地図のサイズを返します。 |
データモデル
シーン条件内で使用できるオブジェクトは次のとおりです。
JSON の完全なデータモデルのスニペットの例を次に示します。
{
"intent": {
"params": {
"<param_name>": {
"original": "five people",
"resolved": 5
}
}
},
"session": {
"params": {
"<session_params_key>": "<session_params_value>"
}
},
"scene": {
"slots": {
"status": "FINAL",
"params": {
"<slot_name>": "<slot_value>"
}
}
},
"user": {
"params": {
"<user_params_key>": "<user_params_value>"
},
"permissions": [
"DEVICE_PRECISE_LOCATION"
],
"accountLinkingStatus": "LINKED",
"verificationStatus": "VERIFIED",
"lastSeenTime": {
"seconds": 123,
"nanos": 456
},
"engagement": {
"pushNotificationIntents": [
"intent1",
"intent2"
]
}
},
"home": {
"params": {
"<home_params_key>": "<home_params_value>"
}
},
"canvas": {
"state": {
"<canvas_state_key>": "<canvas_state_value>"
}
},
"device": {
"capabilities": [
"SPEECH",
"RICH_RESPONSE",
"LONG_FORM_AUDIO",
"INTERACTIVE_CANVAS"
],
"currentLocation": {
"coordinates": {
"latitude": 37.422,
"longitude": -122.084
},
"postalAddress": {
"revision": 0,
"regionCode": "US",
"languageCode": "en",
"postalCode": "94043",
"sortingCode": "",
"administrativeArea": "California",
"locality": "Mountain View",
"sublocality": "",
"addressLines": ["1600 Amphitheatre Parkway"],
"recipients": [],
"organization": ""
}
}
},
"resources": {
"strings": {
"<resource_string_key>": "<resource_string_value>"
},
"images": {
"<resource_image_key>": "<resource_image_value>"
}
}
}
使用リファレンス
次の構文例は、Terraform を使用して
session.params
オブジェクトの場合:
session.params = {
"flag": true,
"count": 10,
"name": "john smith",
"myList": [1, 2, 3],
"myMap": {"one": 1, "two":2}
}
次の条件操作を実行できます。
// numbers and boolean logic
session.params.count > 0 && session.params.count < 100 // AND
session.params.count == 0 || session.params.count != 5 // OR
!(session.params.count <= 0) // NOT
// booleans
!false // true constant
session.params.flag // boolean variable
session.params.flag == true // explicitly compare with true constant
// strings
session.params.name == "john smith" // double quotes supported
session.params.name == 'john smith' // single quotes supported
session.params.name.contains("john") // substring
session.params.name + "!!!" == "john smith!!!" // string concatenation
session.params.name < "abc" // compares lexicographically
size(session.params.name) == 10 // length of string
// lists
1 in session.params.myList // "contains in list" operator
session.params.myList[0] == 1 // "index into list" operator
size(session.params.myList) == 3 // returns number of elements in the list
// maps
session.params.myMap == {"one": 1, "two":2} // compare map with json
session['params']['myMap']['one'] == 1 // index using square brackets
size(session.params.myMap) == 2 // number of entries in the map
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[[["\u003cp\u003eDefine conversational flow logic with conditions based on data from the intent, scene, session, user, home, device, canvas, and resources objects.\u003c/p\u003e\n"],["\u003cp\u003eUtilize logical operators (\u003ccode\u003e&&\u003c/code\u003e, \u003ccode\u003e||\u003c/code\u003e, \u003ccode\u003e!\u003c/code\u003e), numerical and string operators (\u003ccode\u003e+\u003c/code\u003e, \u003ccode\u003e-\u003c/code\u003e, \u003ccode\u003e*\u003c/code\u003e, \u003ccode\u003e/\u003c/code\u003e), and comparison operators (\u003ccode\u003e==\u003c/code\u003e, \u003ccode\u003e!=\u003c/code\u003e, \u003ccode\u003e<\u003c/code\u003e, \u003ccode\u003e<=\u003c/code\u003e, \u003ccode\u003e>\u003c/code\u003e, \u003ccode\u003e>=\u003c/code\u003e) to construct conditional expressions.\u003c/p\u003e\n"],["\u003cp\u003eAccess and manipulate data within lists and maps using syntax like \u003ccode\u003ex in list\u003c/code\u003e, \u003ccode\u003elist[x]\u003c/code\u003e, \u003ccode\u003esize(list)\u003c/code\u003e, and specific notations for maps.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the comprehensive data model and usage reference for detailed information on available objects, their properties, and example syntax.\u003c/p\u003e\n"]]],["Conditional logic in scenes uses values from data model objects. Supported operators include logical (`&&`, `||`, `!`), numerical/string (`+`, `-`, `*`, `/`), and comparison (`==`, `!=`, `\u003c`, `\u003c=`, `\u003e`, `\u003e=`). Booleans (`true`, `false`) are supported. Lists use `in`, index, and `size()`, while maps allow for comparison, indexing, and `size()`. Data model objects (`intent`, `scene`, `session`, `user`, `home`, `device`, `canvas`, `resources`) can be referenced. Example syntax provided for numbers, booleans, strings, lists and maps.\n"],null,["# Conditions\n\nYou can carry out conditional logic in scenes using values from the\n[Data model](#data_model) objects. The following sections describe\nthe valid syntax for conditions.\n\nLogical operators\n-----------------\n\n| Operator | Description |\n|----------|---------------------------------------------------------------------------------------------------------------------------------------|\n| **`&&`** | Logical AND. Inner expressions are evaluated iteratively, and the evaluation is short-circuited if any expression evaluates to false. |\n| **`||`** | Logical OR. Inner expressions are evaluated iteratively, and the evaluation is short-circuited if any expression evaluates to true |\n| **`!`** | Logical NOT. The evaluation of the inner expression is negated |\n\n### Numerical and string operators\n\nThe following numerical and string operators are supported:\n\n| Operator | Description |\n|----------|-------------------------------------|\n| **`+`** | Add numbers or string concatenation |\n| **`-`** | Subtract numbers |\n| **`*`** | Multiply numbers |\n| **`/`** | Divide numbers |\n\n### Booleans\n\nThe following constant booleans are supported:\n\n| Constant | Description |\n|--------------|-----------------------------------------|\n| **`true`** | Must be lowercase |\n| **`false`** | Must be lowercase |\n| **`!false`** | Evaluates to `true`. Must be lowercase. |\n\n### Comparison operators\n\nThe following comparison operators are provided:\n\n| Operator | Description |\n|----------|---------------------|\n| **`==`** | Equals |\n| **`!=`** | Not equals |\n| **`\u003c`** | Less than |\n| **`\u003c=`** | Less than equals |\n| **`\u003e`** | Greater than |\n| **`\u003e=`** | Greater than equals |\n\n### Lists and maps\n\nGiven a list named `session.params.myList`:\n\n| Syntax | Description |\n|-----------------------------------|-------------------------------------------------------------|\n| **`x in session.params.myList`** | Returns true if the value `x` is in `session.params.myList` |\n| **`myList[x]`** | Returns the value at index `x` of `myList` |\n| **`size(session.params.myList)`** | Returns the size of a list |\n\nGiven a map named `session.params.myMap`:\n\n| Syntax | Description |\n|---------------------------------------------------|--------------------------------------|\n| **`session.params.myMap == {\"one\": 1, \"two\":2}`** | Returns `true` if maps are equal |\n| **`session['params']['myMap']['one']`** | Returns the value with specified key |\n| **`size(session.params.myMap)`** | Returns the map size |\n\nData model\n----------\n\nThe following objects can be used within scene conditions:\n\n| Syntax | Description |\n|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **`intent`** | [Matched intent parameter](/assistant/conversational/intents) data |\n| **`scene`** | [Slot-filling](/assistant/conversational/scenes#slot_filling) data |\n| **`session`** | [Session storage](/assistant/conversational/storage-session) data |\n| **`user`** | [User storage](/assistant/conversational/storage-user) data |\n| **`home`** | [Home storage](/assistant/conversational/storage-home) data |\n| **`device`** | Device [capability](/assistant/conversational/webhooks?tool=sdk#check_device_capabilities) and [location](/assistant/conversational/permissions) data |\n| **`canvas`** | [Canvas state](/assistant/interactivecanvas/web-apps#setcanvasstate) data |\n| **`resources`** | [Localized project resources](/assistant/conversational/build/projects?tool=sdk#add_resources) (audio, images, strings, etc.) data |\n\n| **Note:** These data values can also be referenced within [static prompts](/assistant/conversational/prompts).\n\nThe following is an example snippet of the full data model in JSON: \n\n {\n \"intent\": {\n \"params\": {\n \"\u003cparam_name\u003e\": {\n \"original\": \"five people\",\n \"resolved\": 5\n }\n }\n },\n \"session\": {\n \"params\": {\n \"\u003csession_params_key\u003e\": \"\u003csession_params_value\u003e\"\n }\n },\n \"scene\": {\n \"slots\": {\n \"status\": \"FINAL\",\n \"params\": {\n \"\u003cslot_name\u003e\": \"\u003cslot_value\u003e\"\n }\n }\n },\n \"user\": {\n \"params\": {\n \"\u003cuser_params_key\u003e\": \"\u003cuser_params_value\u003e\"\n },\n \"permissions\": [\n \"DEVICE_PRECISE_LOCATION\"\n ],\n \"accountLinkingStatus\": \"LINKED\",\n \"verificationStatus\": \"VERIFIED\",\n \"lastSeenTime\": {\n \"seconds\": 123,\n \"nanos\": 456\n },\n \"engagement\": {\n \"pushNotificationIntents\": [\n \"intent1\",\n \"intent2\"\n ]\n }\n },\n \"home\": {\n \"params\": {\n \"\u003chome_params_key\u003e\": \"\u003chome_params_value\u003e\"\n }\n },\n \"canvas\": {\n \"state\": {\n \"\u003ccanvas_state_key\u003e\": \"\u003ccanvas_state_value\u003e\"\n }\n },\n \"device\": {\n \"capabilities\": [\n \"SPEECH\",\n \"RICH_RESPONSE\",\n \"LONG_FORM_AUDIO\",\n \"INTERACTIVE_CANVAS\"\n ],\n \"currentLocation\": {\n \"coordinates\": {\n \"latitude\": 37.422,\n \"longitude\": -122.084\n },\n \"postalAddress\": {\n \"revision\": 0,\n \"regionCode\": \"US\",\n \"languageCode\": \"en\",\n \"postalCode\": \"94043\",\n \"sortingCode\": \"\",\n \"administrativeArea\": \"California\",\n \"locality\": \"Mountain View\",\n \"sublocality\": \"\",\n \"addressLines\": [\"1600 Amphitheatre Parkway\"],\n \"recipients\": [],\n \"organization\": \"\"\n }\n }\n },\n \"resources\": {\n \"strings\": {\n \"\u003cresource_string_key\u003e\": \"\u003cresource_string_value\u003e\"\n },\n \"images\": {\n \"\u003cresource_image_key\u003e\": \"\u003cresource_image_value\u003e\"\n }\n }\n }\n\nUsage reference\n---------------\n\nThe following syntax examples assumes you are working\nwith `session.params` object: \n\n session.params = {\n \"flag\": true,\n \"count\": 10,\n \"name\": \"john smith\",\n \"myList\": [1, 2, 3],\n \"myMap\": {\"one\": 1, \"two\":2}\n }\n\nYou can carry out the following conditional operations: \n\n // numbers and boolean logic\n session.params.count \u003e 0 && session.params.count \u003c 100 // AND\n session.params.count == 0 || session.params.count != 5 // OR\n !(session.params.count \u003c= 0) // NOT\n\n // booleans\n !false // true constant\n session.params.flag // boolean variable\n session.params.flag == true // explicitly compare with true constant\n\n // strings\n session.params.name == \"john smith\" // double quotes supported\n session.params.name == 'john smith' // single quotes supported\n session.params.name.contains(\"john\") // substring\n session.params.name + \"!!!\" == \"john smith!!!\" // string concatenation\n session.params.name \u003c \"abc\" // compares lexicographically\n size(session.params.name) == 10 // length of string\n\n // lists\n 1 in session.params.myList // \"contains in list\" operator\n session.params.myList[0] == 1 // \"index into list\" operator\n size(session.params.myList) == 3 // returns number of elements in the list\n\n // maps\n session.params.myMap == {\"one\": 1, \"two\":2} // compare map with json\n session['params']['myMap']['one'] == 1 // index using square brackets\n size(session.params.myMap) == 2 // number of entries in the map"]]