这段代码可以完美地工作
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 (一种云服务)上,所以我无法想象任何环境因素都会导致这个问题。
感谢您的帮助。
发布于 2018-05-04 01:34:30
这段代码可以工作
var ajax = require('request-promise');
//...
app.intent('marcopolo', {
'slots': {},
'utterances': ['marco']
}, function(req, res){
ajax('http://google.com').then(function() {
console.log('success');
res.say('polo').send();
}).catch(function(err) {
console.log(err.statusCode);
res.say('not working').send();
});
return false;
});事实证明,return语句是必需的,而且它必须是false。我找不到任何有记录的地方,也找不到任何关于return false对app.intent()意味着什么的解释。返回undefined或Promise对象会中断交互。
https://stackoverflow.com/questions/50145295
复制相似问题