import { IncomingWebhook } from '@slack/webhook' import { URLs } from './types' export const sendSlackMessage = async (urls: URLs, response: any, text: string) => { try { const webhook = new IncomingWebhook('https://hooks.slack.com/services/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') await webhook.send( { blocks: [ { type: 'section', text: { type: 'mrkdwn', text, }, }, { type: 'section', text: { type: 'mrkdwn', text: `\`\`\`${response}\`\`\``, }, }, { type: 'section', text: { type: 'mrkdwn', text: 'Restart Service NOW! => => :aws:', }, accessory: { type: 'button', text: { type: 'plain_text', text: 'Log into AWS', emoji: true, }, url: `https://ap-southeast-2.console.aws.amazon.com/ec2/v2/home?region=ap-southeast-2#Instances:search=${urls.awsUrl};sort=instanceState`, }, }, { type: 'divider', }, { type: 'divider', }, ], }, ) } catch (err) { console.error(err) throw new Error('Could not send slack message') } }