制御コンポーネント
これらのYAMLモード制御コンポーネントは、ユーザー入力が事前定義済の値と一致するかどうかに基づいてフローをルーティングします。
System.ConditionEquals
このコンポーネントは、変数値に基づいてナビゲーションを変更します。
このコンポーネントを使用して、値が一致する場合にダイアログ・フローを分岐します。このコンポーネントは、
source
またはvariable
プロパティに設定された値をvalue
プロパティに格納された値と比較して、値ベースのルーティングを実行します。このコンポーネントは、一致(または一致しないこと)に基づいて、equal
およびnotequal
アクションをトリガーします。次のスニペットでは、顧客はorders
コンテキスト変数について抽出された入力がpizza
に一致した場合はorderPizza
状態にルーティングされ、一致しない場合はorderPasta
状態で始まる実行パスにルーティングされます。 Check for Pizza:
component: "System.ConditionEquals"
properties:
variable: "orders"
value: "pizza"
transitions:
actions:
equal: "orderPizza"
notequal: "orderPasta"
プロパティ | 説明 | 必須? |
---|---|---|
variable |
現在の値によってルーティングが決定される変数の名前。source プロパティも定義されている場合、ダイアログ・エンジンはvariable プロパティを無視します。
|
いいえ |
source |
source プロパティは、variable プロパティにかわるものです。
|
いいえ |
value |
source またはvariable のいずれかのプロパティと比較される値。
|
はい |
System.ConditionEqualsコンポーネントでApache FreeMarker式を使用する方法
Apache FreeMarker式を使用して
value
およびsource
プロパティを定義することによって、一致基準を特定の値および書式に絞り込むことができます。例:
verifyCode: component: "System.ConditionEquals" properties: variable: "code" value: "${userEnteredCode.value}" transitions: actions: equal: "wrongCode" notequal: "${flow.value}"
conditionEquals: component:"System.ConditionEquals" properties: source: "${addressVariable.value.state} - ${addressVariable.value.country}" value: "CA - USA" transitions: actions: equal: goCalfifornia notequal: goSomewhereElse
main: true name: "Shoppingbot" context: variables: yesnoVar: "YES_NO" ... confirmBuy: component: "System.ConditionEquals" properties: source: "${yesnoVar.value.yesno}" value: "YES" transitions: actions: equal: "deviceDone" notequal: "cancelOrder" deviceDone: component: "System.Output" properties: text: "Your ${devices.value} is on its way." transitions: return: "done" cancelOrder: component: "System.Output" properties: text: "Thanks for your interest." transitions: return: "done"
-
context: variables: wordLength: "int" words: "string" states: askName: component: "System.Text" properties: prompt: "What is your name?" variable: "words" setVariable: component: "System.SetVariable" properties: variable: "wordLength" value: "${words.value?length}" conditionEquals: component: "System.ConditionEquals" properties: source: "${(wordLength.value?number > 2)?then('valid', 'invalid')}" value: "valid" transitions: actions: equal: "checkFirstNameinDatabase" notequal: "inValidName" done: component: "System.Output" properties: text: "Done" transitions: return: "done" checkFirstNameinDatabase: component: "System.Output" properties: text: "Check the first name in the database." transitions: return: "done" inValidName: component: "System.Output" properties: text: "This name is not valid. It needs to be at least three letters." transitions: return: "done"
System.ConditionExists
このコンポーネントを使用して、指定した変数の存在をチェックします。値に従ってダイアログをルーティングするには、exists
アクションおよびnotexist
アクションを使用して遷移キーを定義します。
プロパティ | 説明 | 必須? |
---|---|---|
variable |
変数の名前 | はい |
main: true
name: "HelloKids"
context:
variables:
foo: "string"
lastQuestion: "string"
lastResponse: "string"
states:
intent:
component: "System.Intent"
properties:
variable: "iResult"
transitions:
actions:
Talk: "checkUserSetup"
unresolvedIntent: "checkUserSetup"
checkUserSetup:
component: "System.ConditionExists"
properties:
variable: "user.lastQuestion"
transitions:
actions:
exists: "hellokids"
notexists: "setupUserContext"
setupUserContext:
component: "System.CopyVariable"
properties:
from: "lastQuestion,lastResponse"
to: "user.lastQuestion,user.lastResponse"
transitions:
...
...
System.Switch
このコンポーネントを使用して、変数値に基づいて状態を切り替えます。
System.ConditionEquals
コンポーネントと同様の値ベースのルーティングを有効にします。System.Switch
コンポーネントは、値リストをvariable
またはsource
プロパティと比較して、実行パスを選択します。値が一致すると、コンポーネントは実行パスを開始する状態を指定するアクション遷移をトリガーします。変数に対して設定された現在の値がvalues
プロパティに定義されているアイテムのいずれとも一致しない場合は、NONE
遷移を追加できます。予期しないアクションのダイアログ・フローの構成では、System.Switch
コンポーネントによってスキル・ボットが不正なユーザー入力を適切に処理できるようにする方法を説明します。switchOnCategory:
component: "System.Switch"
properties:
variable: "category"
values:
- "Vehicle"
- "Property"
- "Other"
transitions:
actions:
NONE: "ActionNoLongerAvailable"
Vehicle: "getVehicleQuote"
Property: "getPropertyQuote"
Other: "getOtherQuote"
プロパティ | 説明 | 必須? |
---|---|---|
variable |
現在の値が切替え遷移の基礎として使用される変数。values プロパティを比較値のリストとして定義します。source プロパティも定義されている場合、ダイアログ・エンジンはvariable プロパティを無視します。
|
いいえ |
source |
source プロパティは、variable プロパティにかわるものです。
|
いいえ |
values |
source またはvariable プロパティとの比較として使用される値リスト。
|
はい |
System.SwitchコンポーネントでApache FreeMarker式を使用する方法
Apache FreeMarker式を使用して
value
およびsource
プロパティを定義することによって、一致基準を特定の値および書式に絞り込むことができます。たとえば、date
やstring
などの組込みのFreeMarker操作を使用して式を定義できます: switch2:
component: "System.Switch"
properties:
source: "${startDate.value.date?string('dd-MM-yyyy')}"
values:
- "17-12-2017"
- "18-12-2017"
transitions:
actions:
"17-12-2017": goToday
"18-12-2017": goTomorrow