【发布时间】:2018-10-13 04:36:52
【问题描述】:
这段代码完美运行
var app = new Alexa.app('appName');
// ...
app.intent('marcopolo', {
'slots': {},
'utterances': ['marco']
}, function(request, response){
console.log('marco worked');
response.say('polo').shouldEndSession(false).send();
});
// Alexa says: polo
// Log says: marco worked
此代码不起作用
var app = new Alexa.app('appName');
// ...
app.intent('marcopolo', {
'slots': {},
'utterances': ['marco']
}, function(request, response){
console.log('marco started');
return ajax('http://www.google.com')
.then(function(){
console.log('marco response');
response.say('polo').shouldEndSession(false).send();
})
.catch(function(){
console.log('marco error');
response.say('polo, I think').shouldEndSession(false).send();
});
});
// alexa says: (no response)
// Log says: marco started
我尝试使用 request-promise 和 superagent 作为 Ajax 库,结果相同。
以下是版本:
"alexa-app": "^2.4.0",
"request-promise": "^2.0.0",
"superagent": "^3.8.3"
这是我的 Alexa 技能意图:
"intents": [
{
"name": "marcopolo",
"slots": [],
"samples": [ "marco" ]
}
]
我从未见过app.intent() 使用return 语句的示例,但我在网上某处阅读了一条回复,该回复建议在app.intent() 中为异步返回一个promise,但此更新没有效果:
return ajax('http://www.google.com')
我还认为它可能很慢并且超时,但我的 Alexa 技能超时设置为 5 分钟。我有其他技能可以毫无问题地执行 Ajax,并且代码都在 Lambda(一种云服务)上运行,所以我无法想象任何环境会导致问题。
任何帮助表示赞赏。
【问题讨论】:
-
我找到了this documentation of Async Handlers,但似乎在做同样的事情。我一定没有正确处理承诺......
标签: javascript ajax amazon-web-services aws-lambda alexa