### Chatery WhatsApp Quick Start Guide Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md A quick start guide for the Chatery WhatsApp project, showing essential commands to start the server, create a session, get a QR code, and send a message using cURL. ```bash # Start the server npm start # Create a session curl -X POST http://localhost:3000/api/whatsapp/sessions/mysession/connect \ -H "X-Api-Key: your_api_key" \ -H "Content-Type: application/json" # Get QR Code # http://localhost:3000/api/whatsapp/sessions/mysession/qr/image (requires API key) # Send a message curl -X POST http://localhost:3000/api/whatsapp/chats/send-text \ -H "X-Api-Key: your_api_key" \ -H "Content-Type: application/json" \ -d '{"sessionId": "mysession", "chatId": "628123456789", "message": "Hello!"}' ``` -------------------------------- ### Standard Installation of Chatery WhatsApp API Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Instructions for setting up the Chatery project locally using Git and npm. This process involves cloning the repository, installing dependencies, configuring the environment, and starting the server. ```bash git clone https://github.com/farinchan/chatery_whatsapp.git cd chatery_whatsapp npm install cp .env.example .env npm start ``` -------------------------------- ### Docker Installation of Chatery WhatsApp API Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Instructions for deploying the Chatery project using Docker Compose. This method is recommended for containerized environments to ensure consistent configuration and easy management. ```bash git clone https://github.com/farinchan/chatery_whatsapp.git cd chatery_whatsapp cp .env.example .env docker-compose up -d ``` -------------------------------- ### API Key Authentication Setup for Chatery WhatsApp Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Demonstrates how to set up and use API key authentication for the Chatery WhatsApp API. This includes setting the API key in the .env file and including the 'X-Api-Key' header in requests. ```bash # Enable API Key Authentication API_KEY=your_super_secret_key_12345 # Example cURL request curl -X GET http://localhost:3000/api/whatsapp/sessions \ -H "X-Api-Key: your_super_secret_key_12345" ``` ```bash # Disable API Key Authentication API_KEY= # or API_KEY=your_api_key_here ``` -------------------------------- ### Get QR Code for Session Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Retrieves the QR code needed to connect your WhatsApp account to the session. ```APIDOC ## GET /api/whatsapp/sessions/{sessionId}/qr/image ### Description Retrieves the QR code image for a given session. This QR code is used to link your WhatsApp account. ### Method GET ### Endpoint `/api/whatsapp/sessions/{sessionId}/qr/image` ### Parameters #### Path Parameters - **sessionId** (string) - Required - The unique identifier for the session. ### Request Example Access this URL in your browser or use curl: ``` http://localhost:3000/api/whatsapp/sessions/mysession/qr/image ``` Or using curl with authentication: ```bash curl -X GET http://localhost:3000/api/whatsapp/sessions/mysession/qr/image \ -H "X-Api-Key: your_api_key" ``` ### Response #### Success Response (200) - **Image** (image/png) - The QR code image. #### Response Example (Returns a PNG image stream) ``` -------------------------------- ### Document Ready Event Listener and Initialization Source: https://github.com/farinchan/chatery_whatsapp/blob/main/public/dashboard.html Sets up event listeners for when the DOM is fully loaded. It checks authentication, connects to the WebSocket, loads sessions, and starts periodic updates for WebSocket statistics. ```JavaScript document.addEventListener('DOMContentLoaded', async () => { if (!checkAuth()) { const loggedIn = await promptLogin(); if (!loggedIn) return; } connectWebSocket(); loadSessions(); loadWsStats(); updateRequestBody(); setInterval(() => { loadSessions(); loadWsStats(); }, 30000); }); ``` -------------------------------- ### Get Chats Overview (HTTP) Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Fetches an overview of chats, allowing filtering by type and pagination. Requires a session ID and optional limit/offset parameters. ```http POST /chats/overview ``` -------------------------------- ### Chatery WhatsApp Environment Configuration (.env file) Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Example of the .env file used to configure the Chatery WhatsApp application. It includes settings for the server port, CORS origin, dashboard authentication credentials, and API key for authentication. ```env PORT=3000 CORS_ORIGIN=* DASHBOARD_USERNAME=admin DASHBOARD_PASSWORD=securepassword123 API_KEY=your_secret_api_key_here ``` -------------------------------- ### Docker Compose Commands for Chatery WhatsApp Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Common Docker Compose commands used to manage the Chatery WhatsApp application containers. These commands allow for starting, stopping, viewing logs, restarting, and rebuilding the application's Docker images. ```bash docker-compose up -d docker-compose down docker-compose logs -f docker-compose restart docker-compose build --no-cache ``` -------------------------------- ### Get QR Code (JSON) (HTTP) Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Retrieves the QR code for a session in JSON format. This is typically used for initiating a new WhatsApp connection. ```http GET /sessions/:sessionId/qr ``` -------------------------------- ### Get QR Code (Image) (HTTP) Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Retrieves the QR code for a session as a PNG image. This image can be directly displayed or scanned by a WhatsApp client. ```http GET /sessions/:sessionId/qr/image ``` -------------------------------- ### Get All Groups (HTTP) Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Retrieves a list of all groups the authenticated session is part of. Returns group details such as ID, subject, participant count, and creation timestamp. ```http POST /groups ``` -------------------------------- ### Get All Bulk Jobs (HTTP) Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Retrieves a list of all initiated bulk messaging jobs. This endpoint requires a session ID and returns job details including status, counts, and timestamps. ```http POST /chats/bulk-jobs ``` -------------------------------- ### Get All Groups Source: https://github.com/farinchan/chatery_whatsapp/blob/main/public/dashboard.html Retrieve a list of all groups the user is a part of. ```APIDOC ## POST /api/whatsapp/groups ### Description Get all groups you are participating in. ### Method POST ### Endpoint /api/whatsapp/groups ### Parameters #### Request Body - **sessionId** (string) - Required - The session ID for the WhatsApp connection. ### Request Example ```json { "sessionId": "your_session_id" } ``` ### Response #### Success Response (200) - **groups** (array of objects) - An array of group objects. - **id** (string) - The group ID. - **name** (string) - The group name. #### Response Example ```json { "groups": [ { "id": "123456789@g.us", "name": "My Group" } ] } ``` ``` -------------------------------- ### Get Contacts Source: https://github.com/farinchan/chatery_whatsapp/blob/main/public/dashboard.html Retrieve a list of contacts, with options for filtering and searching. ```APIDOC ## POST /api/whatsapp/contacts ### Description Get a list of contacts. Allows filtering by name or number using the search parameter. ### Method POST ### Endpoint /api/whatsapp/contacts ### Parameters #### Request Body - **sessionId** (string) - Required - The session ID for the WhatsApp connection. - **limit** (integer) - Optional - Maximum number of contacts to return (default: 100). - **offset** (integer) - Optional - Number of contacts to skip for pagination (default: 0). - **search** (string) - Optional - Filter contacts by name or number. ### Request Example ```json { "sessionId": "your_session_id", "search": "John" } ``` ### Response #### Success Response (200) - **contacts** (array of objects) - An array of contact objects. - **id** (string) - The contact's ID. - **name** (string) - The contact's name. - **pushname** (string) - The contact's push name. #### Response Example ```json { "contacts": [ { "id": "628123456789@s.whatsapp.net", "name": "John Doe", "pushname": "John" } ] } ``` ``` -------------------------------- ### Get Chat Info Source: https://github.com/farinchan/chatery_whatsapp/blob/main/public/dashboard.html Retrieve detailed information about a specific chat or group. ```APIDOC ## POST /api/whatsapp/chats/info ### Description Get detailed information about a chat or group, including participants, admins, and settings. ### Method POST ### Endpoint /api/whatsapp/chats/info ### Parameters #### Request Body - **sessionId** (string) - Required - The session ID for the WhatsApp connection. - **chatId** (string) - Required - The ID of the chat (e.g., '628123456789@s.whatsapp.net' or '123456789@g.us'). ### Request Example ```json { "sessionId": "your_session_id", "chatId": "123456789@g.us" } ``` ### Response #### Success Response (200) - **chatInfo** (object) - An object containing detailed chat information. - **id** (string) - The chat ID. - **name** (string) - The name of the chat/group. - **isGroup** (boolean) - True if it's a group chat. - **participants** (array of objects) - List of participants (if group). - **adminIds** (array of strings) - List of admin IDs (if group). #### Response Example ```json { "chatInfo": { "id": "123456789@g.us", "name": "Awesome Group", "isGroup": true, "participants": [ // ... participant details ... ], "adminIds": ["628123456789@s.whatsapp.net"] } } ``` ``` -------------------------------- ### Listen for WebSocket Events Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Demonstrates how to listen for incoming messages, QR code generation, and connection status updates. ```javascript const socket = io('http://localhost:3000'); socket.on('connect', () => { console.log('Connected to WebSocket'); socket.emit('subscribe', 'mysession'); }); socket.on('message', (data) => { console.log('New message:', data.message); }); socket.on('qr', (data) => { console.log('Scan QR Code:', data.qrCode); }); socket.on('connection.update', (data) => { console.log('Connection status:', data.status); }); ``` -------------------------------- ### Get Chat Messages Source: https://github.com/farinchan/chatery_whatsapp/blob/main/public/dashboard.html Retrieve messages from a specific chat, with support for pagination. ```APIDOC ## POST /api/whatsapp/chats/messages ### Description Get messages from a specific chat. Supports pagination using a cursor (message ID). ### Method POST ### Endpoint /api/whatsapp/chats/messages ### Parameters #### Request Body - **sessionId** (string) - Required - The session ID for the WhatsApp connection. - **chatId** (string) - Required - The ID of the chat. Use '@s.whatsapp.net' for personal chats and '@g.us' for groups. - **limit** (integer) - Optional - Maximum number of messages to return (default: 50). - **cursor** (string) - Optional - Message ID for pagination. Use the ID of the last message received to fetch older messages. ### Request Example ```json { "sessionId": "your_session_id", "chatId": "628123456789@s.whatsapp.net", "limit": 30 } ``` ### Response #### Success Response (200) - **messages** (array of objects) - An array of message objects. - **id** (string) - The message ID. - **fromMe** (boolean) - True if the message was sent by you. - **text** (string) - The message content. - **timestamp** (integer) - Timestamp of the message. #### Response Example ```json { "messages": [ { "id": "message_abc123", "fromMe": false, "text": "Hi there!", "timestamp": 1678886400 } ] } ``` ``` -------------------------------- ### Configuration (.env file) Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Environment variables for configuring the Chatery WhatsApp application. ```APIDOC ## Configuration Create a `.env` file in the root directory: ```env PORT=3000 CORS_ORIGIN=* # Dashboard Authentication DASHBOARD_USERNAME=admin DASHBOARD_PASSWORD=securepassword123 # API Key Authentication (optional - leave empty or 'your_api_key_here' to disable) API_KEY=your_secret_api_key_here ``` ``` -------------------------------- ### Get All Groups - Chatery WhatsApp API Source: https://github.com/farinchan/chatery_whatsapp/blob/main/public/dashboard.html Retrieves a list of all groups the user is a participant in. ```javascript body = { sessionId: '' }; helpText = 'đĨ Get all groups you are participating in.'; ``` -------------------------------- ### Initialize WebSocket Connection Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Establishes a connection to the WebSocket server and manages session subscriptions. ```javascript import { io } from 'socket.io-client'; const socket = io('http://localhost:3000'); // Subscribe to a session socket.emit('subscribe', 'mysession'); // Unsubscribe from a session socket.emit('unsubscribe', 'mysession'); ``` -------------------------------- ### Get Profile Picture Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Retrieves the profile picture associated with a given phone number. ```http POST /chats/profile-picture ``` ```json { "sessionId": "mysession", "phone": "628123456789" } ``` -------------------------------- ### Get All Bulk Jobs Source: https://context7.com/farinchan/chatery_whatsapp/llms.txt Retrieves a list of all bulk jobs associated with a specific session. ```APIDOC ## POST /api/whatsapp/chats/bulk-jobs ### Description Retrieves all bulk jobs for a session. ### Method POST ### Endpoint /api/whatsapp/chats/bulk-jobs ### Parameters #### Request Body - **sessionId** (string) - Required - The session ID to filter bulk jobs by. ### Request Example ```json { "sessionId": "mysession" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **data** (array of objects) - A list of bulk jobs. - **jobId** (string) - The unique ID for the bulk job. - **type** (string) - The type of bulk job (e.g., "text", "image"). - **status** (string) - The current status of the job. - **total** (number) - The total number of messages intended for the job. #### Response Example ```json { "success": true, "data": [ { "jobId": "bulk_1704326400000_abc123def", "type": "text", "status": "completed", "total": 50 } ] } ``` ``` -------------------------------- ### Get Invite Code Source: https://context7.com/farinchan/chatery_whatsapp/llms.txt Retrieves the current invitation code and link for a specified WhatsApp group. ```APIDOC ## POST /api/whatsapp/groups/invite-code ### Description Retrieves the group invitation code/link. ### Method POST ### Endpoint /api/whatsapp/groups/invite-code ### Parameters #### Request Body - **sessionId** (string) - Required - The session ID for the WhatsApp connection. - **groupId** (string) - Required - The ID of the group to get the invite code from. ### Request Example ```json { "sessionId": "mysession", "groupId": "123456789@g.us" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **message** (string) - A confirmation message. - **data** (object) - Contains the invite details. - **groupId** (string) - The ID of the group. - **inviteCode** (string) - The invitation code. - **inviteLink** (string) - The full invitation link. #### Response Example ```json { "success": true, "message": "Invite code retrieved successfully", "data": { "groupId": "123456789@g.us", "inviteCode": "AbCdEfGhIjKlMn", "inviteLink": "https://chat.whatsapp.com/AbCdEfGhIjKlMn" } } ``` ``` -------------------------------- ### Create or Connect WhatsApp Session Source: https://context7.com/farinchan/chatery_whatsapp/llms.txt Initializes a new WhatsApp session or reconnects an existing one. Accepts optional metadata and webhook configurations in the request body. ```bash curl -X POST http://localhost:3000/api/whatsapp/sessions/mysession/connect \ -H "X-Api-Key: your_api_key" \ -H "Content-Type: application/json" \ -d '{ "metadata": { "userId": "user123", "plan": "premium" }, "webhooks": [ {"url": "https://example.com/webhook", "events": ["all"]}, {"url": "https://analytics.example.com/webhook", "events": ["message"]} ] }' ``` -------------------------------- ### Get Bulk Job Status Source: https://context7.com/farinchan/chatery_whatsapp/llms.txt Retrieves the status and progress of a specific bulk messaging job. ```APIDOC ## GET /api/whatsapp/chats/bulk-status/{jobId} ### Description Retrieves the status and progress of a bulk messaging job. ### Method GET ### Endpoint /api/whatsapp/chats/bulk-status/{jobId} ### Parameters #### Path Parameters - **jobId** (string) - Required - The ID of the bulk job to retrieve status for. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **data** (object) - Contains the status details of the bulk job. - **sessionId** (string) - The session ID used for the job. - **type** (string) - The type of bulk job (e.g., "text", "image"). - **status** (string) - The current status of the job (e.g., "completed", "processing", "failed"). - **total** (number) - The total number of messages to be sent. - **sent** (number) - The number of messages successfully sent. - **failed** (number) - The number of messages that failed to send. - **progress** (number) - The completion percentage of the job. - **details** (array of objects) - Detailed status for each recipient. - **recipient** (string) - The recipient's phone number. - **status** (string) - The status for this specific recipient (e.g., "sent", "failed"). - **messageId** (string) - The message ID if sent successfully. - **error** (string) - Error message if sending failed. - **timestamp** (string) - Timestamp of the status update. - **createdAt** (string) - Timestamp when the job was created. - **completedAt** (string) - Timestamp when the job was completed. #### Response Example ```json { "success": true, "data": { "sessionId": "mysession", "type": "text", "status": "completed", "total": 50, "sent": 48, "failed": 2, "progress": 100, "details": [ { "recipient": "628123456789", "status": "sent", "messageId": "ABC123", "timestamp": "2024-01-15T10:00:00.000Z" }, { "recipient": "628987654321", "status": "failed", "error": "Number not registered", "timestamp": "2024-01-15T10:00:01.000Z" } ], "createdAt": "2024-01-15T10:00:00.000Z", "completedAt": "2024-01-15T10:02:30.000Z" } } ``` ``` -------------------------------- ### Create WhatsApp Session Source: https://github.com/farinchan/chatery_whatsapp/blob/main/README.md Initiates a new WhatsApp session. This is the first step to connect your WhatsApp account. ```APIDOC ## POST /api/whatsapp/sessions/{sessionId}/connect ### Description Creates and connects a new WhatsApp session. ### Method POST ### Endpoint `/api/whatsapp/sessions/{sessionId}/connect` ### Parameters #### Path Parameters - **sessionId** (string) - Required - The unique identifier for the session. #### Request Body None ### Request Example ```bash curl -X POST http://localhost:3000/api/whatsapp/sessions/mysession/connect \ -H "X-Api-Key: your_api_key" \ -H "Content-Type: application/json" ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the session is being created. #### Response Example ```json { "message": "Session mysession is being created" } ``` ``` -------------------------------- ### Connect to WebSocket and Subscribe to Events Source: https://context7.com/farinchan/chatery_whatsapp/llms.txt Establishes a WebSocket connection to the server and subscribes to various session events for real-time notifications. Handles connection, subscription confirmation, QR code generation, connection status updates, message events, presence updates, group changes, and logout. ```javascript import { io } from 'socket.io-client'; const socket = io('http://localhost:3000'); // Subscribe to a session socket.on('connect', () => { console.log('Connected to WebSocket'); socket.emit('subscribe', 'mysession'); }); // Handle subscription confirmation socket.on('subscribed', (data) => { console.log('Subscribed:', data.message); }); // Handle QR code generation socket.on('qr', (data) => { console.log('QR Code ready:', data.qrCode); }); // Handle connection status changes socket.on('connection.update', (data) => { console.log('Connection status:', data.status); if (data.status === 'connected') { console.log(`Connected as ${data.name} (${data.phoneNumber})`); } }); // Handle new incoming messages socket.on('message', (data) => { console.log('New message:', data.message); }); // Handle message sent confirmation socket.on('message.sent', (data) => { console.log('Message sent:', data.message); }); // Handle message status updates (read, delivered) socket.on('message.update', (data) => { console.log('Message status update:', data.update); }); // Handle presence updates (typing, online) socket.on('presence.update', (data) => { console.log('Presence update:', data.presence); }); // Handle group updates socket.on('group.participants', (data) => { console.log('Group participants changed:', data.update); }); // Handle logout socket.on('logged.out', (data) => { console.log('Session logged out:', data.message); }); // Unsubscribe when done socket.emit('unsubscribe', 'mysession'); ``` -------------------------------- ### GET /api/whatsapp/sessions Source: https://context7.com/farinchan/chatery_whatsapp/llms.txt Retrieves a list of all active WhatsApp sessions including connection status and metadata. ```APIDOC ## GET /api/whatsapp/sessions ### Description Retrieves information about all active WhatsApp sessions including connection status, phone number, and configured webhooks. ### Method GET ### Endpoint /api/whatsapp/sessions ### Parameters #### Headers - **X-Api-Key** (string) - Required - API authentication key ### Request Example curl -X GET http://localhost:3000/api/whatsapp/sessions -H "X-Api-Key: your_api_key" ### Response #### Success Response (200) - **success** (boolean) - Status of the request - **data** (array) - List of session objects #### Response Example { "success": true, "message": "Sessions retrieved", "data": [ { "sessionId": "mysession", "status": "connected", "isConnected": true, "phoneNumber": "628123456789", "name": "John Doe" } ] } ``` -------------------------------- ### Load and Render Webhooks Source: https://github.com/farinchan/chatery_whatsapp/blob/main/public/dashboard.html Fetches and displays the list of configured webhooks for a session. It handles loading states and error scenarios while rendering the webhook list dynamically. ```javascript async function loadWebhooks(sessionId) { const container = document.getElementById('webhooksList'); container.innerHTML = '
setting options:announcement - Only admins can send messagesnot_announcement - All members can sendlocked - Only admins can edit group infounlocked - All members can edit group info
`; } else if (path.includes('/groups/picture')) { body = { sessionId: '', groupId: '123456789@g.us', imageUrl: 'https://example.com/group-pic.jpg' }; helpText = 'đŧī¸ Update group profile picture. Image should be square.'; } else if (path.includes('/groups/invite-code')) { body = { sessionId: '', groupId: '123456789@g.us' }; helpText = 'đ Get the current invite link for the group.'; } else if (path.includes('/groups/revoke-invite')) { body = { sessionId: '', groupId: '123456789@g.us' }; helpText = 'đ Revoke current invite link and generate a new one.'; }
```
--------------------------------
### Get WhatsApp Session Status
Source: https://context7.com/farinchan/chatery_whatsapp/llms.txt
Returns the current connection status and metadata for a specific session ID. Useful for monitoring session health.
```bash
curl -X GET http://localhost:3000/api/whatsapp/sessions/mysession/status \
-H "X-Api-Key: your_api_key"
```