你好,我想连接我的watson assisstant与alexa设备,为此,我需要亚马逊开发技能包和AWS lambda。但我无法连接watson,因为我的承诺有问题,而且我在amazon开发人员控制台中看不到我的代码日志。我的助手负责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的结果应该是“祝你今天好”,这是来自Watson.but的回复,现在Alexa说:“对不起,我听不懂命令。请再说一遍。”
你有没有其他的方法来尝试一下?谢谢你!
发布于 2019-05-11 06:45:43
听起来您已经成功地呼叫了Watson Assistant,并且如果在对话框节点中配置的响应是"Good day to you“-which就是您收到的响应,则该连接正在工作。但是,如果我没记错的话,Alexa期望的响应是一个JSON对象,而不是一个字符串。因此,您需要格式化响应以满足Alexa的需求。
快速浏览此站点:https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html
表示以下是必需响应json包的一个很好的例子。
{
"version": "string",
"sessionAttributes": {
"key": "value"
},
"response": {
"outputSpeech": {
"type": "PlainText",
"text": "Plain text string to speak",
"playBehavior": "REPLACE_ENQUEUED"
},
"reprompt": {
"outputSpeech": {
"type": "PlainText",
"text": "Plain text string to speak",
"playBehavior": "REPLACE_ENQUEUED"
}
},
"shouldEndSession": true
}
}请注意。我不能确认,因为我从来没有把Alexa技能带到生产中(只在开发环境下构建了它们作为演示,并与有限的几个人分享)。但我被告知,亚马逊并不喜欢他们将工作转移给Watson的技能。这真是个遗憾。
https://stackoverflow.com/questions/56060603
复制相似问题