@erulabs-tech/medusa-plugin-slack
v0.0.1
Published
A starter for Medusa plugins.
Maintainers
Readme
Features
- 📦 Order Notifications - Get notified when orders are placed, canceled, or completed
- 👤 Customer Alerts - Track new customer registrations
- 📊 Inventory Monitoring - Low stock alerts sent to your warehouse team
- 🚨 Error Monitoring - Critical error notifications for your dev team
- 🎨 Rich Formatting - Beautiful Slack messages with blocks, buttons, and attachments
- 🔗 Deep Links - Quick access to orders, customers, and products in admin
Installation
- Install the plugin:
pnpm add @erulabs-tech/medusa-plugin-slack- Configure in
medusa-config.js:
module.exports = defineConfig({
// ...
plugins: [
{
resolve: "@erulabs-tech/medusa-plugin-slack",
options: {
webhookUrl: process.env.SLACK_WEBHOOK_URL,
adminUrl: process.env.MEDUSA_ADMIN_URL,
defaultChannel: "#general",
username: "Medusa Bot",
iconEmoji: ":robot_face:",
},
},
],
});- Set environment variables:
# Required
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
MEDUSA_ADMIN_URL=https://admin.yourstore.com
# Optional
SLACK_DEFAULT_CHANNEL=#general
SLACK_USERNAME=Medusa Bot
SLACK_ICON_EMOJI=:robot_face:Available Notifications
Order Events
| Event | Channel | Description |
| ----------------- | ---------------- | ------------------------------- |
| order.placed | #orders | New order received with details |
| order.canceled | #orders-alerts | Order cancellation alert |
| order.completed | #fulfillment | Order successfully delivered |
Customer Events
| Event | Channel | Description |
| ------------------ | ------------ | ------------------------- |
| customer.created | #marketing | New customer registration |
Inventory Events
| Event | Channel | Description |
| ----------------- | ------------ | ------------------------------------- |
| product.updated | #warehouse | Low stock alert (threshold: 10 units) |
Error Monitoring
| Event | Channel | Description |
| ----------- | ------------- | ---------------------------- |
| app.error | #dev-alerts | Critical errors and warnings |
Example Slack Message
When an order is placed, you'll receive a rich Slack message like:
🛒 New Order Received
━━━━━━━━━━━━━━━━━━━━
Order ID: #1234
Customer: [email protected]
Total: $99.99 USD
Items: 3
━━━━━━━━━━━━━━━━━━━━
[View in Admin]Custom Notifications
Send custom Slack notifications from your code:
import { Modules } from "@medusajs/framework/utils";
const notificationModuleService = container.resolve(Modules.NOTIFICATION);
await notificationModuleService.createNotifications({
to: "#my-channel",
channel: "slack",
body: "Custom notification",
data: {
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: "🎉 Custom Header",
},
},
],
},
});Block Kit Helpers
The plugin includes helper functions for building Slack messages:
import {
createHeaderBlock,
createSectionBlock,
createDividerBlock,
createContextBlock,
createButtonBlock,
buildOrderNotificationBlocks,
buildCustomerNotificationBlocks,
buildInventoryAlertBlocks,
} from "@erulabs-tech/medusa-plugin-slack/utils";Testing
- Create a Slack app and enable incoming webhooks
- Copy the webhook URL to your
.envfile - Trigger events in your Medusa store
- Check your Slack channel for notifications
Troubleshooting
Notifications not appearing in Slack
- Verify your webhook URL is correct
- Check that the Slack app is installed in your workspace
- Ensure the webhook has permission to post to the target channel
Wrong channel receiving notifications
- Check the
tofield in your notification - Verify channel overrides in notification data
- Review subscriber configuration
Contributing
Contributions are welcome! Please read our contributing guidelines first.
License
Licensed under the MIT License. See LICENSE for more information.
