Unyablog.

のにれんのブログ

Actions on Google SDK を用いた Action の開発で詰まった点

Google Assistant 用のアプリケーションを開発するときは Actions on Google SDK を使う。

よくあるのは Dialogflow 経由で設定して Firebase などで返答を決定するものだが、 Actions on Google SDK というものもある。

これを使えば、json で Action について記述して、gactions コマンドでデプロイすることができる*1

https://developers.google.com/actions/sdk/

基本的にドキュメントに書いてあるとおりなのだが、詰まった点をいくつか。

Dialogflow から Actions SDK に変更する時

$ gactions test では Dialogflow から変更されない。 $ gactions update を行うことで、 Dialogflow から Actions SDK にターゲットが変更される。

1プロジェクト1Actionなのは微妙に不便 *2

初めの呼びかけ以降は基本的に生のテキストが降ってくる

intent に独自の intent を記述して、 queryPattern に反応する語句とパースする変数を書くとその intent が使えるようになるのだが、これは最初だけである。 一度でも app.ask を行うと、 app.intent.TEXT 等のはじめからある intent しか降ってこないので注意。

For the first conversation turn, the intent will refer to the intent of the action that is being triggered. For subsequent conversation turns, the intent will be a built-in intent. For example, if the expected input is actions.intent.OPTION, then the the intent specified here will either be actions.intent.OPTION if the Google Assistant was able to satisfy that intent, or actions.intent.TEXT if the user provided other information.

https://developers.google.com/actions/reference/rest/Shared.Types/AppRequest#Input

要するに、

「Ok Google、○○ に XX と言って」

のような言い方をしないとパースされない。 Dialogflow を使えってことらしい(↓で Google のエンジニアが言っている)。

queryPattern の変数は前後に空白を置く

空白を置かないと反応しない。

"$color:SchemaOrg_Color の服を教えて"

個人用の Action に使っていたのだけど、微妙なので Alexa skill も使ってみたい。

*1:この時にプレビューの expire を指定できるので100年ぐらいにしようという目論見だった。しかし、もうじきそのオプションは消えるらしい

*2:Action だけ削除ができないのも難点