Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

73 changes: 56 additions & 17 deletions src/interfaces/teams-payload.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
export interface TeamsPayload {
'@type': string;
'@context': string;
themeColor: string;
title: string;
summary: string;
text?: string;
sections?: Section[];
potentialAction?: Action[];
type: string;
attachments: Attachment[];
}

interface Section {
facts: Fact[];
interface Attachment {
contentType: string;
contentUrl: unknown;
content: AdaptiveCard;
}

interface AdaptiveCard {
$schema: string;
type: string;
version: string;
body: Element[];
actions: Action[];
backgroundImage: BackgroundImage;
msteams: MSTeams;
}

type Element = TextBlock | FactSet | ActionSet | ColumnSet | Column;

interface TextBlock {
type: 'TextBlock';
text: string;
weight?: 'default' | 'lighter' | 'bolder';
size?: 'default' | 'small' | 'medium' | 'large' | 'extraLarge';
}

interface Fact {
name: string;
title: string;
value: string;
}

interface FactSet {
type: 'FactSet';
facts: Fact[];
}

interface ActionSet {
type: 'ActionSet';
actions: Action[];
}

interface ColumnSet {
type: 'ColumnSet';
columns: Column[];
}

interface Column {
type: 'ColumnSet';
items: Element[];
}

interface Action {
'@type': string;
name: string;
targets: Target[];
type: string;
title: string;
url: string;
}

interface BackgroundImage {
url: string;
fillMode: 'RepeatHorizontally';
}

interface Target {
os: string;
uri: string;
interface MSTeams {
width: 'Full';
}
59 changes: 41 additions & 18 deletions src/normalizers/teams.normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,49 @@ export const normalizeTeamsPayload = (
buttons: Button[],
): TeamsPayload => {
return {
'@type': 'MessageCard',
'@context': 'https://schema.org/extensions',
themeColor: color,
summary: title,
title,
text,
sections: [
type: 'message',
attachments: [
{
facts: fields,
contentType: 'application/vnd.microsoft.card.adaptive',
contentUrl: null,
content: {
$schema:
'http://adaptivecards.io/schemas/adaptive-card.json',
type: 'AdaptiveCard',
version: '1.5',
body: [
{
type: 'TextBlock',
text: title,
size: 'large',
},
{
type: 'TextBlock',
text: text,
},
{
type: 'FactSet',
facts: fields.map(({ name, value }) => ({
title: name,
value,
})),
},
],
actions: buttons.map(({ label, url }) => ({
type: 'Action.OpenUrl',
title: label,
url: url,
})),
msteams: {
width: 'Full',
},
backgroundImage: {
// TODO: Replace with base64 template, but no idea how that works...
url: `https://singlecolorimage.com/get/${color}/1x3`,
fillMode: 'RepeatHorizontally',
},
},
},
],
potentialAction: buttons.map((button) => ({
'@type': 'OpenUri',
name: button.label,
targets: [
{
os: 'default',
uri: button.url,
},
],
})),
};
};
Loading