Search code examples
botframework

connect ETIMEDOUT 137.116.128.188:443 for bot FRAMEWORK, can be extended


So I have a request that is expected to run for at least 1 min. before it will give a response

To help aid user on not doing anything while my request is still running, I set some sendTyping activities:

For censoring production codes work sensitive information , this is generally how my code looks like:

        var queryDone = "No";
        var xmlData = '';
        let soappy = soapQuery("123", "456", "789","getInfo");

        soappy.then(function (res) {
            queryDone = 'Yes';
            xmlData = res;
            console.log(xmlData);
        }, function (err) {
            queryDone = 'Timeout';
        })

        while (queryDone == 'No') {
            await step.context.sendActivity({ type: 'typing' });
        }

where soapQuery() is a function that sends and returns the POST request which looks like this:

return new Promise(function (resolve, reject) {
        request.post(options, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                resolve(body);
            }
            else {
                reject(error);
            }
        })
    })

Problem comes because of this 1 minute response, (it's not really negotiable as the server requires at least 1 min to process it, due to large number of data and validation of my request).

Though after 1 minute, the console does print the response, sadly even before this, the bot already time out. enter image description here

Any suggestion how to fix this, or extend time out of the bot?

I need the sendtyping activity so that user understands that the request is not yet done. And again, it really takes 1 minute before my request responds.

Thank you!


Solution

  • So, the reason that this happens is that HTTP requests work a little bit differently in the Bot Framework than you might expect. Here's how it works:

    enter image description here

    So basically, what's happening in your scenario is:

    1. User sends HTTP POST
    2. Bot calls your soapQuery
    3. Bot starts sending Typing Indicators
    4. soapQuery completes
    5. Bot finally sends an HTTP Response to the HTTP POST from step #1, after the request has already timed out, which happens after 15 seconds

    To fix this, I would:

    1. Use showTypingMiddleware to send the typing indicator continuously and automatically until the bot sends another message (this gets rid of your blocking while loop)
    2. Once soapQuery finishes, the bot will have lost context for the conversation, so your soappy.then() function will need to send a proactive message. To do so, you'll need to save a reference to the conversation prior to calling soappy(), and then within the then() function, you'll need to use that conversationReference to send the proactive message to the user.

    Note, however, that the bot in the sample I linked above calls the proactive message after receiving a request on the api/notify endpoint. Yours doesn't need to do that. It just needs to send the proactive message using similar code. Here's some more documentation on Proactive Messages