我的代码没有运行,任何人都可以帮忙。无法说出文本,我可以返回处理程序输入响应吗?测试函数是一个 http 调用,可能需要 tieme。
function test(url, number)
{
return 5;
}
function speak(handlerInput) {
return handlerInput.responseBuilder
.getResponse();
}
const NumberFactIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'NumberFactIntent';
},
handle(handlerInput) {
const theNumber = handlerInput.requestEnvelope.request.intent.slots.number.value;
const repromptOutput = " Would you like another fact?";
const URL = "http://numbersapi.com";
test(URL, theNumber).then(function (data) {
console.log("data is " + data);
handlerInput.responseBuilder
.speak("Test Data")
.reprompt(repromptOutput)
return speak(handlerInput);
}).catch(function (data) {
console.log("error is " + data);
handlerInput.responseBuilder
.speak(`I wasn't able to find a fact for ${theNumber}` )
.reprompt(repromptOutput)
return speak(handlerInput);
});
}
};