错误:方法必须是字符串,Alexa自定义技能



同时使用 "Alexa Skill Kit"(AWS Lambda nodejs 环境(在 Alexa 自定义技能中使用 nodejs 使用 REST API POST 请求。 这是我在索引中的代码.js

'use strict';
const Alexa = require('alexa-sdk');
const request = require('sync-request');
'validateClientIntent': function() {
var json = {
"clientID": "xxxxx6EF-9D05-49CE-855C-C41CED4A83B5",
"appKey": "D/xxxxxxxxisFSMMzAbntGsrNf0yX6aafNqoyi8="
};
var options = {
url: 'http://link',
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
json: json
};
//var method = "POST";
//options = JSON.parse(options);
try {
request(options, function(err, res, body) {
if (res && (res.statusCode === 200 || res.statusCode === 
201)) {
//var body = JSON.parse(body);
var trackingId = body;
//console.log(trackingId);
//return trackingId;
this.response.speak(trackingId);
}
else {
throw (err);
}
});
}
catch (err) {
this.response.speak(err);
}
this.emit(':responseReady');
},

在这里我使用的是"同步请求",因此请使用以下方法,如 "https://www.npmjs.com/package/sync-request">

var request = require('sync-request');
var res = request('POST', 'https://example.com/create-user', {
json: {username: 'ForbesLindesay'},
});
var user = JSON.parse(res.getBody('utf8'));

最新更新