Skip to content

Commit b336eb0

Browse files
committed
feat: new Teams adaptive cards
1 parent 2a24a15 commit b336eb0

File tree

2 files changed

+79
-36
lines changed

2 files changed

+79
-36
lines changed

src/interfaces/teams-payload.ts

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,58 @@
11
export interface TeamsPayload {
2-
'@type': string;
3-
'@context': string;
4-
themeColor: string;
5-
title: string;
6-
summary: string;
7-
text?: string;
8-
sections?: Section[];
9-
potentialAction?: Action[];
2+
type: string;
3+
attachments: Attachment[];
104
}
115

12-
interface Section {
13-
facts: Fact[];
6+
interface Attachment {
7+
contentType: string;
8+
contentUrl: unknown;
9+
content: AdaptiveCard;
10+
}
11+
12+
interface AdaptiveCard {
13+
$schema: string;
14+
type: string;
15+
version: string;
16+
body: Element[];
17+
actions: Action[];
18+
}
19+
20+
type Element = TextBlock | FactSet | ActionSet | ColumnSet | Column;
21+
22+
interface TextBlock {
23+
type: 'TextBlock';
24+
text: string;
25+
weight?: 'default' | 'lighter' | 'bolder';
26+
size?: 'default' | 'small' | 'medium' | 'large' | 'extraLarge';
1427
}
1528

1629
interface Fact {
17-
name: string;
30+
title: string;
1831
value: string;
1932
}
2033

21-
interface Action {
22-
'@type': string;
23-
name: string;
24-
targets: Target[];
34+
interface FactSet {
35+
type: 'FactSet';
36+
facts: Fact[];
37+
}
38+
39+
interface ActionSet {
40+
type: 'ActionSet';
41+
actions: Action[];
42+
}
43+
44+
interface ColumnSet {
45+
type: 'ColumnSet';
46+
columns: Column[];
2547
}
2648

27-
interface Target {
28-
os: string;
29-
uri: string;
49+
interface Column {
50+
type: 'ColumnSet';
51+
items: Element[];
52+
}
53+
54+
interface Action {
55+
type: string;
56+
title: string;
57+
url: string;
3058
}

src/normalizers/teams.normalizer.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,41 @@ export const normalizeTeamsPayload = (
99
buttons: Button[]
1010
): TeamsPayload => {
1111
return {
12-
'@type': 'MessageCard',
13-
'@context': 'https://schema.org/extensions',
14-
themeColor: color,
15-
summary: title,
16-
title,
17-
text,
18-
sections: [
12+
type: 'message',
13+
attachments: [
1914
{
20-
facts: fields,
15+
contentType: 'application/vnd.microsoft.card.adaptive',
16+
contentUrl: null,
17+
content: {
18+
$schema:
19+
'http://adaptivecards.io/schemas/adaptive-card.json',
20+
type: 'AdaptiveCard',
21+
version: '1.2',
22+
body: [
23+
{
24+
type: 'TextBlock',
25+
text: title,
26+
size: 'large',
27+
},
28+
{
29+
type: 'TextBlock',
30+
text: text,
31+
},
32+
{
33+
type: 'FactSet',
34+
facts: fields.map(({ name, value }) => ({
35+
title: name,
36+
value,
37+
})),
38+
},
39+
],
40+
actions: buttons.map(({ label, url }) => ({
41+
type: 'Action.OpenUrl',
42+
title: label,
43+
url: url,
44+
})),
45+
},
2146
},
2247
],
23-
potentialAction: buttons.map((button) => ({
24-
'@type': 'OpenUri',
25-
name: button.label,
26-
targets: [
27-
{
28-
os: 'default',
29-
uri: button.url,
30-
},
31-
],
32-
})),
3348
};
3449
};

0 commit comments

Comments
 (0)