建立 Webhook 執行要求後,請將其部署至正式環境並連線 加入動作下列步驟說明如何設定環境 部署至 Cloud Functions for Firebase 來進行實際工作環境託管。不過 您可以選擇任何支援 HTTPS 要求的網站代管平台 以便代管執行要求。
如果您已將 Webhook 部署到網站代管平台, 請跳至「將 Webhook 連結至動作」一節。請注意 下列步驟會因您使用的是 Dialogflow 還是 Actions SDK。
部署至 Cloud Functions for Firebase
- 下載並安裝 Node.js。
- 設定並初始化 Firebase CLI。如果下列指令失敗, - EACCES錯誤,您可能需要 變更 npm 權限。- npm install -g firebase-tools
- 使用 Google 帳戶驗證 Firebase 工具: - firebase login
- 前往動作專案目錄並初始化 Firebase。您 請您選取要為 動作專案。選擇 - Functions和您可能會想使用的其他功能。 ,接著按下 Enter 鍵即可確認並繼續操作:- cd <cloud_function_dir> firebase init
- 使用 Actions 專案來選取 Firebase 工具與 Actions 專案之間的關聯 使用方向鍵瀏覽專案清單: 
- 選擇專案後,Firebase 工具會啟動函式設定 會詢問你要使用哪種語言。使用方向鍵選取 按下 Enter 鍵即可繼續操作。 - === Functions Setup 
 A functions directory will be created in your project with a Node.js package pre-configured. Functions can be deployed with firebase deploy. ? What language would you like to use to write Cloud Functions? (Use arrow keys) > JavaScript TypeScript
- 選擇是否要使用 ESLint 找出潛在錯誤並強制執行樣式 輸入 - Y或- N:- ? Do you want to use ESLint to catch probable bugs and enforce style? (Y/n) 
- 在提示中輸入 - Y,以取得專案依附元件:- ? Do you want to install dependencies with npm now? (Y/n) - 設定完成後,您會看到類似下方的輸出內容: - ✔ Firebase initialization complete! 
- 安裝 actions-on-google 依附元件: - cd <cloud_function_dir>/functions npm install actions-on-google
- 取得執行要求依附元件,並部署執行要求函式: - npm install firebase deploy --only functions- 部署作業需要幾分鐘才能完成。完成之後,您會看到輸出內容 類似下方的內容您需要函式網址才能輸入 Dialogflow。 - ✔ Deploy complete! 
 Project Console: https://console.firebase.google.com/project/exampleproject-123/overview Function URL (cloudFunctionName): https://us-central1-exampleproject-123.cloudfunctions.net/cloudFunctionName
將 Webhook 連結至動作
如果您使用 Dialogflow:請參閱 依序前往 Dialogflow 控制台 在「Fulfillment」(執行要求) 下,將「Webhook」按鈕切換為「ENABLED」(啟用),然後 「網址」欄位中的網址,改成您的「函式網址」。
 
使用 Actions SDK:建立物件
在 conversations 物件內部,以便在動作中宣告執行要求
套件:
{
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "myFulfillmentFunction"
      },
      "intent": {
        "name": "actions.intent.MAIN",
        "trigger": {
          "queryPatterns": [
            "talk to myFulfillmentFunction"
          ]
        }
      }
    }
  ],
  "conversations": {
    "myFulfillmentFunction": {
      "name": "myFulfillmentFunction",
      "url": "https://us-central1-myprojectname-ab123.cloudfunctions.net/cloudFunctionName"
    }
  },
  "locale": "en"
}