通过ask-smapi-sdk启用技能时传递登录凭据



我正在构建/部署流程中为我的Alexa技能进行话语和其他自动化测试。现在我还想使用模拟API(https://developer.amazon.com/en-US/docs/alexa/smapi/skill-simulation-api.html)做整个对话流程,但我马上就被卡住了。我的技能使用帐户链接,所以不知何故,我需要为用户传递凭据。在文档中,除了会话id、区域设置和话语之外,我看不到任何其他传递参数的方法。我应该以某种方式使用LWA配置文件登录我的服务吗?在这种情况下,我该怎么做(因为这只是客户端id和客户端机密,没有电子邮件/密码(?

这就是我为LWA配置文件设置javascript代码的方式(它适用于除了模拟API和调用API之外的所有请求(。

const ASK = require("ask-smapi-sdk");
const refreshTokenConfig = {
clientId: "amzn1.application-oa2-client.xxx",
clientSecret: "xxx",
refreshToken: "Atzr|xxx",
};
const smapiClient = new ASK.StandardSmapiClientBuilder()
.withRefreshTokenConfig(refreshTokenConfig)
.client();

如果我现在使用模拟API调用此技能,那么请求/响应示例将类似于此。

await smapiClient.setSkillEnablementV1(skillId, "development");
const response = await smapiClient.simulateSkillV2(skillId, "development", {
device: {
locale: "en-US",
},
input: {
content: "Alexa, ask mySkill to do something",
},
session: {
mode: "FORCE_NEW_SESSION",
},
});

response现在将在响应json中包含此部分。

body: {
version: "1.0",
response: {
outputSpeech: {
type: "SSML",
ssml: "<speak>Hi, to use mySkill, please go to your Alexa app and link your mySkill account.</speak>",
},
card: { type: "LinkAccount" },
shouldEndSession: true,
type: "_DEFAULT_RESPONSE",
},
sessionAttributes: {
...
},
userAgent: "ask-node/2.10.1 Node/v12.19.0",
},
},

重复我的问题,我如何以编程方式登录用户,我应该以某种方式使用我的LWA配置文件,还是有其他进程?

谢谢!

我为此制作了两个类,以使我的生活更轻松

技能模拟:

const fetch = require('node-fetch');
class simulationId{

constructor(){
this.token = process.env.TOKEN
}

async requestSimulationId(utterance, skillId, locale){
var requestBody = 
{
"session": {
"mode": "FORCE_NEW_SESSION"
},
"input": {
"content": utterance
},
"device": {
"locale": locale
}
}
const rawResponse = await fetch(skillId, {

method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': this.token
},
body: JSON.stringify(requestBody)
});

const buildResponse = rawResponse.json();
return buildResponse;
}
}
module.exports = simulationId;

模拟响应:

const fetch = require('node-fetch');
class simulationResponse{

constructor(){
this.token = process.env.TOKEN

}
async requestSimulationResponse(simulationId, skillId){
const rawResponse = await fetch(skillId+simulationId.id, { 
method: 'GET',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': this.token
}});

const buildResponse = rawResponse.json();

return buildResponse;

}
}
module.exports = simulationResponse;

最新更新