### Starting Local Services with Docker Compose Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Command to start the WAHA, PostgreSQL, and n8n services defined in a Docker Compose file. ```bash docker-compose up waha postgres n8n ``` -------------------------------- ### PostgreSQL Docker Compose Setup Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md Example Docker Compose configuration for setting up a PostgreSQL database service. This is commonly used for local development or staging environments. ```yaml services: postgres: image: postgres:15 environment: POSTGRES_DB: waha_db POSTGRES_USER: postgres POSTGRES_PASSWORD: password123 ports: - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data volumes: postgres_data: ``` -------------------------------- ### Get Contacts Response Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md This is an example of the JSON response when retrieving contacts. It includes details like ID, name, and type for each contact. ```json { "contacts": [ { "id": "1234567890@c.us", "name": "John Doe", "pushname": "john", "number": "1234567890", "isBusiness": false, "isGroup": false } ] } ``` -------------------------------- ### Start WAHA Services with Docker Compose Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/README.md Launches the WAHA, PostgreSQL, and n8n services using Docker Compose. Ensure these services are accessible on their default ports. ```bash docker-compose up waha postgres n8n # WAHA on :3000, n8n on :5678, PostgreSQL on :5432 ``` -------------------------------- ### n8n Webhook Incoming Request Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md Example of an external system sending a POST request with a JSON payload to an n8n webhook endpoint for bulk message processing. ```bash curl -X POST \ https://n8n.example.com/webhook/id/messages/default/bulk \ -H "Content-Type: application/json" \ -d '[ {"text": "Hi", "phone": "1234567890"}, {"text": "Hello", "phone": "0987654321"} ]' ``` -------------------------------- ### Get Groups Response Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md This JSON structure represents the response when requesting groups. It lists group IDs, names, and their participants. ```json { "groups": [ { "id": "123456789-1234567890@g.us", "name": "Project Team", "participants": [ "1111111111@c.us", "2222222222@c.us" ] } ] } ``` -------------------------------- ### Development Environment Variables Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md Configure these environment variables for your local development setup. Includes settings for WAHA, PostgreSQL, and a test SMTP server. ```env WAHA_BASE_URL=http://localhost:3000 POSTGRES_HOST=localhost POSTGRES_DATABASE=waha_dev SMTP_HOST=localhost:1025 # Test SMTP server ``` -------------------------------- ### n8n Expression Syntax Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Example demonstrating the correct syntax for expressions in n8n, using double curly braces. ```javascript {{ }} ``` -------------------------------- ### Switch Node Case Configuration Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/n8n-nodes-reference.md Set up the 'Switch' node for multi-path routing based on evaluated expressions. This example defines cases for 'text' and 'image' types. ```javascript { "cases": [ { "condition": { "type": "string", "operation": "equals", "leftValue": "{{ $json.type }}", "rightValue": "text" } }, { "condition": { "type": "string", "operation": "equals", "leftValue": "{{ $json.type }}", "rightValue": "image" } } ], "fallback": "defaultOutput" } ``` -------------------------------- ### Local Development Environment Configuration Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Configuration for running WAHA, n8n, and PostgreSQL locally using Docker Compose. This setup is for internal network access only. ```yaml Environment: Laptop/Desktop WAHA: localhost:3000 n8n: localhost:5678 PostgreSQL: localhost:5432 Reach: Internal only ``` -------------------------------- ### Accessing Node Output Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/n8n-nodes-reference.md Provides examples of how to access data from the current item, previous nodes, or specific nodes within an n8n workflow. ```APIDOC ## Accessing Node Output ### Description Demonstrates how to retrieve output data from nodes within an n8n workflow. ### Accessing Current Item ```javascript // From previous node $json // Current item $json.field // Specific field ``` ### Accessing Specific Node Output ```javascript // From specific node $node["NodeName"].json // All output $node["NodeName"].json[0] // First item $node["NodeName"].json[0].field // Specific field ``` ### Accessing in Loop Context ```javascript // In loop context $item(0).json // Reference to original item ``` ``` -------------------------------- ### Docker Compose Full Stack Setup Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md A complete Docker Compose configuration for running WAHA, PostgreSQL, and n8n services together. This includes service definitions, ports, environment variables, volumes, and health checks. ```yaml version: '3.8' services: waha: image: devlikeapro/waha:latest ports: - "3000:3000" environment: LOG_LEVEL: info volumes: - ./waha-data:/root/.waha postgres: image: postgres:15 environment: POSTGRES_DB: waha_db POSTGRES_USER: waha_user POSTGRES_PASSWORD: waha_password ports: - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U waha_user"] interval: 10s timeout: 5s retries: 5 n8n: image: n8n:latest ports: - "5678:5678" environment: DB_TYPE: postgresdb DB_POSTGRESDB_HOST: postgres DB_POSTGRESDB_PORT: 5432 DB_POSTGRESDB_DATABASE: n8n DB_POSTGRESDB_USER: n8n_user DB_POSTGRESDB_PASSWORD: n8n_password WAHA_BASE_URL: http://waha:3000 POSTGRES_HOST: postgres POSTGRES_DATABASE: waha_db POSTGRES_USER: waha_user POSTGRES_PASSWORD: waha_password depends_on: postgres: condition: service_healthy volumes: - n8n_data:/home/node/.n8n volumes: postgres_data: n8n_data: ``` -------------------------------- ### n8n Webhook Path Parameters Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md Demonstrates how to define and access dynamic path parameters in an n8n webhook URL. The parameter 'session' is accessed within the workflow. ```javascript /messages/:session/bulk Incoming request: POST /webhook/id/messages/default/bulk Accessed in workflow as: $node["Webhook"].json.params.session // "default" ``` -------------------------------- ### Bulk Message Flow - Caller Request Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Example of a POST request to the /webhook/id/messages/default/bulk endpoint to send bulk messages. ```http POST /webhook/id/messages/default/bulk [{"text": "Hi", "phone": "1234567890"}] ``` -------------------------------- ### Get ChatWoot Contact by Phone Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Fetches a contact record from the `chatwoot_contacts` table using the provided WhatsApp phone number. ```sql SELECT * FROM chatwoot_contacts WHERE whatsapp_phone = $1; ``` -------------------------------- ### WAHA Invalid Number Format Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Illustrates the correct format for specifying a phone number when encountering an 'Invalid number' error. ```text 1234567890@c.us ``` -------------------------------- ### Send Video Message Request Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md This JSON structure is for sending a video file to a WhatsApp contact or group. Provide a publicly accessible 'videoUrl' for supported formats (MP4, MOV, AVI, WebM). An optional 'caption' can be added. ```json { "resource": "Chatting", "operation": "Send Video", "sessionId": "default", "chatId": "1234567890@c.us", "videoUrl": "https://example.com/video.mp4", "caption": "Watch this video" } ``` -------------------------------- ### Accessing Node Output Data Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/n8n-nodes-reference.md Examples of how to access data from previous nodes or specific nodes within an n8n workflow. This is crucial for passing data between nodes and within loops. ```javascript // From previous node $json // Current item $json.field // Specific field // From specific node $node["NodeName"].json // All output $node["NodeName"].json[0] // First item $node["NodeName"].json[0].field // Specific field // In loop context $item(0).json // Reference to original item ``` -------------------------------- ### Batching Messages with Delay in WAHA Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md For bulk sending, implement a loop with a delay between messages to prevent rate limiting. This example outlines the structure for batching. ```plaintext Loop Over Items ├─ Item: message ├─ Delay 1-2 seconds (prevent rate limit) └─ WAHA Send ``` -------------------------------- ### Get QR Code Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Fetches the QR code image necessary for session authentication. The response can be a base64 encoded image or a direct image URL. ```APIDOC ## Media: Get QR Code ### Description Fetch the QR code image for session authentication. ### Parameters #### Query Parameters - **sessionId** (string) - Required - WAHA session identifier ### Request Example ```json { "resource": "Media", "operation": "Get QR Code", "sessionId": "default" } ``` ### Response #### Success Response (200) - **qr** (string) - Base64 encoded image or URL - **status** (string) - Indicates the status of the operation, e.g., "success" #### Response Example ```json { "qr": "iVBORw0KGgoAAAANSUhEUgAAANwAAADcCAYAAACD/B/pAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEVSURBVHhe7dExAQAAAMKg9Ue20B9gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "default" } ``` ``` -------------------------------- ### n8n Webhook Query Parameters Access Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md Demonstrates how to access query string parameters from an incoming webhook request within an n8n workflow. The example shows accessing 'status' and 'user' parameters. ```javascript // Request: GET /webhook/id/path?status=pending&user=john $node["Webhook"].json.query.status // "pending" $node["Webhook"].json.query.user // "john" ``` -------------------------------- ### Cloud Deployment (AWS EC2) Environment Configuration Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Configuration for deploying WAHA and n8n on an AWS EC2 instance with RDS PostgreSQL. This setup allows public HTTPS access. ```yaml Environment: AWS EC2 WAHA: ec2-instance:3000 n8n: ec2-instance:5678 PostgreSQL: RDS Reach: Public HTTPS ``` -------------------------------- ### Test Workflow with Bulk Messages Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Send a POST request to your n8n webhook endpoint to test workflow execution with bulk message data. This example demonstrates sending multiple messages in a single request. ```bash # Example for bulk messages curl -X POST \ https://n8n.example.com/webhook/id/messages/default/bulk \ -H "Content-Type: application/json" \ -d '[{"text": "Hi", "phone": "1234567890"}]' ``` -------------------------------- ### Configure Conditional Logic in n8n Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Set up conditional branching within an n8n workflow using an 'If' node. This example checks if the incoming payload body equals 'ping' to determine the next step. ```javascript Double-click If node ↓ Configure condition: - Left value: {{ $json.payload.body }} - Operator: equals - Right value: "ping" ↓ Save ``` -------------------------------- ### Event-Driven Pattern Diagram Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Depicts the Event-Driven pattern, starting with a WhatsApp message received by WAHA, which sends a webhook to n8n. n8n then processes the event and uses a WAHA Action node to send a response back to WhatsApp. ```text WhatsApp Message │ └─ WAHA receives │ └─ WAHA sends HTTP webhook to n8n ↓ n8n WAHA Trigger (fires) ↓ Process ↓ WAHA Action node (send response) ↓ Response to WhatsApp ``` -------------------------------- ### Accessing QR Code Data in JavaScript Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Example of how to access the QR code data from the WAHA node's JSON output in a JavaScript environment. The 'qr' field can contain either base64 encoded image data or a URL. ```javascript // Get base64 QR const qrBase64 = $node["WAHA Get QR"].json.qr; // For email attachment // Use as image data in Email node attachment field ``` -------------------------------- ### Get Groups Request Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Send this JSON payload to fetch a list of groups associated with a WAHA session. The sessionId parameter is mandatory. ```json { "resource": "Contacts", "operation": "Get Groups", "sessionId": "default" } ``` -------------------------------- ### Get Contacts Request Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Use this JSON payload to retrieve a list of contacts for a WAHA session. Ensure the sessionId is correctly specified. ```json { "resource": "Contacts", "operation": "Get Contacts", "sessionId": "default" } ``` -------------------------------- ### Test PostgreSQL Connection and Create Database Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Verify the PostgreSQL server is reachable and create a new database if necessary for templates requiring persistent storage. ```bash # Test connection psql -h localhost -U postgres -d postgres -c "SELECT 1" # Create database if needed createdb waha_db ``` -------------------------------- ### Initialize PostgreSQL Schemas Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Use CREATE TABLE IF NOT EXISTS to initialize necessary tables for the workflow. This ensures tables are created only if they do not already exist. ```sql CREATE TABLE IF NOT EXISTS queue ( id SERIAL PRIMARY KEY, session VARCHAR(50), text TEXT NOT NULL, phone VARCHAR(50), messageId VARCHAR(50), status VARCHAR(50) ); CREATE TABLE IF NOT EXISTS conversations ( id SERIAL PRIMARY KEY, user_phone VARCHAR(50) UNIQUE NOT NULL, typebot_session_id VARCHAR(255), last_message TEXT, state JSONB, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); ``` -------------------------------- ### Test Database Connection Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Use this simple SQL query to verify basic database connectivity. ```sql SELECT 1; -- Simple connectivity test ``` -------------------------------- ### Test WAHA, PostgreSQL, and SMTP Connections Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md Use these commands to test the accessibility and basic functionality of WAHA, PostgreSQL, and SMTP services from the n8n server. ```bash # Test WAHA curl -I http://localhost:3000/api/sessions ``` ```bash # Test PostgreSQL psql -h localhost -U postgres -d waha_db -c "SELECT 1" ``` ```bash # Test SMTP telnet localhost 25 ``` -------------------------------- ### ChatWoot Webhook Payload Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md An example of a ChatWoot webhook payload that is triggered when a new message is created. This payload contains information about the message, sender, and conversation. ```json { "event": "message_created", "data": { "inbox_id": 123, "conversation_id": 456, "message": { "id": 789, "content": "Hello from ChatWoot", "sender": { "id": 111, "name": "Agent Name" } } } } ``` -------------------------------- ### n8n Webhook Error Response Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md Example of constructing an error response in an n8n Response node for webhook errors. This includes a 400 status code and a detailed error message. ```javascript // In Response node { "statusCode": 400, "body": { "error": "Invalid phone number format", "details": "Phone must be 10+ digits" } } ``` -------------------------------- ### n8n Webhook Response Node Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md Example of how to structure a response object in an n8n Response node when 'responseMode' is set to 'responseNode'. This defines the HTTP status code and response body. ```javascript // In Response node { "statusCode": 200, "body": { "status": "success", "processingId": $node["Processing"].json.id, "timestamp": new Date().toISOString() } } ``` -------------------------------- ### Configuration and Credentials Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/COMPLETION_SUMMARY.txt Reference for all configuration options and credential types used within the system. ```APIDOC ## Configuration and Credentials Reference ### Description This section provides a comprehensive reference for all configuration options and credential types supported by the system. It includes details on how to set up and use different credential types for authentication and authorization. ### Credential Types (Documentation for each credential type, including required fields and usage examples.) ### Configuration Options (Details on various configuration settings and their impact.) ``` -------------------------------- ### Typebot Webhook Payload Example Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md An example of a Typebot webhook payload that is received when a user completes a Typebot interaction. It includes bot and session identifiers, along with the user's response content. ```json { "botId": "bot123", "sessionId": "user456", "response": { "type": "text", "content": "What is your name?" } } ``` -------------------------------- ### Backup and Restore Database Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Use pg_dump for backups and psql for restoring PostgreSQL databases. Ensure correct host, username, and database name are provided. ```bash # Backup database pg_dump -h localhost -U username dbname > backup.sql # Restore psql -h localhost -U username dbname < backup.sql ``` -------------------------------- ### Get Groups Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Retrieves a list of all groups associated with the specified WAHA session. ```APIDOC ## Get Groups ### Description Retrieve list of groups for the session. ### Parameters #### Query Parameters - **sessionId** (string) - Required - WAHA session identifier ### Request Example ```json { "resource": "Contacts", "operation": "Get Groups", "sessionId": "default" } ``` ### Response #### Success Response (200) - **groups** (array) - List of group objects. - **id** (string) - Group ID (ends with @g.us) - **name** (string) - Group name - **participants** (array) - List of participant IDs #### Response Example ```json { "groups": [ { "id": "123456789-1234567890@g.us", "name": "Project Team", "participants": [ "1111111111@c.us", "2222222222@c.us" ] } ] } ``` ``` -------------------------------- ### Get Contacts Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Retrieves a list of all contacts associated with the specified WAHA session. ```APIDOC ## Get Contacts ### Description Retrieve list of contacts for the session. ### Parameters #### Query Parameters - **sessionId** (string) - Required - WAHA session identifier ### Request Example ```json { "resource": "Contacts", "operation": "Get Contacts", "sessionId": "default" } ``` ### Response #### Success Response (200) - **contacts** (array) - List of contact objects. - **id** (string) - WhatsApp ID (phone@c.us or group@g.us) - **name** (string) - Contact display name - **pushname** (string) - Name as saved in contact - **number** (string) - Phone number (without @c.us) - **isBusiness** (boolean) - True if business account - **isGroup** (boolean) - True if group chat #### Response Example ```json { "contacts": [ { "id": "1234567890@c.us", "name": "John Doe", "pushname": "john", "number": "1234567890", "isBusiness": false, "isGroup": false } ] } ``` ``` -------------------------------- ### Project Structure Overview Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/project-overview.md This tree displays the directory structure of the WAHA n8n Templates project, showing the organization of various workflow templates and supporting directories. ```bash waha-n8n-templates/ ├── README.md (main index) ├── chatting-template/ # Simple bot responding to ping/image ├── chatwoot/ # ChatWoot bidirectional sync (4 workflows) ├── fetch-image-rotate-and-send-it-back/ # Image processing pipeline ├── forward-all-text-messages-to-email/ # Message forwarding ├── restart-server-at-midnight/ # Scheduled server restart ├── send-bulk-messages/ # Bulk messaging with database tracking ├── send-custom-http-request-to-waha/ # Raw HTTP request example ├── send-qr-code-to-email/ # QR code delivery on session scan ├── whatsapp-typebot/ # Typebot conversational AI integration └── waha-trigger-explanation/ # Educational trigger explanation ``` -------------------------------- ### WAHA API: Get QR Code for Authentication Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Retrieve the QR code for a given session ID to authenticate the user. ```http GET /api/qr/{sessionId} ``` -------------------------------- ### Simple Value Mapping in WAHA Expressions Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Demonstrates mapping values from previous node outputs or current context, including string concatenation, within WAHA Action parameters. ```javascript // From previous node output {{ $node["WAHA Trigger"].json.payload.from }} // From current context {{ $json.phone }} // String concatenation {{ $json.phone + "@c.us" }} ``` -------------------------------- ### Production Environment Variables Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md Configure these environment variables for the production environment. Ensure secure and correct settings for WAHA, PostgreSQL, and SMTP. ```env WAHA_BASE_URL=https://waha.example.com POSTGRES_HOST=db.example.com POSTGRES_DATABASE=waha_prod POSTGRES_SSL=true SMTP_HOST=smtp-secure.example.com ``` -------------------------------- ### WAHA API: Check Session Existence Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Use this GET request to verify if a WAHA session ID is valid and exists. ```http GET /api/sessions/{id} ``` -------------------------------- ### Fetch Image, Rotate and Send it Back Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/workflows-index.md This workflow demonstrates an image processing pipeline. It fetches a remote image, rotates it 180 degrees, and sends the transformed image back to the sender via WhatsApp, marking the original message as seen. ```APIDOC ## Fetch Image, Rotate and Send it Back ### Description This workflow fetches a remote image, rotates it 180 degrees, and sends the transformed image back to the sender via WhatsApp. It also marks the original message as seen. ### Trigger WAHA Trigger (receives incoming messages) ### Key Operations - Receive message containing image URL or fetch image from message - Rotate image 180 degrees - Send rotated image back to sender - Mark original message as seen ### Nodes - WAHA Trigger - If node - HTTP Request - Image Processing node - WAHA Send Image - WAHA Mark as Seen ### Configuration - Requires WAHA API credentials - Image processing requires image transformation library (built into n8n) ``` -------------------------------- ### WhatsApp Phone Number Formats Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Examples of international and WAHA-specific phone number formats. The WAHA format is used for sending messages. ```text +1-202-555-1234 (display) 12025551234 (without +) 12025551234@c.us (WAHA format) ``` -------------------------------- ### Verify Bulk Messages Database Table Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md After running a migration workflow for the Bulk Messages template, verify that the 'queue' table in the 'waha_db' PostgreSQL database is empty, indicating successful initialization. ```bash psql -d waha_db -c "SELECT * FROM queue;" # Should return empty table (OK) ``` -------------------------------- ### Get Session Status Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Retrieves the current state of the WhatsApp session. Possible states include AUTHENTICATED, SCAN_QR_CODE, DISCONNECTED, LOADING, and ERROR. ```APIDOC ## Session: Get Session Status ### Description Retrieve current session state. ### Parameters #### Query Parameters - **sessionId** (string) - Required - WAHA session identifier ### Request Example ```json { "resource": "Session", "operation": "Get Session Status", "sessionId": "default" } ``` ### Response #### Success Response (200) - **sessionId** (string) - The identifier of the session. - **status** (string) - The current status of the session (e.g., AUTHENTICATED, SCAN_QR_CODE). - **number** (string) - The WhatsApp number associated with the session, if authenticated. #### Response Example ```json { "sessionId": "default", "status": "AUTHENTICATED", "number": "1234567890" } ``` ``` -------------------------------- ### WAHA Trigger Explanation Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/workflows-index.md This is an educational workflow designed to explain the mechanics of the WAHA Trigger node. ```APIDOC ## WAHA Trigger Explanation ### Purpose Educational workflow explaining WAHA Trigger node mechanics ### Content - How webhook URL is generated and used - Payload structure of incoming messages - Event types (message, session.status, etc.) - Message properties accessible in downstream nodes - Proper configuration in WAHA session ### Nodes - WAHA Trigger: Configured with explanatory comments - Sticky notes: Inline documentation - Exemplar nodes: Showing typical usage patterns ``` -------------------------------- ### Test PostgreSQL Connection Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md Verify your PostgreSQL connection using the psql command-line tool. This command checks if you can successfully connect to the database and run a simple query. ```bash psql -h localhost -U postgres -d waha_db SELECT 1; ``` -------------------------------- ### Test n8n Webhook with curl Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md Use curl to send POST requests to test n8n webhooks. This example demonstrates sending JSON data. ```bash # Test n8n webhook curl -X POST \ https://n8n.example.com/webhook/id/path \ -H "Content-Type: application/json" \ -d '{"key": "value"}' ``` -------------------------------- ### Implementing Rate Limiting with Delay Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md To avoid hitting WhatsApp's rate limits, implement a delay between sending messages, especially for bulk operations. This pattern shows a loop that sends a message and then pauses for one second before repeating. ```text Loop ├─ WAHA Send (message) ├─ Delay (1 second) └─ Repeat ``` -------------------------------- ### Bulk Message Flow - WAHA Send Text API Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Example of a POST request to the /api/send endpoint to send a text message via WAHA. ```http POST /api/send { "sessionId": "default", "chatId": "1234567890@c.us", "text": "Hi" } ``` -------------------------------- ### Typebot Environment Variables Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md Configure Typebot integration by setting these environment variables. The Base URL, Bot ID, and API Token are essential for communication. ```bash TYPEBOT_BASE_URL=https://typebot.io TYPEBOT_BOT_ID=bot_abc123xyz TYPEBOT_API_TOKEN=token_xyz789 ``` -------------------------------- ### Bidirectional Sync Pattern Diagram Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/glossary-and-reference.md Shows the Bidirectional Sync pattern between Service A (e.g., ChatWoot) and Service B (WhatsApp via WAHA) using n8n for transformation. It includes webhooks flowing in both directions. ```text Service A (ChatWoot) Service B (WhatsApp via WAHA) │ │ ├─ Webhook → n8n ──→ Transform → WAHA Send │ │ └─ ← Webhook ← Transform ← WAHA Trigger (reciprocal) ``` -------------------------------- ### Webhook API Documentation Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/COMPLETION_SUMMARY.txt Documentation for webhook patterns and integration, including security considerations. ```APIDOC ## Webhook Integration Patterns and Security ### Description This section details the webhook integration patterns supported by the system, along with security best practices for their implementation. ### Endpoint N/A (Describes patterns, not specific endpoints) ### Parameters N/A ### Request Example N/A ### Response N/A ### Security Information on securing webhook integrations, including authentication and authorization mechanisms. ``` -------------------------------- ### If Node Condition Configuration Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/n8n-nodes-reference.md Configure the 'If' node to route workflows based on specific conditions. This example checks if a JSON payload body equals 'ping'. ```javascript { "conditions": { "conditions": [ { "leftValue": "{{ $json.payload.body }}", "operator": { "type": "string", "operation": "equals" }, "rightValue": "ping" } ], "combinator": "or" } } ``` -------------------------------- ### Monitor Database Performance Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Analyze sequential and index scans to identify performance bottlenecks in user tables. ```sql SELECT schemaname, tablename, seq_scan, idx_scan FROM pg_stat_user_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema') ORDER BY seq_scan DESC; ``` -------------------------------- ### n8n Webhook Request Headers Access Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/webhooks-api.md Shows how to access common request headers sent to an n8n webhook. Examples include 'content-type', 'authorization', and 'x-api-key'. ```javascript // Common headers $node["Webhook"].json.headers["content-type"] $node["Webhook"].json.headers["authorization"] $node["Webhook"].json.headers["x-api-key"] ``` -------------------------------- ### Test PostgreSQL Database Connection Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Use this psql command to directly test your PostgreSQL database connection. Ensure the host, user, database name, and permissions are correctly configured. ```bash # Test connection directly psql -h localhost -U postgres -d waha_db -c "SELECT 1" ``` -------------------------------- ### WAHA Session Get Session Status Request Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Send this JSON payload to the WAHA node to retrieve the current status of a WhatsApp session. Requires a sessionId. ```json { "resource": "Session", "operation": "Get Session Status", "sessionId": "default" } ``` -------------------------------- ### Staging Environment Variables Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/configuration-credentials.md Set these environment variables for the staging environment. These values point to staging-specific services for WAHA, PostgreSQL, and SMTP. ```env WAHA_BASE_URL=https://waha-staging.example.com POSTGRES_HOST=db-staging.example.com POSTGRES_DATABASE=waha_staging SMTP_HOST=smtp.example.com ``` -------------------------------- ### WAHA Media Get QR Code Request Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/waha-action-node.md Send this JSON payload to the WAHA node to request a QR code for session authentication. Requires a sessionId. ```json { "resource": "Media", "operation": "Get QR Code", "sessionId": "default" } ``` -------------------------------- ### Check Database Indexes Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Inspect existing indexes on a specific table to understand query performance. ```sql SELECT * FROM pg_indexes WHERE tablename = 'queue'; ``` -------------------------------- ### Cron Node: Cron Expression Configuration Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/n8n-nodes-reference.md Configure the Cron node using a cron expression for complex scheduling. This example sets the schedule to run daily at midnight. ```javascript { "mode": "cronExpression", "cronExpression": "0 0 * * *" // Daily at midnight } ``` -------------------------------- ### Vacuum and Analyze Database Tables Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Reclaim unused space and update table statistics for improved query performance. ```sql -- Reclaim space and update statistics VACUUM ANALYZE queue; VACUUM ANALYZE conversations; ``` -------------------------------- ### Backup PostgreSQL Database Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/implementation-guide.md Command to create a SQL dump of the WAHA PostgreSQL database. This is essential for data recovery. ```bash # PostgreSQL backup pg_dump -h localhost -U postgres waha_db > backup.sql ``` -------------------------------- ### Safe Parameter Substitution in SQL Queries Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/database-integration.md Illustrates the correct method for using parameter placeholders ($1, $2, etc.) in SQL queries within n8n to prevent SQL injection. Avoid direct string concatenation. ```javascript // RIGHT: { "query": "SELECT * FROM users WHERE id = $1", "values": [id] } ``` -------------------------------- ### Send Bulk Messages via n8n Webhook Source: https://github.com/devlikeapro/waha-n8n-templates/blob/main/_autodocs/README.md Example of sending bulk messages to WAHA through an n8n webhook. The payload is an array of objects, each containing the message text and phone number. ```bash curl -X POST \ https://n8n.example.com/webhook/id/messages/default/bulk \ -H "Content-Type: application/json" \ -d '[{"text": "Hi", "phone": "1234567890"}]' ```