node.js - Alexa:响应来自服务的响应(节点 v2 SDK)
问题描述
我正在使用 Alexa API。我想让 Alexa 响应从服务接收到的内容。
不确定在哪里添加承诺。我试过了,但 Alexa 说“请求的技能响应有问题”
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
MyService.facts().then(function(data) {
const speechText = 'No facts';
if (data) {
speechText = 'random facts: '
data.forEach(function (fact) {
speechText += fact;
})
}
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}, function(err) {
console.log(err);
});
}
};
解决方案
不使用 Promise 的响应。这个例子怎么样:
async handle(handlerInput) {
return await MyService.facts().then(function(data) {
// other stuff
});
}
推荐阅读
- c# - 列表上的Linq排序及其同一类的嵌套集合
- marklogic - 访问 narthex 时出现 404 Not Found 错误
- python - Python:如何打开文件并注释特定行?
- postgresql - 优化器如何在合并连接和散列连接之间做出决定?
- java - 修复软键盘上方的布局
- javascript - 打印完整路径javascript
- javascript - event.preventDefault(), event.stopPropagation() 在单击锚标记时无法停止页面重定向
- sql - 如果 UNION SQL Server 时表中不存在列,则拉 NULL
- node.js - 在 docker 环境中成功 CI 后如何部署到自定义服务器?
- laravel - 使用 Laravel 和 Amazon s3 显示“安全”图像的最快方法是什么?