【发布时间】:2019-09-27 08:38:03
【问题描述】:
您好,我想将我的 watson 助手与 alexa 设备连接, 为此,我需要 Amazon 开发技能包和 AWS lambda。但我无法连接 watson,因为我的承诺有问题,而且我在亚马逊开发者控制台中看不到我的代码日志。我的助手负责 nodeJs 应用程序。
这是我的 watson 的标题:
const assistant = new AssistantV2({
version: '2019-02-28',
iam_apikey: 'apiSecretKey',
url: 'https://gateway-lon.watsonplatform.net/assistant/api'
});
const assistant_id = "assistantIDSecret" ;
我尝试了一些代码:
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 说“抱歉,我听不懂命令。请再说一遍。”
您还有其他方法可以尝试吗?谢谢你!
【问题讨论】:
标签: node.js promise aws-lambda alexa-skills-kit watson-assistant