Skip to content Skip to sidebar Skip to footer

Use Await Inside Callback (Microsoft Bot Framework V4 Nodejs)

I am trying to send the response back to chatbot emulator from inside callback. async getUserDetails(step){ console.log('inside get userdetaiuls modeiule') this.userDBObjec

Solution 1:

I would recommend using Axios - a promise based HTTP client for node.js - rather than the request package. Since Axios is promise based, you can use async/await instead of callbacks. The resulting code falls more in line with the flow of the BotFramework. For more details, see the code snippet below and the Axios Documentation.

async getUserDetails(step){
    this.userDBObject.password = step.result;
    try {
        const res = await axios.post('#', {form:{key: 'hi'}});
        await step.context.sendActivity("Done");
    } catch (error) {
        console.log(error);
        await step.context.sendActivity("Sorry, we were not able to complete your request.");
    } 
    return step.endDialog();
}

Post a Comment for "Use Await Inside Callback (Microsoft Bot Framework V4 Nodejs)"