Skip to content

Commit 9a0caf1

Browse files
authored
feat: new Teams adaptive cards (#5)
* feat: new Teams adaptive cards
1 parent 81f6b8a commit 9a0caf1

File tree

4 files changed

+138
-54
lines changed

4 files changed

+138
-54
lines changed

dist/index.js

Lines changed: 40 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/interfaces/teams-payload.ts

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,69 @@
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+
backgroundImage: BackgroundImage;
19+
msteams: MSTeams;
20+
}
21+
22+
type Element = TextBlock | FactSet | ActionSet | ColumnSet | Column;
23+
24+
interface TextBlock {
25+
type: 'TextBlock';
26+
text: string;
27+
weight?: 'default' | 'lighter' | 'bolder';
28+
size?: 'default' | 'small' | 'medium' | 'large' | 'extraLarge';
1429
}
1530

1631
interface Fact {
17-
name: string;
32+
title: string;
1833
value: string;
1934
}
2035

36+
interface FactSet {
37+
type: 'FactSet';
38+
facts: Fact[];
39+
}
40+
41+
interface ActionSet {
42+
type: 'ActionSet';
43+
actions: Action[];
44+
}
45+
46+
interface ColumnSet {
47+
type: 'ColumnSet';
48+
columns: Column[];
49+
}
50+
51+
interface Column {
52+
type: 'ColumnSet';
53+
items: Element[];
54+
}
55+
2156
interface Action {
22-
'@type': string;
23-
name: string;
24-
targets: Target[];
57+
type: string;
58+
title: string;
59+
url: string;
60+
}
61+
62+
interface BackgroundImage {
63+
url: string;
64+
fillMode: 'RepeatHorizontally';
2565
}
2666

27-
interface Target {
28-
os: string;
29-
uri: string;
67+
interface MSTeams {
68+
width: 'Full';
3069
}

src/normalizers/teams.normalizer.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,49 @@ 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.5',
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+
msteams: {
46+
width: 'Full',
47+
},
48+
backgroundImage: {
49+
// TODO: Replace with base64 template, but no idea how that works...
50+
url: `https://singlecolorimage.com/get/${color}/1x3`,
51+
fillMode: 'RepeatHorizontally',
52+
},
53+
},
2154
},
2255
],
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-
})),
3356
};
3457
};

0 commit comments

Comments
 (0)