【发布时间】:2019-09-28 03:56:00
【问题描述】:
您好,我想将我的 watson 助手与 alexa 设备连接,为此我需要 Amazon 开发技能包和 AWS lambda。但我无法连接 watson,因为我的承诺有问题,而且我在亚马逊开发者控制台中看不到我的代码日志。我的助手负责 nodeJs 应用程序。
我尝试了一些代码:
const MyNameIsIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SearchIntent';
},
async handle(handlerInput) {
assistant.createSession({
assistant_id: assistant_id
})
.then(res => {
session_id = res.session_id;
})
.catch(err => {
console.log(err);
});
assistant.message({
assistant_id: assistant_id,
session_id: session_id,
input: {
'message_type': 'text',
'text': "hello"
}
})
.then(res => {
console.log(JSON.stringify(res, null, 2));
speechText = res.output.generic.response.text;
})
.catch(err => {
speechText = err;
});
}, function(err){
speechText = "Problem with Api call";
});
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
},
};
还有其他的承诺方式:
try{
let res = await assistant.createSession({
assistant_id: assistant_id
});
session_id = res.session_id;
let message = await assistant.message({
assistant_id: assistant_id,
session_id: session_id,
input: {
'message_type': 'text',
'text': "hello"
}
});
speechText = message.output.generic.response.text;
}catch(err){
speechText = err;
}
speechText 的结果应该是“Good day to you”,这是来自 Watson 的回应。但现在 Alexa 说“抱歉,我听不懂命令。请再说一遍。”
您是否有其他方法可以尝试使用其他方式来实现承诺?谢谢你!
【问题讨论】:
-
这个例子只有
text在input,github.com/watson-developer-cloud/node-sdk/blob/…中的属性。 -
即使这个测试用例也是如此:github.com/watson-developer-cloud/node-sdk/blob/…
标签: node.js amazon-web-services promise ibm-watson alexa-skills-kit