LoginSignup
2
3

More than 1 year has passed since last update.

Alexa-hostedスキルにインポート可能なGitリポジトリを作成する(スキルパッケージ形式)

Last updated at Posted at 2020-07-11

はじめに

Alexa-hostedスキル作成時のインポート機能を試してみたかったのでGitHubにリポジトリを作成したが、マニュアルどおりにファイル配置してもエラーになってしまい、しかもこのメッセージ以外の情報がなくて原因がわからず、試行錯誤した結果、確実にうまく行く方法がこれしか思いつかなかったのでメモ。

image.png

前提

  • ASK CLI v2
  • Alexa Developer Console
  • GitHub

※作業環境 Windows

手順

  1. ask new でAlexa-hostedスキルを作成する
  2. 作成されたスキルを削除する
  3. ファイルを修正する
  4. GitHub リポジトリ作成する
  5. リポジトリへアップロードする
  6. Alexa-hostedスキルを作成する

ask new でAlexa-hostedスキルを作成する

任意のフォルダ を作成し、ask new する。
ASK CLI v2 を使っているので、生成されるフォルダ構成はv2のスキルパッケージ形式で作成される。

PS C:\hosted> ask new

? Choose the programming language you will use to code your skill:  (Use arrow keys)
> NodeJS
  Python
  Java

<ENTER>

? Choose a method to host your skill's backend resources:  (Use arrow keys)
> Alexa-hosted skills
  Host your skill code by Alexa (free).
  AWS with CloudFormation
  Host your skill code with AWS services and provision with AWS CloudFormation (requires AWS account)
  AWS Lambda
  Host your skill code on AWS Lambda (requires AWS account).
  ──────────────
  self-hosted and manage your own hosting

<ENTER>

? Please type in your skill name:  (Hello World Skill) 

test-alexa-hosted-skill-package <ENTER>

? Please type in your folder name for the skill project (alphanumeric):  (test-alexa-hosted-skill-package)

<ENTER>

/ Creating your Alexa hosted skill. It will take about a minute.      

Project directory for test-alexa-hosted-skill-package created at
        C:\hosted\test-alexa-hosted-skill-package
- Cloning Alexa Hosted Skill...warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory

Lambda code for test-alexa-hosted-skill-package created at
        ./lambda

Skill schema and interactionModels for test-alexa-hosted-skill-package created at
        ./skill-package

Skill is enabled successfully.
Hosted skill provisioning finished. Skill-Id: amzn1.ask.skill.186f4e9e-2ce0-4100-a62b-135e30f57b8f
Please follow the instructions at https://developer.amazon.com/en-US/docs/alexa/hosted-skills/build-a-skill-end-to-end-using-an-alexa-hosted-skill.html#askcli to learn more about the usage of "git" for Hosted skill.
PS C:\hosted>

作成されたスキルを削除する

ask new すると 任意のフォルダ にファイルが生成されると同時に、Alexa Developer Console 上に test-alexa-hosted-skill-package スキルが作成されてしまうので削除する。言語も 英語(米国) のため使えない。任意のフォルダ に生成されたファイルを使用する。

アクション削除 をクリックする。

image.png

はい、スキルを削除します をクリックするとスキルが削除される。

image.png

ファイルを修正する

skill.jsonen-US.json を修正する。

skill.json の変更

"regions" を削除する。
"locales""en-US""ja-JP" に変更する。

