發生這種情況是因爲您發送的所有內容都是字符串,而Lex期望以特定格式回覆,例如
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled or Failed",
"message": {
"contentType": "PlainText or SSML",
"content": "Message to convey to the user. For example, Thanks, your pizza has been ordered."
},
"responseCard": {
"version": integer-value,
"contentType": "application/vnd.amazonaws.card.generic",
"genericAttachments": [
{
"title":"card-title",
"subTitle":"card-sub-title",
"imageUrl":"URL of the image to be shown",
"attachmentLinkUrl":"URL of the attachment to be associated with the card",
"buttons":[
{
"text":"button-text",
"value":"Value sent to server on button click"
}
]
}
]
}
}
此代碼將工作:
function close(sessionAttributes, fulfillmentState, message, responseCard) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
responseCard,
},
};
}
function dispatch(intentRequest, callback) {
const outputSessionAttributes = intentRequest.sessionAttributes || {};
callback(close(outputSessionAttributes, 'Fulfilled', { contentType: 'PlainText',
content: 'Thank you and goodbye' }));
}
function loggingCallback(response, originalCallback) {
originalCallback(null, response);
}
exports.handler = (event, context, callback) => {
try {
console.log("event: " + JSON.stringify(event));
dispatch(event, (response) => loggingCallback(response, callback));
} catch (err) {
callback(err);
}
};
它只是發回「謝謝,再見」,在需要的格式,在這種情況下,用「dialogAction」式的「關閉」 - 它通知Lex不會期待用戶的迴應。
還有其他類型 - 這和更多都在Lex documentation解釋。
你能顯示你的節點代碼嗎? – AndyOS
exports.handler =(event,context,callback)=> {TODO implements callback(null,「this works」); }; – Gabe
對不起,它看起來很奇怪,我不能讓markdown正常工作 – Gabe