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.
- Diff
- BotBuilder
- Teams AI
- 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' });
+ });
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
- Diff
- BotBuilder
- Teams AI
- 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');
+ });
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
- Diff
- BotBuilder
- Teams AI
- 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')));
+ });
import { TeamsActivityHandler, CardFactory } from 'botbuilder';
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'
}]
})
]
});
});
}
}
import { AdaptiveCard, TextBlock } from '@microsoft/teams.cards';
app.on('message', async ({ send }) => {
await send(new AdaptiveCard(new TextBlock('hello world')));
});
Attachments
- Diff
- BotBuilder
- Teams AI
- 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(...));
+ });
import { TeamsActivityHandler } from 'botbuilder';
export class ActivityHandler extends TeamsActivityHandler {
constructor() {
super();
this.onMessage(async (context) => {
await context.sendActivity({
type: 'message',
attachments: [
...
]
});
});
}
}
import { AdaptiveCard, TextBlock } from '@microsoft/teams.cards';
app.on('message', async ({ send }) => {
await send(new MessageActivity().addAttachment(...));
});