starbasedb
starbasedb copied to clipboard
Slack plugin for sending messages to webhooks
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
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 |