snap-notify
v0.1.0
Published
Slack DSL for sending templated messages
Downloads
3
Readme
snap-notify.js
A simple and flexible Slack messaging library that supports both YAML-based templates and programmatic message sending.
Features
- 📝 YAML-based message templates with variable substitution
- 🧩 Support for all Slack message features (text, blocks, attachments)
- 🧵 Thread support
- ⚡️ Simple programmatic API
- 🔒 Environment-based configuration
Installation
npm install snap-notifyConfiguration
Set your Slack bot token as an environment variable:
export SLACK_TOKEN=xoxb-your-tokenUsage
Using Templates (DSL)
- Create a YAML template (e.g.,
templates/welcome.yml):
text: "Hey {{username}}, welcome to the team! 🎉"
channel: "#general"
thread_ts: "{{thread_ts}}" # optional for thread replies- Load and send the template:
import { loadTemplate } from 'snap-notify';
import { sendSlackMessage } from 'snap-notify/slack';
const variables = {
username: 'Chris',
thread_ts: '', // optional: set if replying in a thread
};
const message = loadTemplate('templates/welcome.yml', variables);
await sendSlackMessage(message);Programmatic Usage
You can also create and send messages programmatically:
import { sendSlackMessage } from 'snap-notify/slack';
await sendSlackMessage({
text: 'Hello from snap-notify! 👋',
channel: '#general',
blocks: [{
type: 'section',
text: {
type: 'mrkdwn',
text: '*Welcome to snap-notify!*\nA simple way to send Slack messages.'
}
}]
});Message Options
The message object supports all Slack message options:
text(string) - Message textchannel(string) - Channel, private group, or DM channel to send message tothread_ts(string) - Provide another message'stsvalue to make this message a replyblocks(array) - A list of block elementsattachments(array) - Legacy message attachments
License
MIT
