我这里订阅的是Skill enable和skill disable消息。
参考:Skill Events in Alexa Skills | Alexa Skills Kit
这里有些先决条件:
权限提示的问题
You must set up your skill to prompt the customer to grant the appropriate permissions. Your skill.json file requires a permissionsInfo object if you include list events in your skill manifest, as described in Update your skill definition to include events.
文件中必须添加event节点
Your skill manifest must include an events object which includes your subscriptions to events, as seen in the Skill Manifest.
manifest
这里有一个demo,演示怎么处理订阅事件
For a demo that shows how to configure event subscriptions in a skill manifest, see the Delete Persistent Attributes Demo in the alexa-cookbook repo on GitHub.
这里就是必须在aws lambda中添加Alexa Skills Kit触发器,看下面的图
You must ensure that your AWS Lambda function endpoint is configured with an Alexa Skills Kit trigger. You can do this in the AWS Console, as described here.
首先要安装ask-cli,请参考
Quick Start: Alexa Skills Kit Command Line Interface (ASK CLI) | Alexa Skills Kit
现在利用ask-cli来修改manifest以来订阅事件,
Add Events to Your Skill | Alexa Skills Kit
首先下载原先的skill的manifest文件,下载后最好备份下。
ask smapi get-skill-manifest -s amzn1.ask.skill.xxx > skill.json
这里需要在manifest文件中添加需要订阅的事件,这里有一个官方示例的manifest文件。
Skill Manifest Examples | Alexa Skills Kit
这里要加入的节点就是event:配置处理event的lambda端点,也就是由谁来处理事件
"events": {
"endpoint": {
"uri": "arn:aws:lambda:us-east-1:xxxe"
},
"subscriptions": [
{
"eventName": "SKILL_ENABLED"
},
{
"eventName": "SKILL_DISABLED"
},
{
"eventName": "SKILL_PERMISSION_ACCEPTED"
},
{
"eventName": "SKILL_PERMISSION_CHANGED"
},
{
"eventName": "SKILL_ACCOUNT_LINKED"
}
],
"regions": {
"NA": {
"endpoint": {
"uri": "arn:aws:lambda:us-east-1:xxx"
}
}
}
},
然后将manifest文件更新到skill上
ask smapi update-skill-manifest -s amzn1.ask.skill.xxx -g development --manifest "file:skill.json"
然后终端会提示我们要验证一下
[Warn]: This is an asynchronous operation. Check the progress using the following command: ask smapi get-skill-status --skill-id amzn1.ask.skill.xxx --resource manifest --profile default
Command executed successfully!
执行:
ask smapi get-skill-status --skill-id amzn1.ask.skill.xxx --resource manifest --profile default
终端打出,成功更新。完成订阅
profile default
{
"manifest": {
"eTag": "a83ba1e2babb738880ffc809c8875122",
"lastUpdateRequest": {
"status": "SUCCEEDED"
}
}
}