starbasedb icon indicating copy to clipboard operation
starbasedb copied to clipboard

Slack plugin for sending messages to webhooks

Open Brayden opened this issue 10 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