diff --git a/package-lock.json b/package-lock.json index 92c52fa..f913856 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,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", @@ -5208,9 +5208,9 @@ "dev": true }, "node_modules/ms-teams-webhook": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/ms-teams-webhook/-/ms-teams-webhook-1.0.4.tgz", - "integrity": "sha512-QyKoAq9FNwRSyw4Ww5h8OaOx+YQUsRyMOQu/jKsHFS9ITe4URXDF9rAbnndmTfy61CdzLsUCRzsPDlkzrecqcQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms-teams-webhook/-/ms-teams-webhook-2.0.0.tgz", + "integrity": "sha512-QggbQ2uG1O8hoQmNdx3B5rjZhku/Sb9kmD2h0yRpaQFToR579FBL2iO1iZZVEFN8wCbAkpFORAPKUfmNbD9sTw==", "dependencies": { "axios": "^0.21.1" } @@ -10634,9 +10634,9 @@ "dev": true }, "ms-teams-webhook": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/ms-teams-webhook/-/ms-teams-webhook-1.0.4.tgz", - "integrity": "sha512-QyKoAq9FNwRSyw4Ww5h8OaOx+YQUsRyMOQu/jKsHFS9ITe4URXDF9rAbnndmTfy61CdzLsUCRzsPDlkzrecqcQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms-teams-webhook/-/ms-teams-webhook-2.0.0.tgz", + "integrity": "sha512-QggbQ2uG1O8hoQmNdx3B5rjZhku/Sb9kmD2h0yRpaQFToR579FBL2iO1iZZVEFN8wCbAkpFORAPKUfmNbD9sTw==", "requires": { "axios": "^0.21.1" } diff --git a/package.json b/package.json index 6a37311..30b07b9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/handlers/forward-to-teams.ts b/src/handlers/forward-to-teams.ts index 35d721b..ee5bae9 100644 --- a/src/handlers/forward-to-teams.ts +++ b/src/handlers/forward-to-teams.ts @@ -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), + }, + ], }, - ], - }) - ); + }, + ], + }); } };