Skip to content

BotBuilderPlugin Not Intercepting Messages #270

@aminesnow

Description

@aminesnow

Issue Summary

The BotBuilderPlugin is not working as expected. It's supposed to intercept messages and use the defined handler to handle them, but the plugin handler is never triggered. Instead, messages are being processed only by the main app's message handler.

Expected Behavior

  • BotBuilderPlugin should intercept and handle incoming messages
  • The ActivityHandler.onMessage() callback should be triggered for incoming messages

Actual Behavior

  • BotBuilderPlugin handler is never called
  • Messages bypass the plugin entirely and go directly to the main app's app.on('message') handler
  • Console logs from the BotBuilder handler (console.log('BotBuilder handler received message:', ctx.activity.text)) are never displayed

Code Configuration

Current Implementation

import { App } from '@microsoft/teams.apps';
import { BotBuilderPlugin } from '@microsoft/teams.botbuilder';
import { TeamsActivityHandler, TurnContext } from 'botbuilder';
import { CloudAdapter } from 'botbuilder';

class ActivityHandler extends TeamsActivityHandler {
  constructor() {
    super();
    this.onMessage(async (ctx, next) => {
      console.log('BotBuilder handler received message:', ctx.activity.text);
      await ctx.sendActivity('hi from botbuilder...');
      await next();
    });
  }

  async run(context: TurnContext): Promise<void> {
    console.log('BotBuilder handler received message:', context.activity.text);
    await context.sendActivity('hi from botbuilder...');
  }
}

const handler = new ActivityHandler();

const adapter = new CloudAdapter(
  new ConfigurationBotFrameworkAuthentication(
    {},
    new ConfigurationServiceClientCredentialFactory({
      MicrosoftAppType: 'MultiTenant',
      MicrosoftAppTenantId: "d0afe711-d9a2-46fd-9d6c-fd8b481b5a37",
    })
  )
);

// Create BotBuilder plugin with ActivityHandler
const botBuilderPlugin = new BotBuilderPlugin({ adapter, handler });

const app = new App({
  plugins: [
    new DevtoolsPlugin(),
    botBuilderPlugin,
  ],
});

// This handler is being called instead of the BotBuilder handler
app.on('message', async ({ send, activity }) => {
  await send({ type: 'typing' });
  await send(`you said: "${activity.text}"`);
});

Steps to Reproduce

  1. Set up the application with the BotBuilderPlugin configuration as shown above (clone https://github.com/aminesnow/quote-agent)
  2. Send a message to the bot
  3. Observe that only the main app handler responds with "you said: [message]"
  4. Notice that the BotBuilder handler console logs never appear
  5. The BotBuilder response "hi from botbuilder..." is never sent

Environment

  • Package: @microsoft/teams.botbuilder@preview
  • BotBuilder: botbuilder@^4.23.0
  • Teams Apps: @microsoft/teams.apps@preview
  • Node.js: Latest LTS
  • TypeScript: ^5.4.5

cc @rbickel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions