alexa技能个数_如何创建管理待办事项的Alexa技能

alexa技能个数

by Terren Peterson

由Terren Peterson

如何创建管理待办事项的Alexa技能 (How to create an Alexa skill that manages to-do lists)

I’m recognized as an Amazon Alexa Champion and have published more than twenty custom skills on the platform. I continue to look for new ways to stretch this technology, and one recent area I’ve been exploring is using Alexa to help organize everyday tasks. One of the underused features on the platform is the ability to create custom lists. Here is a brief review on how you can take advantage of this feature, and please feel free to test out the Workout Planner Skill — it’s free!

我被公认为Amazon Alexa冠军,并且已经在平台上发布了二十多种自定义技能。 我一直在寻找扩展该技术的新方法,最近一直在探索的领域是使用Alexa来帮助组织日常任务。 平台上未充分使用的功能之一是能够创建自定义列表。 以下是有关如何利用此功能的简要概述,请随时测试“ 锻炼计划者”技能 -这是免费的!

背景 (Background)

Hands-free devices like an Alexa open up the possibilities of building handy digital assistants. One of the first features that was enabled with the native device was the ability to create shopping lists. Given the retail heritage of Amazon, it’s not surprising that this came early. Saying phrases like “add shampoo to my shopping list” adds it to the user’s Amazon account. It also renders the data on other applications that the user is signed in on.

诸如Alexa的免提设备开辟了构建方便的数字助理的可能性。 本机启用的首批功能之一是创建购物清单的功能。 考虑到亚马逊的零售传承,提早推出就不足为奇了。 诸如说“将洗发水添加到我的购物清单”之类的短语会将其添加到用户的Amazon帐户中。 它还在用户登录的其他应用程序上呈现数据。

不要将Alexa带到体育馆,要列出清单 (Don’t Bring Alexa to the Gym, Bring a List)

After using the shopping list feature for a while, I started to think of other types of lists that I could create. The device has the ability to create custom lists, and I thought it might be helpful in organizing my workouts. Rather than bring a handwritten workout list, I could make one using my voice.

使用购物清单功能一段时间后,我开始考虑可以创建的其他类型的清单。 该设备具有创建自定义列表的功能,我认为这可能对组织锻炼有帮助。 不用携带手写的锻炼清单,我可以使用自己的声音制作一个锻炼清单。

I wrote a custom Alexa Skill called Workout Planner that asked questions about what types of exercises to do. It then created a list for me to track. Here’s a screenshot of what the skill creates on my phone.

我编写了一个名为“锻炼计划者”的自定义Alexa技能,询问有关进行哪种类型的练习的问题。 然后,它创建了一个列表供我跟踪。 这是该技能在我的手机上产生的屏幕截图。

使用Alexa列表的架构 (Architecture to use the Alexa Lists)

The core functionality around lists is enabled through an Alexa API that manages the entities that are rendered on the Alexa companion app.

列表周围的核心功能通过Alexa API启用,该API管理在Alexa随播应用程序上呈现的实体。

In a typical Alexa skill architecture, the API gets invoked from the Lambda function that contains the functionality of the skill. Data passed into the API call indicates if a new list should be created, what item should be added, if an item can be crossed off the list, and so on. The companion app handles all of the user interaction with the data on the list, with no additional effort by the skill developer. The user then has the ability to manage this list through the companion app, including marking items off as complete.

在典型的Alexa技能体系结构中,从包含该技能功能的Lambda函数调用该API。 传递到API调用的数据指示是否应该创建新列表,应该添加什么项目,是否可以从列表中删除项目等等。 配套应用程序可以处理用户与列表中数据的所有交互,而无需技术开发人员的额外努力。 然后,用户可以通过配套应用程序管理此列表,包括将项目标记为完成。

The voice interface is the same as any Alexa skill. Authoring a custom skill includes setup of sample utterances, intents, and so on based on the functionality being provided to the user.

语音界面与任何Alexa技能相同。 创作自定义技能包括根据提供给用户的功能来设置样本话语,意图等。

启用使用列表的权限 (Enabling Permissions to use the Lists)

