LoginSignup
8
4

More than 5 years have passed since last update.

ASK CLI を使って Alexa Custom Skills のシナリオテストをしよう

Last updated at Posted at 2018-04-30

はじめに

ある日、ASK CLI コマンド リファレンスをぼーっと眺めていたら

( ゚ ρ ゚ )・・・あれっ、なんか前と少し違う気がする

何気なく、以下を見ていたら

Simulates an invocation of your skill with text input. Under the hood, the command calls ask api simulate-skill and continues polling for the simulation status until it is finalized. The parameters are the same as for ask api simulate-skill.

( ゚ ρ ゚ )・・・シミューレート早く日本語で使えるようにならないかなぁ。。。んっ…?

--locale, -l

Optional if ASK_DEFAULT_DEVICE_LOCALE environment variable is set, otherwise, required. Locale for the skill to be simulated. Valid values are en-US, en-GB, en-CA, en-AU, en-IN, de-DE, or ja-JP. If not specified, you will be prompted to enter the locale.

(つд⊂)ゴシゴシ

ja-JP

(;゚д゚) ・・・日本語で使えるだと…

私の当てにならない記憶では、ja-JPはサポートされてませんと載っていたと記憶しています。
もしかしたら、かなり前から使えたかもしれません。

というわけで使ってみました。

とりあえず使ってみる

ask simulate --profile ask-profile-staging --skill-id amzn1.ask.skill.xxxx --locale ja-JP --text "じゃらじゃらを開いて"
{
  "id": "xxxxx",
  "status": "SUCCESSFUL",
  "result": {
    "skillExecutionInfo": {
      "invocationRequest": {
        "endpoint": "arn:aws:lambda:ap-northeast-1:xxxxx",
        "body": {
          "version": "1.0",
          "session": {
            "new": true,
            "sessionId": "amzn1.echo-api.session.xxxxx",
            "application": {
              "applicationId": "amzn1.ask.skill.xxxxx"
            },
            "user": {
              "userId": "amzn1.ask.account.xxxxx"
            }
          },
          "context": {
            "Display": {},
            "System": {
              "application": {
                "applicationId": "amzn1.ask.skill.xxxxx"
              },
              "user": {
                "userId": "amzn1.ask.account.xxxxx"
              },
              "device": {
                "deviceId": "amzn1.ask.device.xxxxx",
                "supportedInterfaces": {
                  "AudioPlayer": {},
                  "Display": {
                    "templateVersion": "1.0",
                    "markupVersion": "1.0"
                  }
                }
              },
              "apiEndpoint": "xxxxx",
              "apiAccessToken": "xxxxx"
            }
          },
          "request": {
            "type": "LaunchRequest",
            "requestId": "",
            "timestamp": "2018-04-30T00:27:07Z",
            "locale": "ja-JP",
            "shouldLinkResultBeReturned": false
          }
        }
      },
      "invocationResponse": {
        "body": {
          "version": "1.0",
          "response": {
            "outputSpeech": {
              "type": "SSML",
              "ssml": " 点数を教えてと言ってください。 "
            },
            "reprompt": {
              "outputSpeech": {
                "type": "SSML",
                "ssml": " 親の20符3翻の点数を教えてと言ってください。 "
              }
            },
            "shouldEndSession": false
          },
          "sessionAttributes": {},
          "userAgent": "ask-nodejs/1.0.25 Node/v6.10.3"
        }
      },
      "metrics": {
        "skillExecutionTimeInMilliseconds": 127
      }
    }
  }
}

おぉ…返ってくる!

本投稿では、リクエストした結果からresult.skillExecutionInfo.invocationResponse.body.response.outputSpeech.ssmlの結果を出力するまでがゴールです。

シナリオテスト

シナリオテストなんて書いてますが、凝ったことはしていません。

まずは、ASK CLIに食わせる会話をテキストに書き込んでいきます。

シナリオの作成

じゃらじゃらを開いて
ストップ
じゃらじゃらで子の点数を教えて
20
リャン

これをask simulateコマンドの--textオプションに渡していきます。

simulateコマンドの実行

ask simulateに前項で作成したテキストを渡すため、以下のコマンドを使用します。

  • cat
  • xargs(テキストの会話を--textオプションに渡す)
  • sed(結果を加工 タグの除去など)
  • jq

環境に合わせて以下を設定してください。

  • プロファイル名
  • スキルID
simulate-staging.sh
: > simulate-result-staging.log

cat conversation-staging.txt \
| xargs -n 1 -J % ask simulate --profile ask-profile-staging --skill-id amzn1.ask.skill.xxxx --locale ja-JP --text % \
| jq -r .result.skillExecutionInfo.invocationResponse.body.response.outputSpeech.ssml \
| sed -e 's/<[^>]*>//g' | sed 's/^[ \t]*//' >> simulate-result-staging.log

シミュレート結果

結果はこんな感じです。

点数を教えてと言ってください。 
また、呼んでくださいね! 
null
null
20符2翻の点数は、ツモは親が700点、子が400点です。 

ダイアログモデルを利用しているため、スロット収集中はoutputSpeech部分は結果が返ってきません。
そのため、nullが出力されています。

今後拡張していきたいなぁと思います。

まとめ

simulateコマンドを使って、シナリオテストを行いました。
実機で確認する前に、単体テスト、機能テストさらにsimulateコマンドでシナリオテストをすることで事前に問題が見つけやすくなりますね!

余談

simulateコマンドの日本語対応はいつされたんでしょうね・・・?
Change Logからはわかりませんでした。。。

ドキュメント(英語!)は細かくチェックしましょう!

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4