Amazon Alexa Smart Home Skill 增加订阅事件

我这里订阅的是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"
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值