When creating an advanced skill like this, the skill will need to request additional permissions. There are multiple levels of permissions and security, which all need to be in place for the skill to fully function.

当创建这样的高级技能时,该技能将需要请求其他权限。 有多种级别的权限和安全性,才能使该功能完全发挥作用,所有这些级别都必须存在。

First, the skill developer will need to acknowledge to the Alexa platform that the skill will make use of the lists. You can do this within the setup of the skill in the Developer console. The screenshot below is from the Permissions tab in the console. The sliders for both list attributes must be set.

首先,技能开发人员需要向Alexa平台承认该技能将使用列表。 您可以在开发人员控制台的技能设置范围内执行此操作。 下面的屏幕快照来自控制台的“权限”选项卡。 必须设置两个列表属性的滑块。

As the skill goes through certification, Amazon validates that the permissions are required for the skill to work. This helps manage access to the user’s data that will be gained by the developer.

随着该技能通过认证,Amazon会验证该技能正常运行需要权限。 这有助于管理对开发人员将获得的用户数据的访问。

Second, when a user enables the skill on their device, they will need to grant consent for the skill to be able to read and write their data for their account. This is enabled through the companion app, and follows an “opt-in” model to access the escalated privileges. Below is a screenshot of the sliders that need to be adjusted in the settings.

其次,当用户在其设备上启用该技能时,他们将需要同意该技能才能读取和写入其帐户数据。 这是通过配套应用启用的,并遵循“选择加入”模型来访问升级的特权。 下面是需要在设置中调整的滑块的屏幕截图。

Finally, at runtime, a consent token is created for each session that uses the skill. This token needs to be saved by the Lambda function, then passed in the header of the API call to Alexa.

最后,在运行时,将为使用该技能的每个会话创建一个同意令牌。 此令牌需要由Lambda函数保存,然后将API调用的标头传递给Alexa。

示例API调用 (Example API Call)

As highlighted in the architecture, the household API contains the core functionality required to manage the lists. There are multiple operations available within the API, and here is the documentation from Amazon. Using Node.js, here is the code used to invoke the API using the POST operation that creates a new list called “Workout Tracker”.

如体系结构中突出显示的那样,家用API包含管理列表所需的核心功能。 API中有多种可用操作,这是Amazon的文档。 使用Node.js,以下是用于使用POST操作调用API的代码,该操作创建一个名为“ Workout Tracker”的新列表。

var path = "/v2/householdlists/";     var postData = {        "name": "Workout Tracker", //item value, with a string description up to 256 characters         "state": "active" // item status (Enum: "active" only)    };            var consent_token = session.user.permissions.consentToken;
var options = {        host: api_url,        port: api_port,        path: path,        method: 'POST',        headers: {            'Authorization': 'Bearer ' + consent_token,            'Content-Type': 'application/json'        }    };
var req = https.request(options, (res) => {    console.log('statusCode:', res.statusCode);    console.log('headers:', res.headers);    var data = "";
res.on('data', (d) => {         console.log("data received:" + d);         data += d;    });    res.on('error', (e) => {         console.log("error received");         console.error(e);    });    res.on('end', function() {         console.log("ending post request");        if (res.statusCode === 201) {             var responseMsg = eval('(' + data + ')');             console.log("new list id:" + responseMsg.listId);             callback(res.statusCode, responseMsg.listId);        } else {             callback(res.statusCode, 0);        }    });});    req.end(JSON.stringify(postData));

The API returns a JSON object that includes the ListIdentifier used in subsequent calls to add items to the list.

该API返回一个JSON对象,该对象包括ListIdentifier,该ID在随后的调用中用于将项目添加到列表中。

结论 (Conclusion)

This is an easy way to leverage the voice user interface of Alexa with the ubiquity of the Alexa Companion App. Here is a link to the full repo of the skill, and if you have any ideas on how to improve — please let me know!

这是将Alexa的语音用户界面与Alexa Companion App普遍存在的一种简单方法。 这里是该技能全部回购的链接 ,如果您对改进有任何想法,请告诉我!

翻译自: https://www.freecodecamp.org/news/how-to-create-an-alexa-skill-that-manages-to-do-lists-11c4bab29ea5/

alexa技能个数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值