我正在構建AWS Lex聊天機器人,並且在lambda函數設置上遇到了一些問題。根據示例代碼,它在對話結束時使用了這個lambda函數。這就是爲什麼代碼是這樣的:功能關閉(.....)AWS Lex lambda函數引出槽
'use strict';
// Close dialog with the customer, reporting fulfillmentState of Failed
or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
不過,我想使用DialogCodeHook而不是此FulfillmentCodeHook做什麼。
Lex內最簡單的邏輯是問問題1 - >得到答案1 - >問題2 - >得到答案2 - >問題2 - >得到答案3; 我想要做的是 向允許被1.1,1.2 如果響應值= 1.1值 提問2 如果響應值= 1.2值向 問題3 提問4-值4.1,值4.2問題1-應答值 ..等等
在AWS論壇上,答案如下: 是的,您可以使用Lambda來實現決策樹。 Lambda允許您使用'dialogAction'設置特定的消息並引出一個插槽。
對於這個特定的會話流
if (response_value = 1.1) {
// set dialogAction.message = "Question 2"
...
// set type = ElicitSlot
...
// slotToElicit = answer2"
}
同樣你會定義條件要問問題3,4等
但我不知道我應該把這個如果在.....以及如何使用這個ElicitSlot函數。
的關閉功能的示例代碼的完整版本是:
'use strict';
// Close dialog with the customer, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
// --------------- Events -----------------------
function dispatch(intentRequest, callback) {
console.log('request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.intentName}');
const sessionAttributes = intentRequest.sessionAttributes;
const slots = intentRequest.currentIntent.slots;
const crust = slots.crust;
const size = slots.size;
const pizzaKind = slots.pizzaKind;
callback(close(sessionAttributes, 'Fulfilled',
{'contentType': 'PlainText', 'content': `Okay, I have ordered your ${size} ${pizzaKind} pizza on ${crust} crust`}));
}
// --------------- Main handler -----------------------
// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.
exports.handler = (event, context, callback) => {
try {
dispatch(event,
(response) => {
callback(null, response);
});
} catch (err) {
callback(err);
}
};
希望有人能幫助!非常感謝!!!!!!!!!!!!!!!!!!!!!
恐怕你的問題** lex **標籤是錯誤的。 (這個lex標籤是用於編譯器編譯器工具lex或flex,通常與yacc或bison一起使用。)我相信這不是你想到的。 (請參閱lex的氣泡幫助,或者如果有疑問,請點擊標籤。) – Scheff
哦,是的,我的意思是AWS Lex功能。對不起。謝謝! –