Overview
Custom Cap BD automatically sends real-time notifications to your Discord server whenever:
- A new order is submitted
- An order status is updated
- An urgent order requires immediate attention
This system provides instant visibility into your order pipeline without requiring manual monitoring.
Notification Types
1. New Order Notifications
Triggered when: Customer submits a new order
Channel: #new-orders
Information Included:
- Order ID and customer details
- Product name and quantity
- Delivery urgency
- Total price
- Shipping location
2. Order Status Updates
Triggered when: Admin changes order status
Channel: #order-updates
Information Included:
- Order ID and customer name
- Status change (old → new)
- Updated by (admin name)
- Color-coded by status
Status Colors:
- 🟡 PENDING_REVIEW (Yellow)
- 🟢 CONFIRMED (Green)
- 🔵 PRODUCTION (Blue)
- 🟣 SHIPPED (Pink)
- 🟢 DELIVERED (Dark Green)
- 🔴 CANCELLED (Red)
3. Urgent Order Alerts
Triggered when: Order meets urgent criteria
Channel: #urgent-orders
Urgent Criteria:
- Express delivery (8-12 days)
- Rush delivery (4-6 days)
- High-value orders (>$5,000)
- Large quantity (>500 units)
Special Feature: Mentions @everyone for immediate attention
Setup Instructions
Step 1: Create Discord Webhooks
- Open Discord server settings
- Go to Integrations → Webhooks
- Create webhook for each channel:
#new-orders#order-updates#urgent-orders
- Copy webhook URLs
Step 2: Configure Database
Run the migration in Supabase SQL Editor:
-- Update webhook URLs for each channel
UPDATE discord_channels
SET webhook_url = 'YOUR_WEBHOOK_URL_HERE'
WHERE channel_id = 'CHANNEL_ID_HERE';
Step 3: Test Notifications
-
Test Order Creation:
- Submit a test order via the product page
- Check
#new-ordersfor notification
-
Test Status Update:
- Update an order status in Admin Dashboard
- Check
#order-updatesfor notification
Example Notifications
New Order Message
🎉 New Custom Order Received!
Order CCBD-1730567890-A1B2 has been submitted
👤 Customer: John Doe
📧 john@example.com
📱 +880-1234567890
📦 Product: 6-Panel Structured Cap
🔢 Quantity: 100 pieces
⚡ Urgency: Standard
💵 Total: $1,250.00
📍 Shipping: Dhaka, Bangladesh
Status Update Message
📊 Order Status Updated
Order CCBD-1730567890-A1B2 status changed
👤 Customer: John Doe
📋 Status Change: PENDING_REVIEW → IN_PRODUCTION
Updated by Admin
Troubleshooting
No notifications received?
Check these:
- ✅ Webhook URL configured in database
- ✅ Webhook not expired/deleted in Discord
- ✅ Channel IDs match your Discord server
- ✅ Supabase connection active
- ✅ Check notification logs in database
View Notification History
Query recent notifications:
SELECT
channel_type,
message_content,
status,
sent_at,
error_message
FROM discord_notifications
ORDER BY sent_at DESC
LIMIT 20;
Technical Details
Database Schema
Table: discord_channels
- Stores channel IDs and webhook URLs
- RLS enabled (OFFICIAL users only)
Table: discord_notifications
- Logs all sent notifications
- Tracks delivery status and errors
API Integration
Order Submission: POST /api/orders/submit
- Calls
sendNewOrderNotification() - Calls
sendUrgentOrderNotification()(if urgent)
Order Update: PATCH /api/orders/[orderId]
- Calls
sendOrderStatusUpdate()(if status changed)
Error Handling
- Notification failures don't block order operations
- Errors logged to console and database
- Automatic retry (future enhancement)
Security
Webhook Protection
- ✅ Stored in database (server-side only)
- ✅ RLS policies restrict access
- ✅ Never exposed to client-side code
Rate Limiting
- Discord allows 30 requests/minute per webhook
- Current volume: Safe for typical usage
- Future: Rate limiting for high-volume scenarios
Advanced Features
Notification Logs
View complete notification history in Admin Dashboard:
- Path: Admin → Communication → Discord Logs
- Features:
- Filter by channel, status, date
- Retry failed notifications
- Export logs to CSV
Custom Notifications
Extend the system for custom events:
import { sendDiscordNotification } from '@/lib/discord-notification';
// Send custom notification
await sendDiscordNotification({
channelId: 'YOUR_CHANNEL_ID',
embed: {
title: 'Custom Event',
description: 'Something important happened!',
color: 0x5865F2,
fields: [
{ name: 'Field 1', value: 'Value 1', inline: true }
]
}
});
Related Documentation
Support
For questions or issues:
- Check troubleshooting section above
- Review notification logs in database
- Contact technical support
System Status: ✅ Production Ready