Actions on Google 可讓您透過動作擴充 Google 助理的功能。動作可讓使用者透過對話的快速介面開啟某些燈具或較長的對話,例如玩益智遊戲。
Actions SDK 是在不使用 Dialogflow 的情況下開發對話履行的方法。使用 Actions SDK 時,您會使用動作套件將意圖對應至其執行要求。您也必須在動作套件中提供查詢模式,以便定義使用者可能會說的範例詞組。
Gactions CLI
使用 Actions SDK 開發時,您會使用 gactions
指令列介面 (CLI) 來測試及更新 Actions 專案。gactions
CLI 也能協助您建立及管理對話動作的動作套件。
透過動作套件建立動作
您可以在意圖套件中建立操作,以將意圖對應至執行要求。動作會定義一個進入點,其專屬 ID 稱為意圖。意圖會對應至履行意圖的執行要求。
舉例來說,假設您要建立一個專案,並在其中加入用於購買部分商品、查看訂單狀態,以及顯示部分每日優惠的動作。您可以透過以下方式定義觸發的意圖:
- 「Ok Google,與 ExampleAction 交談。」
- 「Ok Google,向 ExampleAction 購買一些鞋款。」
- 「Ok Google,與 ExampleAction 查看我的訂單。」
- 「Ok Google,與 ExampleAction 展開今日特惠。」
動作套件 JSON 檔案可能如下所示:
{
"actions": [
{
"name": "MAIN",
"intent": {
"name": "actions.intent.MAIN"
},
"fulfillment": {
"conversationName": "ExampleAction"
}
},
{
"name": "BUY",
"intent": {
"name": "com.example.ExampleAction.BUY",
"parameters": [{
"name": "color",
"type": "org.schema.type.Color"
}],
"trigger": {
"queryPatterns": [
"find some $org.schema.type.Color:color sneakers",
"buy some blue suede shoes",
"get running shoes"
]
}
},
"fulfillment": {
"conversationName": "ExampleAction"
}
},
{
"name": "ORDER_STATUS",
"intent": {
"name": "com.example.ExampleAction.ORDER_STATUS",
"trigger": {
"queryPatterns": [
"check on my order",
"see order updates",
"check where my order is"
]
}
},
"fulfillment": {
"conversationName": "ExampleAction"
}
},
{
"name": "DAILY_DEALS",
"intent": {
"name": "com.example.ExampleAction.DAILY_DEALS",
"trigger": {
"queryPatterns": [
"hear about daily deals",
"buying some daily deals",
"get today's deals"
]
}
},
"fulfillment": {
"conversationName": "ExampleAction"
}
}
],
"conversations": {
"ExampleAction": {
"name": "ExampleAction",
"url": "https://www.example.com/ExampleAction"
}
}
}
建立及部署執行要求 Webhook
當叫用專案中的動作時,Actions on Google 會呼叫您的執行項目,與使用者開始對話以完成該動作。
每次履行要求 Webhook 時,您都會以文字字串接收使用者輸入內容。為了處理意圖,您通常會剖析文字輸入並傳回回應。在動作的對話結束之前,這項交換作業會彼此交換。
上傳您的動作套件
建立動作套件並部署其執行要求之後,就可以將動作套件上傳到 Actions 主控台。Actions 主控台會使用 Action 專案將對話動作的分類,例如在 Google 助理目錄中的審查狀態和顯示名稱等中繼資料。這項專案也能讓您定義動作的相關中繼資料,並透過核准程序管理及追蹤動作。
建立專案後,您可以透過 gactions
CLI 上傳定義所有動作的 Action 套件。
將專案送交審核,並提供給使用者
範例
如要探索已完成的專案,請查看 Node.js 和 Java Actions SDK 範例。