1
votes

I'm building the AWS Lex chat bot right now and faced some issue on the lambda function settings. According to the sample code, it used this lambda function at the end of the conversation. That's why the code was like : function close(.....)

'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,
            },
        };
    }

However what I would like to do is using the DialogCodeHook instead of this FulfillmentCodeHook.

The simplest logic inside Lex is asking question 1-->get answer 1-->asking question 2-->get answer 2-->asking question 2-->get answer 3; What i wanna do is Ask Question 1- Response Value allowed are 1.1, 1.2 If Response Value= Value 1.1 Ask Question 2 If Response Value= Value 1.2 Ask Question 3 Ask Question 4- Value 4.1, Value 4.2 .. so on

On AWS discussion forum, an answer is like: Yes, you can use Lambda to implement the decision tree. Lambda allows you to set a specific message and elicit a slot using 'dialogAction'.

For this specific conversation flow

if (response_value = 1.1) {
// set dialogAction.message = "Question 2"
...
// set type = ElicitSlot
...
// slotToElicit = answer2"

}

Similarly you would define conditions to ask Question 3, 4 etc.

But I am not sure where should I put this If..... at and how to use this ElicitSlot function.

Full version of the sample code for the close function is:

'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);
    }
};

Hope someone can help! Thank you so much!!!!!!!!!!!!!!!!!!!!!

1
I'm afraid that the lex tag is wrong in your question. (This lex tag is for the compiler compiler tool lex or flex which is often used together with yacc or bison.) I believe this is not the lex you have in mind. (Please, see the bubble help of lex or click the tag if in doubt.)Scheff's Cat
Oh yes, what I mean is AWS Lex function. Sorry for that. Thanks!ZZ.W

1 Answers

0
votes

Please check this code: https://github.com/nicholasjackson/slack-bot-lex-lambda/blob/master/src/dispatcher.js

It lists functions for all possible scenarios, including the close(...) you have, but also the ElicitSlot(...) as well that you're after. Please note that there is an ElicitIntent dialog action type as well which is not used in the code but it could be useful in some scenarios.

Hope it helps. Tibor