Amazon Alexaask-cli

SFB (Skill Flow Builder)でビルドしたAlexaスキルをデプロイする

Alexaでストーリー性のあるスキルを作るためのエディタ”Skill Flow Builder Editor”を触ってみた (Mac版) デプロイについてはAWS / Node.jsよりのトピックなので、こちらのブログで […]

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

Alexaでストーリー性のあるスキルを作るためのエディタ”Skill Flow Builder Editor”を触ってみた (Mac版)

デプロイについてはAWS / Node.jsよりのトピックなので、こちらのブログで紹介します。

プロジェクトディレクトリへ移動する

まずはプロジェクトが保存されたディレクトリへ移動しましょう。サンプルプロジェクトをビルドした状態だと、おそらくこのような構成のはずです。

$ tree -L 2
.
├── abcConfig.json
├── baked
│   └── en-US
├── code
│   ├── dist
│   ├── extensions
│   ├── index.ts
│   ├── node_modules
│   ├── package.json
│   ├── tsconfig.json
│   └── yarn.lock
└── content
    ├── MANIFEST.json
    ├── NOTES.md
    ├── en-GB
    ├── en-US
    ├── languageStrings.json
    └── story.abc

9 directories, 9 files

abcConfig.jsonにスキル情報を入力する

abcConfig.jsonがプロジェクトルートに存在します。このファイルの以下の値を変更しましょう。

"ask-skill-directory-name": ASK CLIで使用するスキルの名前です。AWS Lambda関数名とスキル名は、この値から取得します。このフィールドには、アルファベットの大文字および小文字(A~Z、a~z)、数字(0~9)、アンダースコア(_)、ダッシュ(-)を含めることができます。

"skill-invocation-name": ユーザーがスキルを呼び出す方法を定義します。詳細については、ユーザーによるカスタムスキルの呼び出しを参照してください。

"publish-locales": Alexaがサポートするロケールのリストです。これらのロケールがスキルの公開先となります。

https://developer.amazon.com/ja/docs/custom-skills/set-up-the-skill-flow-builder-as-a-developer.html#deploy-your-alexa-skill

ざっとサンプルに手を入れた形がこちらです。S3やDynamoDBのリソースを作ると思われるパラメーターがありますね。S3バケット名はグローバルに一意なので注意しましょう。

{
    "prod": {},
    "beta": {},
    "alpha": {},
    "dev": {},
    "prod-en-us": {},
    "beta-en-us": {},
    "alpha-en-us": {},
    "dev-en-us": {},
    "en-us": {},
    "en-gb": {},
    
    "default": {
        "ask-profile-name": "default",

        "aws-profile-name": "default",

        "skill-invocation-name": "My First SFB",

        "dynamo-db-session-table-name": "my-first-sfb-sessions",

        "s3-domain-name": "s3.amazonaws.com",

        "s3-bucket-name": "alexa-ml",

        "ask-skill-directory-name": "my-first-sfb",

        "publish-locales": [
            "en-US"
        ],

        "update-string-with-source": true,

        "story-title": "My First SFB",

        "story-id": "untitled-project",
        
        "abc-baked-filename": "baked_story.json",
        
        "abc-recording-script-filename": "vo_script.txt",

        "public-resource-folders": ["audio", "images", "vo"],

        "polly-config": {
            "enabled": false,
            "combineAudioTags": true,
            "dontUseCache": false
        },

        "default-narrator": {
            "enabled": false,
            "name": "Matthew",
            "pitch": "+10%",
            "rate": "112%",
            "volume": "1.0"
        },
        
        "snippet-map-filename": "Snippets.json",
        "apl-templates-filename": "apl-templates.json",
        "custom-slottype-filename": "SlotTypes.json",
        "isp-config-filename": "ProductISPs.json"
    }
}

sfb用のCLIをインストールする

ビルド・デプロイに必要なCLIをインストールします。

$ npm i -g  @alexa-games/sfb-cli
-games/sfb-cli/dist/bin/alexa-sfb
+ @alexa-games/sfb-cli@1.0.2
added 351 packages from 667 contributors in 24.791s

デプロイする

あとはデプロイするだけです。

SFBのプロジェクトをいつものASK CLIで作られたプロジェクト形式に変換してからデプロイされます。

