From 46a0d6504648a0530e67ae7bd778de649dfb62a5 Mon Sep 17 00:00:00 2001 From: Daniel Cadenas Date: Wed, 27 Mar 2024 17:00:09 -0300 Subject: [PATCH] Test Slack message --- src/lib/slack.js | 66 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/src/lib/slack.js b/src/lib/slack.js index 20a09da..be37a24 100644 --- a/src/lib/slack.js +++ b/src/lib/slack.js @@ -1,10 +1,64 @@ +const { WebClient } = require("@slack/web-api"); + +if (!process.env.SLACK_TOKEN) { + throw new Error("SLACK_TOKEN environment variable is required"); +} + +if (!process.env.CHANNEL_ID) { + throw new Error("CHANNEL_ID environment variable is required"); +} + +const token = process.env.SLACK_TOKEN; +const channelId = process.env.CHANNEL_ID; +const web = new WebClient(token); export default class Slack { static async postManualVerification(reportRequest) { - console.log( - `TODO: Implement Slack.postManualVerification.\n - Event payload: ${JSON.stringify(reportRequest.reportedEvent)}\n - Reporter pubkey: ${reportRequest.reporterPubkey}\n - Reporter text: ${reportRequest.reporterText}` - ); + // console.log( + // `TODO: Implement Slack.postManualVerification.\n + // Event payload: ${JSON.stringify(reportRequest.reportedEvent)}\n + // Reporter pubkey: ${reportRequest.reporterPubkey}\n + // Reporter text: ${reportRequest.reporterText}` + // ); + try { + const result = await web.chat.postMessage({ + channel: channelId, + text: "This is a sample message with buttons", + blocks: [ + { + type: "section", + text: { + type: "mrkdwn", + text: "Choose an option:", + }, + }, + { + type: "actions", + elements: [ + { + type: "button", + text: { + type: "plain_text", + text: "Button 1", + }, + value: "value-1", + action_id: "action1", + }, + { + type: "button", + text: { + type: "plain_text", + text: "Button 2", + }, + value: "value-2", + action_id: "action2", + }, + ], + }, + ], + }); + console.log(result); + } catch (error) { + console.error(error); + } } }