Amazon Alexa

ask-cliで作成済みのAlexa skillの情報を取得する

ask-cliつかってますか?ask-cliを使うと、Alexa Skillの設定をコード化できるため、ある程度運用が固まってきたスキルの管理などに便利です。逆にGUIの対話モデルビルダーが使いやすいため、これからスキル […]

広告ここから
広告ここまで

ask-cliつかってますか?ask-cliを使うと、Alexa Skillの設定をコード化できるため、ある程度運用が固まってきたスキルの管理などに便利です。逆にGUIの対話モデルビルダーが使いやすいため、これからスキルを作っていこうという方がいきなりcliから始めるのはちょっと大変かもしれません。

ということで、GUIで作ったスキルの情報をask-cliにインポートする方法をまとめます。

get-skillコマンドでスキル情報をインポートする

スキル情報はask api get-skillで取得できます。

$ ask api get-skill -h

  Usage: get-skill <-s|--skill-id <skill-id>> [-g|--stage <stage>] [-p|--profile <profile>] [--debug]

  get a skill

  Options:

    -s, --skill-id <skill-id>  skill-id for the skill
    -g, --stage <stage>        stage for the skill
    -p, --profile <profile>    ask cli profile
    --debug                    ask cli debug mode
    -h, --help                 output usage information

実行すると、スキルの基本情報がJSONで返ってきます。

$ ask api get-skill -s amzn1.ask.skill.xxxxx-xxx-xxx-xxxx
{
  "manifest": {
    "publishingInformation": {
      "locales": {
        "ja-JP": {
          "name": "ハローアレクサ"
        }
      }
    },
    "apis": {
      "custom": {
        "endpoint": {
          "uri": "arn:aws:lambda:ap-northeast-1:9999999:function:example-development-hello"
        },
        "interfaces": []
      }
    },
    "manifestVersion": "1.0"
  }
}

ask-cliで管理する場合のファイル配置場所

ask createで作成されたファイルのうち、./skill.jsonがこのアウトプットと同じ構成となります。なので、インポートする場合は以下のような形でファイル出力してもよさそうです。

$ ask api get-skill -s amzn1.ask.skill.xxxxx-xxx-xxx-xxxx > ./skill.json

get-modelコマンドで対話モデルを取得する

インテント・スロット・サンプル発話などのビルド済み対話モデルは、api get-modelコマンドで取得できます。

$ ask api get-model -h

  Usage: get-model <-s|--skill-id <skill-id>> [-g|--stage <stage>] <-l|--locale <locale>> [-p|--profile <profile>] [--debug]

  get an interaction model for skill

  Options:

    -s, --skill-id <skill-id>  skill-id for the skill
    -g, --stage <stage>        stage for the skill
    -l, --locale <locale>      model locale for the skill
    -p, --profile <profile>    ask cli profile
    --debug                    ask cli debug mode
    -h, --help                 output usage information

実際に取得すると、以下のようになります。

$ ask api get-model -s amzn1.ask.skill.xxxxx-xxx-xxx-xxxx --stage development -l ja-JP

{
  "interactionModel": {
    "languageModel": {
      "invocationName": "ハローアレクサ",
      "intents": [
        {
          "name": "AMAZON.CancelIntent",
          "samples": []
        },
        {
          "name": "AMAZON.HelpIntent",
          "samples": []
        },
        {
          "name": "AMAZON.StopIntent",
          "samples": []
        },
        {
          "name": "ExampleIntent",
          "slots": [
            {
              "name": "sample_number",
              "type": "AMAZON.NUMBER"
            }
          ],
          "samples": [
            "こんにちはアレクサ",
            "正解は {sample_number} 番"
          ]
        }
      ]
    }
  }
}

ask-cliで管理する場合のファイル配置場所

ask craeteで作成されるファイル構成では、models/配下に対話モデルの設定が配置されます。

$ tree -L 2
.
├── lambda
│   └── custom
├── models
│   └── en-US.json

そのため、インポートする場合は、以下のようにしてファイル出力しておくとよいでしょう。

$ ask api get-model -s amzn1.ask.skill.xxxxx-xxx-xxx-xxxx --stage development -l ja-JP > ./models/ja-JP.json

Lambdaのソースコード配置場所

ask createした場合、/lambda/custom/配下にファイルが配置されています。

$ tree -L 3
.
├── lambda
│   └── custom
│       ├── index.js
│       ├── node_modules
│       ├── package-lock.json
│       └── package.json
├── models

ソースコードをここに移動させることで、Lambdaのコードもask-cliから管理できるようになります。

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts