Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
fix: deprecated ms-teams integration (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
waigel authored Mar 10, 2023
1 parent 4119190 commit 6c344fe
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 138 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@aws-sdk/util-arn-parser": "^3.55.0",
"date-fns": "^2.28.0",
"lambda-log": "^3.1.0",
"ms-teams-webhook": "^1.0.4"
"ms-teams-webhook": "^2.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.2.0",
Expand Down
258 changes: 128 additions & 130 deletions src/handlers/forward-to-teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,137 +27,135 @@ export const handler: SNSHandler = async (event) => {

const stateChangeTime = parseISO(message.StateChangeTime);

await webhook.send(
JSON.stringify({
type: 'message',
attachments: [
{
contentType: 'application/vnd.microsoft.card.adaptive',
contentUrl: null,
content: {
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
type: 'AdaptiveCard',
version: '1.3',
body: [
{
type: 'Container',
padding: 'None',
items: [
{
type: 'TextBlock',
wrap: true,
size: 'Large',
color: getHeadingColor(message.NewStateValue),
text: `${getEmoji(message.NewStateValue)} ${
message.NewStateValue
}: ${message.AlarmName}`,
},
],
},
{
type: 'Container',
items: [
{
type: 'TextBlock',
text: message.AlarmDescription,
wrap: true,
},
{
type: 'TextBlock',
text: message.NewStateReason,
wrap: true,
},
],
isVisible: false,
id: 'alarm-details',
},
{
type: 'Container',
padding: 'None',
items: [
{
type: 'ColumnSet',
columns: [
{
type: 'Column',
width: 'stretch',
items: [
{
type: 'TextBlock',
text: 'Account',
wrap: true,
isSubtle: true,
weight: 'Bolder',
},
{
type: 'TextBlock',
wrap: true,
spacing: 'Small',
text: message.AWSAccountId,
},
],
},
{
type: 'Column',
width: 'stretch',
items: [
{
type: 'TextBlock',
text: 'Region',
wrap: true,
isSubtle: true,
weight: 'Bolder',
},
{
type: 'TextBlock',
text: message.Region,
wrap: true,
spacing: 'Small',
},
],
},
{
type: 'Column',
width: 'stretch',
items: [
{
type: 'TextBlock',
text: 'Time',
wrap: true,
weight: 'Bolder',
isSubtle: true,
},
{
type: 'TextBlock',
text: `{{TIME(${formatISO(stateChangeTime)})}}`,
wrap: true,
spacing: 'Small',
},
],
},
],
},
],
},
],
padding: 'None',
actions: [
{
type: 'Action.ToggleVisibility',
title: 'Show Details',
targetElements: ['alarm-details'],
},
{
type: 'Action.OpenUrl',
title: 'View in CloudWatch',
url: getAlarmLink(message.AlarmArn),
},
],
},
await webhook.send({
type: 'message',
attachments: [
{
contentType: 'application/vnd.microsoft.card.adaptive',
contentUrl: null,
content: {
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
type: 'AdaptiveCard',
version: '1.3',
body: [
{
type: 'Container',
padding: 'None',
items: [
{
type: 'TextBlock',
wrap: true,
size: 'Large',
color: getHeadingColor(message.NewStateValue),
text: `${getEmoji(message.NewStateValue)} ${
message.NewStateValue
}: ${message.AlarmName}`,
},
],
},
{
type: 'Container',
items: [
{
type: 'TextBlock',
text: message.AlarmDescription,
wrap: true,
},
{
type: 'TextBlock',
text: message.NewStateReason,
wrap: true,
},
],
isVisible: false,
id: 'alarm-details',
},
{
type: 'Container',
padding: 'None',
items: [
{
type: 'ColumnSet',
columns: [
{
type: 'Column',
width: 'stretch',
items: [
{
type: 'TextBlock',
text: 'Account',
wrap: true,
isSubtle: true,
weight: 'Bolder',
},
{
type: 'TextBlock',
wrap: true,
spacing: 'Small',
text: message.AWSAccountId,
},
],
},
{
type: 'Column',
width: 'stretch',
items: [
{
type: 'TextBlock',
text: 'Region',
wrap: true,
isSubtle: true,
weight: 'Bolder',
},
{
type: 'TextBlock',
text: message.Region,
wrap: true,
spacing: 'Small',
},
],
},
{
type: 'Column',
width: 'stretch',
items: [
{
type: 'TextBlock',
text: 'Time',
wrap: true,
weight: 'Bolder',
isSubtle: true,
},
{
type: 'TextBlock',
text: `{{TIME(${formatISO(stateChangeTime)})}}`,
wrap: true,
spacing: 'Small',
},
],
},
],
},
],
},
],
padding: 'None',
actions: [
{
type: 'Action.ToggleVisibility',
title: 'Show Details',
targetElements: ['alarm-details'],
},
{
type: 'Action.OpenUrl',
title: 'View in CloudWatch',
url: getAlarmLink(message.AlarmArn),
},
],
},
],
})
);
},
],
});
}
};

Expand Down

0 comments on commit 6c344fe

Please sign in to comment.