修正前:skill.json
{
  "manifest": {
    "apis": {
      "custom": {
        "endpoint": {
          "uri": "arn:aws:lambda:us-east-1:841233596264:function:186f4e9e-2ce0-4100-a62b-135e30f57b8f:Release_0"
        },
        "regions": {
          "EU": {
            "endpoint": {
              "uri": "arn:aws:lambda:eu-west-1:841233596264:function:186f4e9e-2ce0-4100-a62b-135e30f57b8f:Release_0"
            }
          },
          "NA": {
            "endpoint": {
              "uri": "arn:aws:lambda:us-east-1:841233596264:function:186f4e9e-2ce0-4100-a62b-135e30f57b8f:Release_0"
            }
          },
          "FE": {
            "endpoint": {
              "uri": "arn:aws:lambda:us-west-2:841233596264:function:186f4e9e-2ce0-4100-a62b-135e30f57b8f:Release_0"
            }
          }
        }
      }
    },
    "publishingInformation": {
      "locales": {
        "en-US": {
          "name": "test-alexa-hosted-skill-package"
        }
      }
    }
  }
}
修正後:skill.json
{
  "manifest": {
    "apis": {
      "custom": {
        "endpoint": {
          "uri": "arn:aws:lambda:us-east-1:841233596264:function:186f4e9e-2ce0-4100-a62b-135e30f57b8f:Release_0"
        }
      }
    },
    "publishingInformation": {
      "locales": {
        "ja-JP": {
          "name": "test-alexa-hosted-skill-package"
        }
      }
    }
  }
}

en-US.jsonのファイル名を変更する

修正前:en-US.json
C:\hosted\test-alexa-hosted-skill-package\skill-package\interactionModels\custom\en-US.json
修正後:ja-JP.json
C:\hosted\test-alexa-hosted-skill-package\skill-package\interactionModels\custom\ja-JP.json

GitHub リポジトリ作成する

Repository name 欄に入力して、Create repository をクリックする。

image.png

リポジトリへアップロードする

PS C:\hosted\test-alexa-hosted-skill-package> git init
Reinitialized existing Git repository in C:/work/AlexaSkills/a/hosted/test-alexa-hosted-skill-package/.git/

PS C:\hosted\test-alexa-hosted-skill-package> git add .
 :

PS C:\hosted\test-alexa-hosted-skill-package> git commit -m "init"
 :

PS C:\hosted\test-alexa-hosted-skill-package> git remote add origin https://github.com/TAKARA328/test-alexa-hosted-skill-package.git

PS C:\hosted\test-alexa-hosted-skill-package> git remote -v
origin  https://github.com/TAKARA328/test-alexa-hosted-skill-package.git (fetch)
origin  https://github.com/TAKARA328/test-alexa-hosted-skill-package.git (push)

PS C:\hosted\test-alexa-hosted-skill-package> git push -u origin master

アップロードされるとこんな感じ。
v2 のスキルパッケージ形式のフォルダ構成になっていることがわかる。

image.png

Use Git or checkout with SVN using the web URL. に表示されているURLが、Alexa-Hostedスキルのインポート時に指定するURLとなる。

image.png

Alexa-hostedスキルを作成する

Alexa Developer Console から スキルの作成 をクリックする。

image.png

スキル名 に任意の文字列を入れ、デフォルトの言語日本語(日本)を選択し、ホストするリージョンで米国西部(オレゴン)を選択する。そして、スキルを作成 をクリックする。

※日本語スキルを作成する場合は米国西部(オレゴン)を選択

image.png

スキルをインポート (白い方)をクリックする。

image.png

パブリックなGitリポジトリのURLを入力します。 欄に、先ほどのGitHubリポジトリのURLを入力し、インポートをクリックする。

image.png

けっこう時間がかかる。

image.png

だいたい1分ぐらいかな。
いつもの見慣れた画面が表示されればOK!
あとは、スキルの中身を仕上げれば完成!

image.png

何か不備があると以下のようなエラーメッセージが表示される。
だけど、何が悪いのかがわからないので対処するのが非常に困難。そのうちエラーの内容が表示されるようになると思うけど。

image.png

試してうまくいった方法

※2020年7月12日時点の情報

おわりに

なんかマニュアル通りにいかないというか、なにをどうすれば良いのかがイマイチわからなかった。今でも何が正解かわからない。

マニュアルに記載されている通りにファイルを配置しても、インポートエラーになったりするので、今のところこのやり方が良いと思ってる。

普通にデプロイできるスキルを作って、それをGitHubに置いてもダメなんだよな。

参考

2
3
1

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
2
3