0

我正在为我的 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 配置文件还是有其他流程?

谢谢!

4

1 回答 1

0

我为此做了两节课,让我的生活更轻松

技能模拟:

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;
于 2021-02-25T05:45:31.633 回答