$ npx alexa-sfb deploy .
-------------------- Update Skill Project --------------------
Skill Id: amzn1.ask.skill.xxxxx-xxxxx-xxxx-xxxx
Skill metadata deploy finished.

Model submitted. Please use the following command to track the model build status:
    ask api get-skill-status -s amzn1.ask.skill.xxxxx-xxxxx-xxxx-xxxx

Lambda deployment finished.
Lambda function(s) created:
  [Lambda ARN] arn:aws:lambda:us-east-1:99999999999:function:ask-custom-my-first-sfb-default
[Info]: No in-skill product to be deployed.
Your skill is now deployed and enabled in the development stage. Try simulate your Alexa skill skill using "ask dialog" command.
  Creating a copy of .ask/config for safe keeping...
✔ Deployment finished in 52758 ms.

成功したら、スキル開発コンソールからテストすることが可能になります。

スロットに日本語を入れると死ぬ

こういうエラーメッセージが表示されてデプロイが失敗します。

Error code: 400
{
  "message": "Interaction model is not valid.",
  "violations": [
    {
      "message": "InvalidSlotName: Slot name \"はいSlot\" in intent \"FlexibleAnswerIntent\" is invalid. Slot names must begin with an alphabetic character and may only contain alphabetic characters, periods, and underscores."
    }
  ]
}
✘ npx ask deploy --no-wait --force --profile default non-zero return code: 1

ちょっといい解決方法が思いつかないので、だれかいい解決方法ください。

余談

デプロイコマンドは内部でASK CLIを使っています。なので.deploy/<SKILL_NAME>ディレクトリ配下に見慣れたファイル群がでてきます。

$ npx alexa-sfb deploy .
$ tree .deploy/ -I node_modules
.deploy/
├── dist
│   ├── abcConfig
│   │   └── abcConfig.json
│   └── res
│       ├── en-US
│       │   ├── ProductISPs.json
│       │   ├── SlotTypes.json
│       │   ├── Snippets.json
│       │   ├── apl-templates.json
│       │   ├── baked_story.json
│       │   └── en-US.json
│       ├── ja-JP
│       │   ├── ProductISPs.json
│       │   ├── SlotTypes.json
│       │   ├── Snippets.json
│       │   ├── apl-templates.json
│       │   ├── baked_story.json
│       │   └── ja-JP.json
│       └── languageStrings.json
└── my-first-sfb
    ├── LICENSE.txt
    ├── README.md
    ├── hooks
    │   ├── post_new_hook.ps1
    │   ├── post_new_hook.sh
    │   ├── pre_deploy_hook.ps1
    │   └── pre_deploy_hook.sh
    ├── instructions
    │   ├── cli.md
    │   ├── create-alexa-hosted-function.md
    │   ├── create-aws-hosted-function.md
    │   ├── customize-skill-content.md
    │   ├── setup-vui-alexa-hosted.md
    │   ├── setup-vui-aws-hosted.md
    │   └── test-using-simulator.md
    ├── lambda
    │   └── custom
    │       ├── abcConfig
    │       │   └── abcConfig.json
    │       ├── extensions
    │       │   └── ExtensionLoader.js
    │       ├── ffmpeg
    │       ├── index.js
    │       ├── package-lock.json
    │       ├── res
    │       │   ├── en-US
    │       │   │   ├── ProductISPs.json
    │       │   │   ├── SlotTypes.json
    │       │   │   ├── Snippets.json
    │       │   │   ├── apl-templates.json
    │       │   │   ├── baked_story.json
    │       │   │   └── en-US.json
    │       │   ├── ja-JP
    │       │   │   ├── ProductISPs.json
    │       │   │   ├── SlotTypes.json
    │       │   │   ├── Snippets.json
    │       │   │   ├── apl-templates.json
    │       │   │   ├── baked_story.json
    │       │   │   └── ja-JP.json
    │       │   └── languageStrings.json
    │       └── yarn.lock
    ├── models
    │   ├── en-US.json
    │   └── ja-JP.json
    └── skill.json

16 directories, 49 files

デプロイに失敗する場合、この中をみてビルドファイルがおかしなことになっていないか見ると良いでしょう。

余談2

ものすごくCatchAllしてからコードで解決してる感があるんですが、実際どうなんでしょうかねこれ・・・

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

WP Kyotoサポーター募集中

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

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

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

Related Category posts