iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 23
0
AI & Data

Voice App 開發實務:使用Diagflow+firebase開發Google home App (google assistant action)系列 第 23

actions-on-google 建置 Google Home App #22 notifications 主動推播

actions-on-google 建置 Google Home App #22 notifications 主動推播
雖然document還是寫notification,不過在actions on google 的sdk裡,是用update 這個來實notification 的。
參考
Push notifications | Actions on Google | Google Developers
In this guide, we use the Actions on Google tips sample as a reference to show you how to set up push notifications for…developers.google.com
先 git clone https://github.com/actions-on-google/dialogflow-updates-nodejs 這個範例。

Setup Instructions

Steps

  1. Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project. 先到actions on google 新增專案

  2. Click Skip, located on the top right to skip over category selection menu. 點skip 下去

  3. On the left navigation menu under BUILD, click on Actions.
    在BUILD欄裡點Actions。
    Click on Add Your First Action and choose your app's language(s).
    點Add Your First Action

  4. Select Custom intent, click BUILD. This will open a Dialogflow console. Click CREATE.
    這時會跳到 Dialogflow console,點CREATE

  5. Click on the gear icon to see the project settings.
    點 設定 圖示

  6. Select Export and Import.
    Export and Import

  7. Select Restore from zip. Follow the directions to restore from the AoG-Tips.zip file in this repo.
    Restore from zip

  8. Go to the Google Cloud Platform console to activate the Actions API, and select the project that you have created on the Actions on Google console. Then, click the Enable button.
    到GCP找 Actions API 並Enable 這個權限。 //這裡我在操作時,找不到我在action on google 所開的專案,如果你跟我一樣遇到這個問題,你可以到action on google的專案設定裡找 projectID,然後再GCP的console上面收尋,就可以找到你開的專案了。

  9. Go to the Firebase console and select the project that you have created on the Actions on Google console.
    到Firebase console並且尋找你新增在Actions on Google console的專案;一樣我在這裡一開始也是沒看到我新增專案,我後來在 Dialogflow的fulfilment裡新增inline editor並且在deploy,這個會自動幫你新增firebase function 出來,然後下面有open firebase dashboard,點擊後,就會找到這個專案的firebase了。

  10. Click the gear icon, then select Project settings > SERVICE ACCOUNTS.
    點 設定 圖示,選SERVICE ACCOUNTS

  11. Generate a new private key and save it in the functions folder calling the file service-account.json.
    點Generate a new private key,會下載一個key.json,存到剛剛git clone下來的範例裡的funcitons資料夾。

  12. On the left navigation menu under DEVELOP, click on Database.
    點左欄DEVELOP下有個 Database.

  13. Under Cloud Firebase Beta, click Get Started.
    Cloud Firebase BetaGet Started.

  14. Select Start in test mode, click Enable.
    Start in test modeEnable

  15. In the functions directory, deploy the fulfillment webhook provided in the functions folder using Google Cloud Functions for Firebase:

  16. Follow the instructions to set up and initialize Firebase SDK for Cloud Functions. Make sure to select the project that you have previously generated in the Actions on Google Console and to reply N when asked to overwrite existing files by the Firebase CLI.
    在剛剛你git clone下來的範例裡,用terminal下 firebase init ,沒安裝firebase tool,麻煩自已去安裝,記得選你的firebase name。

  17. Run npm install to install dependencies.
    下npm install

  18. Run firebase deploy and take note of the endpoint where the fulfillment webhook has been published. It should look like Function URL (aogTips): https://${REGION}-${PROJECT}.cloudfunctions.net/aogTips
    下firebase deploy

  19. Go back to the Dialogflow console and select Fulfillment from the left navigation menu. Enable Webhook, set the value of URL to the Function URL from the previous step, then click Save.
    會產生兩個網址,將 https://us-central1-push-xxxxx.cloudfunctions.net/aogTips 填到dialogflow的webh

  20. To add tips to the newly created Firestore database, load in a browser https://${REGION}-${PROJECT}.cloudfunctions.net/restoreTipsDB.
    將這個開啟 https://us-central1-push-xxx.cloudfunctions.net/restoreTipsDB 這個會將tipsDB.json的資料倒到firebase database 裡。我一開始沒注意到這個,後面就一直跳錯。

  21. Go to the Actions on Google console.
    開啟Actions on Google console

  22. Follow the Console Setup instructions in the Daily Updates and the Push Notifications documentation to enable daily updates and push notifications.
    將Daily Updates和 push notifications的設定開啟
    後面就照走,測試一下囉

  23. Type Talk to my test app in the simulator, or say OK Google, talk to my test app to any Actions on Google enabled device signed into your developer account.

  24. To test daily updates, choose a category. After the tip, the app will show a suggestion chip to subscribe for daily updates.

  25. To test push notifications, choose to hear the latest tip. After the top, the app will show
    a suggestion chip to subscribe for push notifications. Add a new tip to the Firestore DB to trigger a notification to the subscribed users.
    For more detailed information on deployment, see the documentation.


上一篇
actions-on-google 建置 Google Home App #21 Media Object : 播放 audio..
下一篇
actions-on-google 建置 Google Home App #23 Account linking
系列文
Voice App 開發實務:使用Diagflow+firebase開發Google home App (google assistant action)31

尚未有邦友留言

立即登入留言