A complete WhatsApp automation system for order processing using n8n workflows, Node.js, and WhatsApp Business API.
- WhatsApp Integration: Full WhatsApp Business API integration
- n8n Workflows: Visual workflow automation for order processing
- Order Management: Complete order lifecycle management
- Customer Management: Automatic customer data collection
- Real-time Processing: Instant message processing and responses
- Menu System: Dynamic menu display and ordering
- Order Tracking: Real-time order status tracking
- Database Storage: SQLite database for orders and customers
- Node.js 16+ installed
- WhatsApp Business API access
- Facebook Developer Account
- n8n installed globally
npm installnpm install n8n -gCopy .env.example to .env and configure:
cp .env.example .envFill in your WhatsApp Business API credentials:
WHATSAPP_ACCESS_TOKEN: Your access token from Facebook Developer ConsoleWHATSAPP_PHONE_NUMBER_ID: Your WhatsApp Business phone number IDWHATSAPP_WEBHOOK_VERIFY_TOKEN: A secure token for webhook verification
# Start the Node.js server
npm start
# In another terminal, start n8n
n8n start- Go to Facebook Developer Console
- Navigate to your WhatsApp app
- Set webhook URL:
http://your-domain.com/webhook/whatsapp - Set verify token: Use the same token from your
.envfile - Subscribe to message events
- Open n8n at
http://localhost:5678 - Import the workflow from
n8n-workflows/whatsapp-order-automation.json - Configure the webhook nodes with your server URL
Customers can interact with your WhatsApp bot using these commands:
MENU- Display the restaurant menuHELP- Show help informationTRACK- Track current order status1x2, 3x1- Order items (item ID x quantity)CONFIRM- Confirm pending orderCANCEL- Cancel pending order
- Customer sends message β Webhook receives message
- Message processing β System identifies command/order
- Menu request β Display available items
- Order placement β Parse items and quantities
- Order confirmation β Customer confirms order
- Order processing β System creates order record
- Status updates β Automatic notifications sent
id- Primary keyphone_number- WhatsApp number (unique)name- Customer nameemail- Customer emailaddress- Delivery address
id- Primary keyorder_number- Unique order identifiercustomer_id- Foreign key to customersstatus- Order status (pending, confirmed, preparing, ready, delivered, cancelled)items- JSON array of ordered itemstotal_amount- Order totalcreated_at- Order timestamp
id- Primary keyname- Product namedescription- Product descriptionprice- Product pricestock_quantity- Available stocksku- Product SKU
GET /api/orders- List all ordersGET /api/orders/:id- Get specific orderPOST /api/orders- Create new orderPATCH /api/orders/:id/status- Update order status
GET /api/customers- List all customersGET /api/customers/phone/:phone- Get customer by phonePOST /api/customers- Create/update customer
GET /webhook/whatsapp- Webhook verificationPOST /webhook/whatsapp- Process incoming messages
The included workflow contains:
- Webhook Trigger - Receives WhatsApp messages
- Message Router - Routes messages based on content
- Menu Handler - Displays product menu
- Order Parser - Processes order messages
- Order Creator - Creates order records
- Status Tracker - Handles order tracking
- Response Sender - Sends WhatsApp responses
Update the products table in SQLite or use the admin interface:
INSERT INTO products (name, description, price, stock_quantity, sku)
VALUES ('New Item', 'Description', 9.99, 50, 'ITEM-001');Edit services/whatsappService.js to customize message templates:
async sendOrderConfirmation(to, orderDetails) {
const message = `
π *Order Confirmed!*
π Order: ${orderDetails.orderNumber}
π° Total: $${orderDetails.total}
`.trim();
return this.sendMessage(to, message);
}Extend services/orderProcessor.js to handle new commands:
async processIncomingMessage(phoneNumber, messageText, messageType) {
const normalizedMessage = messageText.toLowerCase().trim();
if (normalizedMessage === 'your-command') {
await this.handleYourCommand(phoneNumber);
}
// ... existing commands
}- Server logs: Console output shows message processing
- Database logs: SQLite queries and results
- n8n logs: Workflow execution details in n8n interface
- WhatsApp API logs: Facebook Developer Console
-
Webhook not receiving messages
- Check webhook URL configuration
- Verify SSL certificate if using HTTPS
- Confirm webhook token matches
-
n8n workflow not triggering
- Ensure n8n webhook URL is correct
- Check workflow is active
- Verify node connections
-
Database errors
- Check database permissions
- Verify SQLite file path
- Review table schema
-
WhatsApp API errors
- Validate access token
- Check phone number ID
- Review API rate limits
MIT License - See LICENSE file for details
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Open pull request
For support and questions:
- Create GitHub issue
- Check documentation
- Review n8n community resources