Sending Activities
BotBuilders pattern for sending activities via its TurnContext is similar to that
in Teams SDK, but one key difference is that when sending adaptive cards you don't need
to construct the entire activity yourself.
- Diff
- BotBuilder
- Teams SDK
- 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 SDK
- 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 SDK
- 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 SDK
- 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(...));
});