Koşullar
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Sahnelerde koşullu mantık yürütme işlemini
Veri modeli nesneleri. Aşağıdaki bölümlerde aşağıdaki bölümlerde açıklanmıştır:
ve koşullar için geçerli söz dizimini belirtmelidir.
Mantıksal operatörler
Operatör |
Açıklama |
&& |
Mantıksal VE. İç ifadeler yinelemeli olarak değerlendirilir ve
herhangi bir ifade yanlış olarak değerlendirilirse değerlendirmesi kısa devreye girer. |
|| |
Mantıksal VEYA. İç ifadeler yinelemeli olarak değerlendirilir ve
Herhangi bir ifade doğru olarak değerlendirilirse değerlendirme kısa devre |
! |
Mantıksal DEĞİL. İç ifadenin değerlendirmesi reddedilir |
Sayısal operatörler ve dize operatörleri
Aşağıdaki sayısal ve dize operatörleri desteklenir:
Operatör |
Açıklama |
+ |
Sayı veya dize birleştirme |
- |
Sayıları çıkarma |
* |
Sayıları çarpma |
/ |
Sayıları bölme |
Boole'lar
Aşağıdaki sabit boole değerleri desteklenir:
Sabit |
Açıklama |
true |
Küçük harf olmalıdır |
false |
Küçük harf olmalıdır |
!false |
true olarak değerlendirilir. Küçük harf olmalıdır. |
Karşılaştırma operatörleri
Aşağıdaki karşılaştırma operatörleri sağlanır:
Operatör |
Açıklama |
== |
Şuna eşittir: |
!= |
Eşit değil |
< |
Küçüktür |
<= |
Küçük veya eşittir |
> |
Şundan büyük: |
>= |
Büyük veya eşittir |
Listeler ve haritalar
session.params.myList
adlı bir liste verildiğinde:
Söz dizimi |
Açıklama |
x in session.params.myList |
x değeri şunun içindeyse true değerini döndürür:
session.params.myList |
myList[x] |
myList dizinden x . sıradaki değeri döndürür |
size(session.params.myList) |
Bir listenin boyutunu döndürür |
session.params.myMap
adlı bir harita verildiğinde:
Söz dizimi |
Açıklama |
session.params.myMap == {"one": 1, "two":2} |
Haritalar eşitse true değerini döndürür |
session['params']['myMap']['one'] |
Belirtilen anahtarla birlikte değeri döndürür |
size(session.params.myMap) |
Harita boyutunu döndürür |
Veri modeli
Sahne koşullarında aşağıdaki nesneler kullanılabilir:
Aşağıda, tam veri modelinin JSON'daki örnek bir snippet'i verilmiştir:
{
"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>"
}
}
}
Kullanım referansı
Aşağıdaki söz dizimi örneklerinde,
session.params
nesneyle:
session.params = {
"flag": true,
"count": 10,
"name": "john smith",
"myList": [1, 2, 3],
"myMap": {"one": 1, "two":2}
}
Aşağıdaki koşullu işlemleri gerçekleştirebilirsiniz:
// 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
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-26 UTC.
[null,null,["Son güncelleme tarihi: 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"]]