LoginSignup
8
5

More than 5 years have passed since last update.

Alexa Skill Kit (ASK) のCLIによるテスト実行(ask simulate)について

Last updated at Posted at 2018-03-16

概要

  • Alexaスキル開発におけるテストの仕方には各種あります。
    • Developer PortalからTest Simulatorを動かす方法
    • local環境でLambdaを擬似的に動かす方法
    • 実機で動かす方法
    • Alexa Skill Kit Command Line Interface(ask-cli)を使う方法 (NEW 2017/09)
  • 今回は4番目のask-cliのsimulate機能について書く
    • 特に、ワンショットで終わるスキルは現状少ないため、多少の会話のキャッチボールが必要なスキルでこのツールは使えるかの検証になります。

Alexa Skill Kit Command Line Interface(ask-cli)とは

ASKコマンドラインインターフェース(ask-cli)は、Alexaスキルおよび関連するAWS Lambda関数を管理するためのツールです。

公式リファレンスクイックスタートあたりが役に立ちます。

前提条件

バージョンは下記の通りです。

  • ask-cli: 1.1.2
  • node: v6.10.3

ask simulateコマンドとは

じつは公式リファレンスのaskコマンド一覧にはのっていないのですが、 ask deployすると下記の文章にちかい説明が発行されます。

The ask deploy command automatically enables your deployed skill, so you can immediately start testing it on your device or using the ask simulate command. You can also use the service simulator on the developer portal.
(スキルデプロイしたから実機かask simulateかDeveloper Portalからテストできるよ)

ヘルプを叩いても確かにいます。
では実際に使ってみましょう。

$ ask --help

  Commands:

    init [options]      initialize the ask-cli with your Amazon developer account credentials
    deploy [options]    deploy a skill to your developer account
    new [options]       create a new skill project on your computer
    clone [options]     clone an existing skill project on your computer
    simulate [options]  simulate a user using your skill
    lambda              list of AWS Lambda commands
    api                 list of Alexa Skill Management API commands
    help [cmd]          display help for [cmd]

ask simulate 使ってみた

使い方の確認

まずは使い方がわからないのでhelpしてみると、下記の通り出力されます。シンプルですね。

$ ask simulate --help

  Usage: simulate <[-f|--file <file-path>] | [-t|--text <text>]> [-l|--locale <locale>] [-s|--skill-id <skill-id>] [-p|--profile <profile>] [--debug]

  simulate a user using your skill

  Options:

    -f, --file <file-path>     path for simulate input file
    -t, --text <text>          text for utterance text
    -l, --locale <locale>      locale for the utterance text
    -s, --skill-id <skill-id>  skill-id for the skill
    -p, --profile <profile>    ask cli profile
    --debug                    ask cli debug mode
    -h, --help                 output usage information

コマンド叩いてみた

何も考えず、ask deployしたスキルを試してみます。長いので一部出力省略してます。
(xxxxのところには各自環境に応じたパラメータを入れてください)


$ ask simulate -t "xxxxを開いて" -s amzn1.ask.skill.xxxx -l ja-JP

✓ Simulation created for simulation id: xxxxxxx
◠ Waiting for simulation response{
  "id": "xxxx",
  "status": "SUCCESSFUL",
  "result": {
    "skillExecutionInfo": {
      "invocationRequest": {
        "endpoint": "arn:aws:lambda:xxxx",
        "body": {
          // Developer PortalでテストしたときのリクエストのJSON
        }
      },
      "invocationResponse": {
        "body": {
          // Developer PortalでテストしたときのレスポンスのJSON
        }
      },
      "metrics": {
        "skillExecutionTimeInMilliseconds": 130
      }
    }
  }
}

上記の通り、発話した内容に応じてSpeech To Text (STT)で解釈されたリクエストとLambda処理されたレスポンスが得られることがわかりました。

複数の発話を処理させたい

殆どのスキルでワンショットで終わるスキルは少なくて多少の会話のキャッチボールがあるかと思います。それをできるかの検証です(正直、これがメイン目的です)。
コマンドのヘルプを見る限り、下記の選択肢が取りえそうなので試してみました。

  • -tオプションを連続で処理させる
  • -fオプションで一発で入れる

-tオプションを連続で処理させる

結論からいうと下記の通り死にました。

$ ask simulate -t "xxxx" -s amzn1.ask.skill.xxxx -l ja-JP

✓ Simulation created for simulation id: xxxx
◞ Waiting for simulation response{
  "id": "xxxx",
  "status": "FAILED",
  "result": {
    "error": {
      "message": "An unexpected error occurred."
    }
  }
} 

二回目の処理ということで-tオプションで指定した文言には 、Invocation Nameをいれてなかったのですが、Invocation Nameがないのでスキルが上手く起動せずに死んだ、という感じに見えました。

-fオプションで一発で入れる

では、-fオプション使えばどうか?という話なのですが、先駆者が地雷を踏んでくれていたようで、、、
ask-cliのファイルフォーマット知りたいを見ると、複数エントリーのリクエストは処理できないとあります。よって、キャッチボールはできないという結論に至りました;;

結論

  • 単発で処理確認する分には意味があります。
    • ローカルLambdaを使わなくても確認可能
    • ただし、ローカルLambdaと比べると圧倒的に遅いのでそこは認識しておく必要有
  • 複数の処理を確認したいときは、やはりテストシミュレータ、alexa-conversation, 実機確認が必要
8
5
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
5