使用 Alexa 技能管理 (SMAPI) 与 CLI

Using Alexa Skill Management (SMAPI) vs CLI

现在它可用了,我想使用 Alexa SMAPI 来管理 Skill 模型,就像我可以通过 Dialogflow API. In the SMAPI docs 在 Google 上使用 Actions 一样,它说:

"If you are building your own tool or service to integrate with the API, you will need to implement OAuth 2.0 integration with Login with Amazon to request your users’ authorization and retrieve access tokens used to call the Skill Management API. See the Developer Guide for Login With Amazon. The API requires using the authorization code grant type."

要使用 Dialogflow API,您只需提供来自代理的开发人员访问令牌。要使用 SMAPI,每个请求都必须有一个授权 header,其值应该是从 Login with Amazon 检索到的访问令牌。

我有一个关于应用 LWA Dev Guide 中的说明获取此访问令牌的基本问题。这一切都是为了告诉您如何在网站上使用 LWA。我没有设置来自网站的 SMAPI 调用。我只想拥有一个 Lambda 函数,该函数被触发以启动 nodejs 代码来更新技能。我如何在这种情况下应用这些说明?根据以上,指南第 25 页的授权代码授予部分适用。有没有办法只获取我可以用来直接获取 access_token 的授权码,而不是通过 redirect_uri?换句话说,我想知道您是否可以在网站之外使用 LWA 框架和 SMAPI。

或者 SMAPI 真的只设置为与网站一起使用,而我们只是应该将 CLI 用于我描述的用例吗?

客户必须使用 Amazon.com 登录名来验证和授权您的应用代表他们使用 API。该部分需要网络浏览器。

一旦完成并且您拥有访问令牌和刷新令牌,您将永远不需要再次使用网络...除非客户通过您提供的机制注销您的服务或取消对您服务的授权通过亚马逊帐户控制面板中的“使用亚马逊应用程序登录”控件。然后他们需要通过 Login with Amazon 重新登录或通过 Login with Amazon 重新授权您的应用。

更新:考虑您的意见...

听起来您只是想为自己编写脚本并且无需在其中编写身份验证工作流程就可以这样做,而是使用您从开发人员控制面板获得的一些访问代码。

所以这里有一个可能的解决方案:在您控制的机器上设置 Alexa Skills Kit 命令行界面 (ASK CLI)。

npm install -g ask-cli
ask init

它将为您打开一个浏览器并运行为您打开一个授权。然后它将您的访问和刷新令牌写入本地计算机上的配置文件。如果您使用 Linux 或 Mac 终端,您可能需要 "sudo" 安装。

documentation of the init command 告诉您在哪里可以找到您的配置文件。将你的令牌从它复制到你的脚本,你应该能够 运行 SMAPI 命令关于与该开发者帐户相关联的技能(我自己没有尝试过,但看起来你在设置时请求相同的范围使用 Amazon 登录 SMAPI 或在 ASK CLI init 中使用它,因此这些令牌应该有效)。

您仍然需要定期刷新访问令牌,但您不必建立任何网站架构。

有帮助吗?

我在查找有关如何创建用于 SMAPI 访问的令牌而无需实施 LWA 的正确文档时也遇到了问题。 我想创建 Lambda 函数来检索技能的意图历史记录。

intent history documentation只提到需要一个LWA令牌,但没有提到如何创建一个。

可以通过 ask-cli.

创建用于 SMAPI 访问的 LWA 令牌

See here

由于链接可能会更改,因此我粘贴了文档中的摘录:

util command

The util command provides utility tools to manage Alexa skill development.

Subcommands Task Subcommand Generate LWA (Login With Amazon) access_token and refresh_token, which may be needed for use with Alexa developer tools generate-lwa-tokens generate-lwa-tokens

Generates an LWA access token and refresh token, which may be required by the skill to access Alexa development tools.

To use this feature, you must whitelist a URL following these steps:

Browse to https://developer.amazon.com/home.html.
Select Apps & Services on the top menu bar.
Select Security Profile in the submenu bar.
Pick the profile you want to use and select the Web settings tab. If you do not have a profile, you can create one by clicking Create a

New Security Profile and following the instructions. Click Edit and paste these URLs to Allowed Return URLs: http://127.0.0.1:9090/cb (if using the default option to open a browser) or https://s3.amazonaws.com/ask-cli/response_parser.html (if using the --no-browser option) Save the change.

generate-lwa-tokens command format

$ ask util generate-lwa-tokens [--scope ] [--no-browser]

我找不到我的案例需要哪些可能的范围(阅读技能的意图历史)。我假设 alexa::ask:skills:read 应该是正确的范围。但事实并非如此。它测试了与其他请求范围的令牌创建,但没有一个创建了一个让我调用意图历史的令牌。 仅在没有范围的情况下调用 ask util generate-lwa-tokens 为我创建了一个工作令牌。

您可以使用 Node.js SDK 从 JavaScript(Lambda 等)进行 SMAPI 调用,并提供文档 here

为了使用 SMAPI 进行身份验证,您需要执行以下操作:

  1. 设置 LWA 安全配置文件。
  2. 使用 ASK CLI 将您的 LWA 客户端 ID 和客户端密码交换为使用 ask util generate-lwa-tokens --client-id <Client ID> --client-confirmation <Client Secret> 的 LWA 刷新令牌。
  3. 初始化 SMAPI 节点 SDK 时使用此刷新令牌:
const Alexa = require('ask-smapi-sdk');

// specify the refreshTokenConfig with clientId, clientSecret and refreshToken generated in the previous step
const refreshTokenConfig = {
    clientId,
    clientSecret, 
    refreshToken
}
const smapiClient = new Alexa.StandardSmapiClientBuilder()
    .withRefreshTokenConfig(refreshTokenConfig)
    .client();

然后您将能够通过 SDK 上的函数调用来访问 SMAPI!

这方面的有用资源: https://levelup.gitconnected.com/email-yourself-daily-alexa-skill-metrics-updates-using-lambda-smapi-and-ses-9c16ac97c1f8