Я создаю чат-бота AWS Lex прямо сейчас и столкнулся с некоторой проблемой в настройках лямбда-функции. Согласно образцу кода, он использовал эту лямбда-функцию в конце разговора. Вот почему код был такой: функция закрыть (.....)
'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, 1,2, если значение ответа = значение 1,1 Задать вопрос 2, если значение ответа = значение 1,2 Задать вопрос 3 Задать вопрос 4 - значение 4,1, значение 4,2 ... и так далее
На дискуссионном форуме AWS ответ такой: Да, вы можете использовать Lambda для реализации дерева решений. Lambda позволяет вам установить конкретное сообщение и вызвать слот с помощью dialogAction.
Для этого конкретного разговора
if (response_value = 1.1) {
// set dialogAction.message = "Question 2"
...
// set type = ElicitSlot
...
// slotToElicit = answer2"
}
Точно так же вы должны определить условия, чтобы задать вопрос 3, 4 и т. Д.
Но я не уверен, куда мне поместить это If ..... at и как использовать эту функцию 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);
}
};
Надеюсь, кто-то может помочь! Большое спасибо!!!!!!!!!!!!!!!!!!!!!