Activity Handlers
A BotBuilder ActivityHandler is similar to the activity routing of the Teams AI App.
The BotBuilderPlugin accepts a botbuilder Activity Handler instance so you can keep using your
existing activity handlers while migrating however many you want to new Teams AI handlers. This allows for
a more incremental migration strategy.
info
this snippet shows how to use the BotBuilderPlugin to route activities using
botbuilder alongside the default Teams AI activity routing.
- index.ts
- adapter.ts
- activity-handler.ts
import { App } from '@microsoft/teams.apps';
import { BotBuilderPlugin } from '@microsoft/teams.botbuilder';
import adapter from './adapter';
import handler from './activity-handler';
const app = new App({
  plugins: [new BotBuilderPlugin({ adapter, handler })],
});
app.on('message', async ({ send }) => {
  await send('hi from teams...');
});
(async () => {
  await app.start();
})();
import { CloudAdapter } from 'botbuilder';
// replace with your BotAdapter
const adapter = new CloudAdapter(
  new ConfigurationBotFrameworkAuthentication(
    {},
    new ConfigurationServiceClientCredentialFactory({
      MicrosoftAppType: tenantId ? 'SingleTenant' : 'MultiTenant',
      MicrosoftAppId: clientId,
      MicrosoftAppPassword: clientSecret,
      MicrosoftAppTenantId: tenantId,
    })
  )
);
export default adapter;
import { TeamsActivityHandler } from 'botbuilder';
// replace with your TeamsActivityHandler
export class ActivityHandler extends TeamsActivityHandler {
  constructor() {
    super();
    this.onMessage(async (ctx, next) => {
      await ctx.sendActivity('hi from botbuilder...');
      await next();
    });
  }
}
const handler = new ActivityHandler();
export default handler;
hi from botbuilder...
hi from teams...