4

Is there a way to add a bit of a delay to the responses? So the bot feels more real, like if it was typing? Just a little bit. Right now the reaction from testers has been that it’s too fast. Which is great, but… feels too “cold”. With a little time where it looks like the bot is typing, it would feel a bit more warm and fuzzy: :)

I need to add delay between two lines

    session.send("Account created successfully");
    session.send("Please login");

Below is the full code

var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url); 
});

// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword,
    openIdMetadata: process.env.BotOpenIdMetadata 
});

// Listen for messages from users 
server.post('/api/messages', connector.listen());

var bot = new builder.UniversalBot(connector);

bot.on('conversationUpdate', (message) => {
    if (message.membersAdded) {
        message.membersAdded.forEach(function (identity) {
            if (identity.id === message.address.bot.id) {
                bot.beginDialog(message.address, 'accountCheck');
            }
        });
    }
});

bot.dialog('accountCheck', [
    function (session, results, next) {

         session.send("Account created successfully");
         session.send("Please login");

    }
]).endConversationAction("stop",
    "",
    {
        matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
        // confirmPrompt: "This will cancel your order. Are you sure?"
    }
);
Vigneswaran A
  • 562
  • 7
  • 18
  • 2
    Use `session.sendTyping()`. From my experience, artificial delays can also lead your users to think there are performance problems. – nwxdev Jan 02 '18 at 21:30
  • I need 2 seconds delay. So, it's not a problem. session.sendTyping() is not working for me – Vigneswaran A Jan 03 '18 at 05:28

5 Answers5

2

You can use session.delay()

bot.dialog('accountCheck', [
    function (session, results, next) {

         session.send("Account created successfully");
         // 0.5 sec delay between messages
         session.delay(500)
         session.send("Please login");

    }
]).endConversationAction("stop",
    "",
    {
        matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
        // confirmPrompt: "This will cancel your order. Are you sure?"
    }
);

see the docs: https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#delay

Amit be
  • 469
  • 3
  • 13
2

Bot framework SDK v4:

await turnContext.sendActivity({ type: ActivityTypes.Typing })

Documentation link SDK v4

Bot Framework SDK v3:

session.sendTyping()

Documentation link SDK v3

Ron
  • 39
  • 1
  • 4
2

The way I have implemented this using nodejs SDK 4.0 is to use ActivityTypes.Typing in SendActivities as below

await context.sendActivities([
{type: ActivityTypes.Typing},
{type: 'delay', value:2000},
{type: ActivityTypes.Message, text: 'Bot Response goes here is only text else send attachments as reply'}])

Try to add above code in Change SendActivity to SendActivities with dealy Try testing in emulator.

Satish Patel
  • 1,784
  • 1
  • 27
  • 39
1

You can use timeout on your client side or backend side.

function (session, results, next) {

    session.send("Account created successfully. Wait 10 seconds...");
    setTimeout(function() {
            session.send("Please login");
    }, 10000); //10 seconds
}
hurricane
  • 6,521
  • 2
  • 34
  • 44
1

Instead of adding delay, you can just send a typing indicator

session.sendTyping();

More info at https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-typing-indicator

Ezequiel Jadib
  • 14,767
  • 2
  • 38
  • 43
  • Not sure what that means... the typing indicator works well it will also depends on the operations you are doing next. As I pointed and also pointed in the comments, adding a delay is not a good practice – Ezequiel Jadib Jan 03 '18 at 12:14
  • be aware that the session.sendTyping() doesn't work for every channel. Maybe that's why it is not working for @VigneswaranA – Victor Lia Fook May 02 '18 at 05:05