starbasedb icon indicating copy to clipboard operation
starbasedb copied to clipboard

Slack plugin for sending messages to webhooks

Open Brayden opened this issue 11 months ago • 1 comments

Purpose

Plugin that sends a Slack message based on a defined Slack webhook and supports sending advanced message formatting (https://api.slack.com/messaging/webhooks#advanced_message_formatting). Very simple implementation that helps with communicating changes, issues, and more directly from a Starbase instance.

Tasks

  • [X] Include Slack webhook plugin
  • [X] Add example usage

Verify

const slackPlugin = new SlackPlugin({
    webhookUrl: 'https://hooks.slack.com/services/SCRIBBLESCRIBBLESCRIBBLE',
})
const cdcPlugin = new ChangeDataCapturePlugin({
    stub,
    broadcastAllEvents: true,
    events: [],
})

cdcPlugin.onEvent(({ action, schema, table, data }) => {
    ctx.waitUntil(
        slackPlugin.sendMessage({
            blocks: [
                {
                    type: 'section',
                    text: {
                        type: 'mrkdwn',
                        text: `${action} detected on ${table}`,
                    },
                },
                {
                    type: 'section',
                    text: {
                        type: 'mrkdwn',
                        text: 'The following data was associated with this action:',
                    },
                },
                {
                    type: 'section',
                    block_id: 'section_1',
                    text: {
                        type: 'mrkdwn',
                        text: '```' + `${JSON.stringify(data)}` + '```',
                    },
                },
            ],
        })
    )
})

Before

After

Brayden avatar Feb 04 '25 17:02 Brayden

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 2.07% (🎯 75%) 21 / 1010
🔴 Statements 1.98% (🎯 75%) 21 / 1057
🔴 Functions 2.99% (🎯 75%) 5 / 167
🔴 Branches 0% (🎯 75%) 0 / 594
File CoverageNo changed files found.
Generated in workflow #57 for commit 53a3f18 by the Vitest Coverage Report Action

github-actions[bot] avatar Feb 04 '25 17:02 github-actions[bot]