Actions SDK 總覽 (Dialogflow)

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 主控台。動作主控台會使用動作專案,將對話動作的中繼資料 (例如審查狀態和 Google 助理目錄中的顯示名稱) 分組。專案也可讓您定義動作的相關中繼資料,以及透過核准程序管理及追蹤動作。

建立專案後,您可以使用 gactions CLI 上傳用來定義所有動作的動作套件。

將專案送交審核,並提供給使用者

範例

如要探索已完成的專案,請查看 Node.js 和 Java Actions SDK 範例