I am developing a bot that is connected to our client application using Direct Line using botbuilder JS V4. for some reasons, messages are sent with a wrong order to the bot. For example:
User: hello
Bot: How can I help you?
- Bot: Hi, I am a robot.
As a solution, I added a delay of two seconds between messages in many of my bot's dialogues.
What is the right way to do that? And is this the recommended way to fix this issue?
Using setTimeout()
async greetUser(step) {
...
await step.context.sendActivity(firstReply);
setTimeout(() => {
await step.context.sendActivity(secondReply);
}, 2000);
}
Using sleep()
const sleep = require("util").promisify(setTimeout);
async greetUser(step) {
...
await step.context.sendActivity(firstReply);
await sleep(2000);
await step.context.sendActivity(secondReply);
}
After adding many of sleep() functions, I noticed that the bot performance is affected. The bot wasn't responding in production enivrement. and it thows this error:
[onTurnErrorStack]: Error
at new RestError (D:\home\site\wwwroot\node_modules\@azure\ms-rest-js\dist\msRest.node.js:1397:28)
at D:\home\site\wwwroot\node_modules\@azure\ms-rest-js\dist\msRest.node.js:1849:37
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
[onTurnError]: {"statusCode":401,"request":{"streamResponseBody":false,"url":"https://directline.botframework.com/v3/conversations/DxjYZQsdv16sdULAsaIn8iQ-h/activities/DxjYZQ65dffgsaIn8iQ-h%7C0000000","method":"POST","headers":{"_
Any suggestions to resolve this issue?