microsoft / BotFramework-Emulator

A desktop application that allows users to locally test and debug chat bots built with the Bot Framework SDK.
https://aka.ms/botemulator
MIT License
1.81k stars 752 forks source link

Typing indicator not rendering while waiting on a delayed activity #2451

Open stevkan opened 7 months ago

stevkan commented 7 months ago

Version

4.14.1 & 4.14.1-371583 (nightly)

Describe the bug

Whether using a JS or a .NET bot, when the ShowTypingMiddleware is utilized, if the message activity to be sent by the bot is delayed, the typing indicator fails to render. However, the activity is still logged in the network activity window and the activity can be selected in the transcript window.

Similarly, without using ShowTypingMiddleware, when sending a typing activity, followed by a delay activity, and finally a message activity the typing activity will fail to render.

To Reproduce

(In a JS-based bot)

Option 1 steps to reproduce the behavior:

  1. Open the 02.echo-bot sample
  2. In the index.js file, add .use(new ShowTypingMiddleware(500, 1000)) to the adapter
  3. In the bot.js file, change the this.onMessage handler to the following:

    this.onMessage(async (context, next) => {
    const replyText = `Echo: ${ context.activity.text }`;
    
    await asyncTimeout(
        async () =>
            await context.sendActivity(MessageFactory.text(replyText, replyText)),
        4000
    );
    await next();
    }
  4. In the bot.js file, add this function at the end:
    const asyncTimeout = async (callback, ms) =>
    new Promise((resolve, reject) => {
        const timeout = setTimeout(async () => {
            if (await callback()) {
                resolve(null);
                clearTimeout(timeout);
            } else {
                reject();
                clearTimeout(timeout);
            }
        }, ms);
    });
  5. Run the bot and test in Emulator

Option 2 steps to reproduce the behavior:

  1. Open the 02.echo-bot sample
  2. In the bot.js file, change the this.onMessage handler to the following:
    await context.sendActivity({ type: 'typing' });
    await context.sendActivity({ type: 'delay', value: 4000 });
    await context.sendActivity({ type: 'message', text: 'Some message' });
  3. Run the bot and test in Emulator

Expected behavior

The typing indicator should render whenever a delay prevents the next activity from immediately being sent.

Additional context

Presently, Emulator uses an older version of Web Chat which may be a factor. When using an updated instance of Web Chat this behavior is not present.

Additionally, the delay activity type isn't used or recognized by Web Chat whereas it does appear to be recognized by Emulator. Updating the Web Chat version in Emulator may affect this.

[bug]