1

I have a call back function which is getting data from an external API and depends on a data check I have tried for a slot elicitation inside callback but looks like elicitation is not working inside the callback. Please find the code snippet below,

GetCustomerDetails().then(response => {


                var serializedcustomerDetails = convert.xml2json(response.data, {
                    compact: true,
                    spaces: 2
                });

                var customerDetails = JSON.parse(serializedcustomerDetails);


                let filteredCustomerDetails = _.filter(customerDetails.CustomerInfo.CustomerDetails, function (o) {
                    return o.CustomerName._text.includes(customerName);
                })

                

                if (filteredCustomerDetails.length == 1) {

                   
                    callback(elicitSlot(outputSessionAttributes, intentRequest.currentIntent.name,
                        intentRequest.currentIntent.slots, '​CustomerCode', {
                            contentType: 'PlainText',
                            content: `Do you mean ${filteredCustomerDetails[0].CustomerName._text} of ${filteredCustomerDetails[0].SpecialityName._text} department?`
                        }));

                    return;

                }

            }).catch(error => {
                console.log(`${error}`)
            })
Vijayanath Viswanathan
  • 8,027
  • 3
  • 25
  • 43

1 Answers1

1

This is my first Awnser on stack so please bear with me.

I have come accross the same problem in a recent project and there are a few things that you can check.

How long does the API call take?

If your API call takes a long time it will be worth checking the timeout settings on your Lambda function. AWS Console -> Lambda -> Your Function -> Basic settings -> Timeout.

Does your Lambda function finish before the API call is done?

I fixed this issue by building a node module to handle my business logic, the module has a function called getNextSlot it returns as a Promise. Inside this function I check the incoming event and figure out which slot I need to elicit next, part of my flow is to call an API endpoint that takes around 10 seconds to complete.

I use the request-promise package to make the api call, this node module makes sure that the lambda function keeps running while the call is running.

exports.getData = function (url, data) {
    var pr = require("request-promise");

    var options = {
        method: 'POST',
        url: 'api.example',
        qs: {},
        headers:
            {
                'Content-Type': 'application/json'
            },
        body: {
            "example": data
        },
        json: true,
        timeout: 60000
    };

    return pr(options);
}

In my main code I call this function as:

apiModule.getData("test", "data")
    .then(function (data) {
        //Execute callback
   })
    .catch(function (error) {
        console.log(error);
        reject(error);
   });

This solved the issue for me anyways.

Thanks,