Skip to main content

Sending Activities

BotBuilders pattern for sending activities via its TurnContext is similar to that in Teams AI, but one key difference is that when sending adaptive cards you don't need to construct the entire activity yourself.

-    import { TeamsActivityHandler } from 'botbuilder';

- export class ActivityHandler extends TeamsActivityHandler {
- constructor() {
- super();
- this.onMessage(async (context) => {
- await context.sendActivity({ type: 'typing' });
- });
- }
- }
+ app.on('message', async ({ send }) => {
+ await send({ type: 'typing' });
+ });

Strings

-    import { TeamsActivityHandler } from 'botbuilder';

- export class ActivityHandler extends TeamsActivityHandler {
- constructor() {
- super();
- this.onMessage(async (context) => {
- await context.sendActivity('hello world');
- });
- }
- }
+ app.on('message', async ({ send }) => {
+ await send('hello world');
+ });

Adaptive Cards

-    import { TeamsActivityHandler, CardFactory } from 'botbuilder';
+ import { AdaptiveCard, TextBlock } from '@microsoft/teams.cards';

- export class ActivityHandler extends TeamsActivityHandler {
- constructor() {
- super();
- this.onMessage(async (context) => {
- await context.sendActivity({
- type: 'message',
- attachments: [
- CardFactory.adaptiveCard({
- $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
- type: 'AdaptiveCard',
- version: '1.0',
- body: [{
- type: 'TextBlock',
- text: 'hello world'
- }]
- })
- ]
- });
- });
- }
- }
+ app.on('message', async ({ send }) => {
+ await send(new AdaptiveCard(new TextBlock('hello world')));
+ });

Attachments

-    import { TeamsActivityHandler } from 'botbuilder';
+ import { AdaptiveCard, TextBlock } from '@microsoft/teams.cards';

- export class ActivityHandler extends TeamsActivityHandler {
- constructor() {
- super();
- this.onMessage(async (context) => {
- await context.sendActivity({
- type: 'message',
- attachments: [
- ...
- ]
- });
- });
- }
- }
+ app.on('message', async ({ send }) => {
+ await send(new MessageActivity().addAttachment(...));
+ });