1
votes

While working on a test Lexbot that orders pizza, I had an error where the Lexbot is calling the wrong Lambda function and outputs the result.

I have two intents, "orderPizzaSize" and "orderPizzaToppings".

The orderPizzaSize intent has a slot type pizzaSize. This slot type contains the values "small pizza", "medium pizza", and "large pizza". The lambda function the orderPizzaSize intent calls for fulfillment is "orderPizza". The code is below:

    exports.handler = (event, context, callback) => {
    var pizzaSizeChoice = event.currentIntent.slots.pizzaSize;
    var price = "free";

        if (pizzaSizeChoice == "small pizza"){
            price = "6 dollars";
        }
        else if (pizzaSizeChoice == "medium pizza"){
            price = "8 dollars";
        }
        else if (pizzaSizeChoice == "large pizza"){
            price = "10 dollars";
        }
        else {
            price = "11 dollars";
        }

    callback(null, {
        "dialogAction": {
        "type": "Close",
        "fulfillmentState": "Fulfilled",
        "message": {
            "contentType": "PlainText",
            "content": "You have ordered a " + event.currentIntent.slots.pizzaSize + " for " + price + ". Would you like any toppings? Just ask!"
        }
    }
});
};

This Lambda function works fine when any of the utterances for orderPizzaSize are said by the user. It will output "You have ordered a large pizza for 10 dollars. Would you like any toppings? Just ask!"

The problem occurs when any utterances for the orderPizzaToppings intent is called. The orderPizzaToppings intent calls another Lambda function "orderPizzaToppings". The code for this function below:

exports.handler = (event, context, callback) => {
    var pizzaToppingsChoice = event.currentIntent.slots.pizzaToppings;
    var price = "free";

        if (toppings == "mushrooms"){
            price = "1 dollar";
        }
        else if (pizzaToppingsChoice == "peppers"){
            price = "2 dollars";
        }
        else if (pizzaToppingsChoice == "onions"){
            price = "3 dollars";
        }
        else if (pizzaToppingsChoice == "sausage"){
            price = "4 dollars";
        }
        else if (pizzaToppingsChoice == "extra cheese"){
            price = "5 dollars";
        }
        else if (pizzaToppingsChoice == "pepperoni"){
            price = "6 dollars";
        }
        else {
            price = "10 dollars";
        }   

    callback(null, {
        "dialogAction": {
        "type": "Close",
        "fulfillmentState": "Fulfilled",
        "message": {
            "contentType": "PlainText",
            "content": "You put " + event.currentIntent.slots.pizzaToppings + " for an extra " + price + "."
        }
    }
});
};

When any orderPizzaToppings utterances are said, it will output "You have ordered a undefined for 11 dollars. Would you like any toppings? Just ask!" It still seems to be calling the first orderPizza Lambda function associated with the orderPizzaSize intent rather than the correct Lambda function orderPizzaToppings.

The strange part is when I completely removed the Lambda function orderPizza, changed the option to "Return parameters to client" and rebuilt the bot, it will still output "You have ordered a undefined for 11 dollars. Would you like any toppings? Just ask!" despite that Lambda function not even being called.

Does anybody know why Lex is still responding with the "orderPizza" lambda function?

1
Did you ever figure out why this was happening?Funzo

1 Answers

0
votes

Are you experiencing the issues when testing the Lex bot via the Console UI or when calling it from an external service?

If it's the latter, check to see that you're calling the correct version of the Bot and that you've published the changes using the correct version alias.