Alexa Skill工作正常,但说:所请求技能的响应有问题

时间:2019-01-22 20:25:44

标签: node.js aws-lambda alexa alexa-skills-kit alexa-skill

对于我的Alexa技能,在触发“ ja”意图之后,该技能应向我的数据库发出一个HTTP PATCH请求,并在该数据库中通过加1来更改数字。当我在alexa开发人员控制台中测试该技能并触发“ ja”意图时,alexa回答:“所请求的技能的响应存在问题”,但是所有http请求都通过并起作用(该数字已更改)。当我从代码中删除http请求时,错误消失了。

这是http PATCH请求

async function patch(id,data) {
  return await new Promise(((resolve, reject) => {

  var options = {
    host: 'myhostname',
    path: 'my/path',
    method: 'PATCH',
    headers: {
        "Authorization": "Bearer adsasdasdasdas",
        "Content-Type": "application/x-www-form-urlencoded"
    }
};


const request = https.request(options, (response) => {
  response.setEncoding('utf8');
  let returnData = '';

  response.on('data', (chunk) => {
    returnData += chunk;
  });

  response.on('end', () => {
    resolve(JSON.parse(returnData));
  });

  response.on('error', (error) => {
    reject(error);
  });
});
request.write(data);
request.end();

  }));
  }


  function buildPatchData(number) {

var writeData = querystring.stringify({
  'callsthismonth': number

  });

 return writeData;
}

这是“ ja”意图:

    'ja': async function () {

  const token = this.event.context.System.user.accessToken;
var Id = String(token);


let number = await buildPatchData(10);
let patchRequest = await patch(Id,number);




await this.emit(':tell', 'Ok, thanks for using our skill!');


    },

0 个答案:

没有答案