### Environment Setup Example Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Demonstrates copying the example environment file and setting the DATABASE_PROVIDER environment variable. ```bash # Copy example environment file cp .env.example .env # NEVER commit secrets to version control # Set DATABASE_PROVIDER before database commands export DATABASE_PROVIDER=postgresql # or mysql ``` -------------------------------- ### Install Dependencies and Configure Environment Source: https://github.com/evolution-foundation/evolution-api/blob/main/README.md Clone the repository, install Node.js dependencies, and configure your environment variables by copying the example file. ```bash git clone git@github.com:evolution-foundation/evolution-api.git cd evolution-api # Install dependencies npm install # Configure environment cp .env.example .env # Edit .env with your database, Redis, and API key ``` -------------------------------- ### Start Production Server Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Runs the production-ready build of the server. ```bash npm run start:prod ``` -------------------------------- ### Database Setup with Prisma Source: https://github.com/evolution-foundation/evolution-api/blob/main/README.md Set your database provider and then generate the Prisma client and deploy migrations. ```bash # Set the database provider export DATABASE_PROVIDER=postgresql # or mysql # Generate Prisma client npm run db:generate # Deploy migrations npm run db:deploy ``` -------------------------------- ### Conventional Commits Examples Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Provides examples of correctly formatted conventional commits for various types. ```bash # Examples # feat(api): add WhatsApp message status endpoint # fix(baileys): resolve connection timeout issue # docs(readme): update installation instructions # refactor(service): extract common message validation logic ``` -------------------------------- ### Start Server with tsx Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Directly executes the server using tsx for development or quick runs. ```bash npm start ``` -------------------------------- ### Start Typebot Session Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Manually initiates a Typebot session with specified parameters and variables. ```bash curl -s -X POST http://localhost:8080/typebot/start/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "url": "https://typebot.io", "typebot": "my-support-flow", "remoteJid": "5511999999999@s.whatsapp.net", "startSession": false, "variables": [ { "name": "customerName", "value": "John Doe" }, { "name": "orderId", "value": "12345" } ] }' ``` -------------------------------- ### Start Full Docker Development Stack Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Launches the complete development environment using a specific Docker Compose file. ```bash docker-compose -f docker-compose.dev.yaml up -d ``` -------------------------------- ### Start Local Docker Services Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Starts essential local services like Redis and PostgreSQL in detached mode using Docker Compose. ```bash docker-compose up -d ``` -------------------------------- ### Manually start a Typebot session Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Initiates a Typebot session for a specified instance. Allows setting initial variables and controlling session start behavior. ```APIDOC ## POST /typebot/start/{instanceName} ### Description Manually start a Typebot session for the specified instance. ### Method POST ### Endpoint /typebot/start/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the Typebot instance. #### Request Body - **url** (string) - Required - The URL of the Typebot. - **typebot** (string) - Required - The name of the Typebot flow. - **remoteJid** (string) - Required - The remote JID for the session. - **startSession** (boolean) - Optional - Whether to start the session immediately. - **variables** (array) - Optional - An array of initial variables for the session. - **name** (string) - Required - The name of the variable. - **value** (string) - Required - The value of the variable. ### Request Example ```json { "url": "https://typebot.io", "typebot": "my-support-flow", "remoteJid": "5511999999999@s.whatsapp.net", "startSession": false, "variables": [ { "name": "customerName", "value": "John Doe" }, { "name": "orderId", "value": "12345" } ] } ``` ``` -------------------------------- ### Conventional Commits CLI Example Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Shows how to use the interactive commit tool and the expected format for conventional commits. ```bash # Use interactive commit tool npm run commit # Commit format: type(scope): subject (max 100 chars) # Types: feat, fix, docs, style, refactor, perf, test, chore, ci, build, revert, security ``` -------------------------------- ### Get Current Settings Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves the current configuration settings for the instance. ```APIDOC ## GET /settings/find/{instanceName} — Get current settings ### Description Fetches the current configuration settings of the specified instance. ### Method GET ### Endpoint /settings/find/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance whose settings are to be retrieved. ``` -------------------------------- ### Controller Pattern Example (Thin Layer) Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Demonstrates the Controller pattern, acting as a thin layer that delegates requests to the service layer for business logic execution. ```typescript export class ExampleController { constructor(private readonly exampleService: ExampleService) {} public async createExample(instance: InstanceDto, data: ExampleDto) { return this.exampleService.create(instance, data); } } ``` -------------------------------- ### Testing Strategy Example Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Illustrates a basic test structure using Jest, including mocking dependencies and asserting behavior for a service. ```typescript // Place tests in test/ directory as *.test.ts // Run: npm test (watches test/all.test.ts) describe('ExampleService', () => { it('should create example', async () => { // Mock external dependencies // Test business logic // Assert expected behavior }); }); ``` -------------------------------- ### Docker Deployment Commands Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Commands to pull the Evolution API image and start the services using Docker Compose. Includes a command for manual database migration. ```bash # Pull and start docker pull evoapicloud/evolution-api:latest docker-compose up -d # Manual database migration docker-compose exec evolution-api sh -c "DATABASE_PROVIDER=postgresql npm run db:deploy" ``` -------------------------------- ### Conventional Commits Examples Source: https://github.com/evolution-foundation/evolution-api/blob/main/CONTRIBUTING.md Examples of commit messages following the Conventional Commits specification. ```git feat: add new feature ``` ```git fix: resolve bug in X ``` ```git docs: update README ``` ```git refactor: simplify Y ``` ```git test: add coverage for Z ``` -------------------------------- ### Get Current Instance Settings Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves the current configuration settings for the WhatsApp instance. This endpoint provides a snapshot of all configurable behaviors. ```bash curl -s http://localhost:8080/settings/find/my-bot \ -H "apikey: YOUR_INSTANCE_TOKEN" ``` -------------------------------- ### Connect / refresh QR code for an instance Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Call this endpoint to get a fresh QR code (base64 PNG) for scanning if the instance is not yet connected or the previous QR code has expired. Requires the instance name. ```bash curl -s http://localhost:8080/instance/connect/my-bot \ -H "apikey: YOUR_GLOBAL_API_KEY" ``` ```json { "pairingCode": null, "code": "2@XXXXXXXX...", "base64": "data:image/png;base64,iVBORw0KGgo..." } ``` -------------------------------- ### Get Current Webhook Configuration Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves the current webhook configuration for a given instance. Requires your instance token. ```bash curl -s http://localhost:8080/webhook/find/my-bot \ -H "apikey: YOUR_INSTANCE_TOKEN" ``` -------------------------------- ### Client-side Socket.io Connection for WebSocket Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Example of connecting to the WebSocket endpoint using Socket.io and handling incoming events like new messages and connection updates. ```javascript // Client-side Socket.io connection import { io } from 'socket.io-client'; const socket = io('http://localhost:8080/my-bot', { extraHeaders: { apikey: 'YOUR_INSTANCE_TOKEN' }, }); socket.on('messages.upsert', (data) => { console.log('New message:', data.data.message); }); socket.on('connection.update', (data) => { console.log('Connection state:', data.data.state); if (data.data.qrcode) { console.log('Scan QR:', data.data.qrcode.base64); } }); ``` -------------------------------- ### Docker Compose for Evolution API Production Setup Source: https://context7.com/evolution-foundation/evolution-api/llms.txt This minimal Docker Compose configuration sets up Evolution API with PostgreSQL and Redis for production. Ensure you replace placeholder credentials with your actual secure keys and URIs. ```yaml version: '3.8' services: evolution-api: image: evoapicloud/evolution-api:latest ports: - "8080:8080" environment: SERVER_URL: http://localhost:8080 AUTHENTICATION_API_KEY: your_secure_global_api_key DATABASE_PROVIDER: postgresql DATABASE_CONNECTION_URI: postgresql://user:pass@postgres:5432/evolution?schema=public REDIS_ENABLED: true CACHE_REDIS_URI: redis://redis:6379 depends_on: - postgres - redis postgres: image: postgres:16 environment: POSTGRES_DB: evolution POSTGRES_USER: user POSTGRES_PASSWORD: pass redis: image: redis:7-alpine ``` -------------------------------- ### Service Layer Pattern Example Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Illustrates the Service Layer pattern, where business logic is encapsulated. Includes dependency injection for services like WAMonitoringService and logging. ```typescript export class ExampleService { constructor(private readonly waMonitor: WAMonitoringService) {} private readonly logger = new Logger('ExampleService'); public async create(instance: InstanceDto, data: ExampleDto) { // Business logic here return { example: { ...instance, data } }; } public async find(instance: InstanceDto): Promise { try { const result = await this.waMonitor.waInstances[instance.instanceName].findData(); return result || null; // Return null on not found (Evolution pattern) } catch (error) { this.logger.error('Error finding data:', error); return null; // Return null on error (Evolution pattern) } } } ``` -------------------------------- ### Get Presigned URL for S3/MinIO Media Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Generates a time-limited presigned URL to directly access a media file stored in S3/MinIO using its ID. ```bash curl -s -X POST http://localhost:8080/s3/getMediaUrl/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "id": "BAE5E90A1C2D1234" }' ``` -------------------------------- ### Send a WhatsApp Business template message Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sends an approved Meta Business template (Cloud API only) with dynamic variable substitution. Ensure the 'name', 'language', and 'components' match your template setup. ```bash curl -s -X POST http://localhost:8080/message/sendTemplate/my-cloud-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "number": "5511999999999", "name": "order_confirmation", "language": "pt_BR", "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "John Doe" }, { "type": "text", "text": "#12345" }, { "type": "currency", "currency": { "fallback_value": "R$ 99,90", "code": "BRL", "amount_1000": 99900 } } ] } ] }' ``` -------------------------------- ### Webhook Payload Example (MESSAGES_UPSERT) Source: https://context7.com/evolution-foundation/evolution-api/llms.txt An example of the JSON payload received when a 'messages.upsert' event occurs. ```json { "event": "messages.upsert", "instance": "my-bot", "data": { "key": { "remoteJid": "5511999999999@s.whatsapp.net", "fromMe": false, "id": "BAE5E90A1C2D1234" }, "pushName": "John Doe", "message": { "conversation": "Hello, I need help!" }, "messageType": "conversation", "messageTimestamp": 1703001234, "instanceId": "abc123", "source": "android" }, "destination": "https://my-server.com/webhook", "date_time": "2024-12-19T15:00:34.000Z", "sender": "5511999999999@s.whatsapp.net", "server_url": "http://localhost:8080", "apikey": "INSTANCE_API_KEY" } ``` -------------------------------- ### Build and Run Production Application Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Commands to build the production-ready application and then run it. ```bash npm run build npm run start:prod ``` -------------------------------- ### Open Prisma Studio Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Launches Prisma Studio, a GUI tool for managing your database content. ```bash npm run db:studio ``` -------------------------------- ### Deploy Database Migrations (Production) Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Applies database migrations to the production environment. Use the appropriate command for your operating system. ```bash npm run db:deploy # Unix/Mac ``` ```bash npm run db:deploy:win # Windows ``` -------------------------------- ### Create a new WhatsApp instance (Meta Cloud API) Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Use this endpoint to create and register a new WhatsApp connection slot for Meta Cloud API. Requires phone number, access token, and business ID. ```bash curl -s -X POST http://localhost:8080/instance/create \ -H "Content-Type: application/json" \ -H "apikey: YOUR_GLOBAL_API_KEY" \ -d '{ "instanceName": "my-cloud-bot", "integration": "WHATSAPP-BUSINESS", "number": "5511999999999", "token": "META_ACCESS_TOKEN", "businessId": "META_BUSINESS_ID" }' ``` -------------------------------- ### Get Group Participants Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves the list of participants for a specific WhatsApp group. ```APIDOC ## GET /group/participants/{instanceName} — Get group participants ### Description Retrieves the participants of a specified group. ### Method GET ### Endpoint /group/participants/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance. #### Query Parameters - **groupJid** (string) - Required - The unique identifier of the group (e.g., '120363123456789@g.us'). ``` -------------------------------- ### Run Development Migrations Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Applies development database migrations and synchronizes them with the provider folder. Use the appropriate command for your operating system. ```bash npm run db:migrate:dev # Unix/Mac ``` ```bash npm run db:migrate:dev:win # Windows ``` -------------------------------- ### Get current webhook configuration Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves the current webhook configuration for a given instance. ```APIDOC ## GET /webhook/find/{instanceName} ### Description Gets the current webhook configuration for a given instance. ### Method GET ### Endpoint /webhook/find/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance to retrieve the configuration for. ### Response #### Success Response (200) - **configuration** (object) - The current webhook configuration. ``` -------------------------------- ### Set Proxy for Instance Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Configures a proxy server for all WhatsApp traffic originating from the instance. Requires `enabled` status, `host`, `port`, `protocol`, and optionally `username` and `password`. ```bash curl -s -X POST http://localhost:8080/proxy/set/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "enabled": true, "host": "proxy.example.com", "port": "8080", "protocol": "http", "username": "proxyuser", "password": "proxypass" }' ``` -------------------------------- ### Get Group Invite Link Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Generates or retrieves the invite link for a specific WhatsApp group. ```APIDOC ## GET /group/inviteCode/{instanceName} — Get group invite link ### Description Retrieves the invite link for a specified group. ### Method GET ### Endpoint /group/inviteCode/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance. #### Query Parameters - **groupJid** (string) - Required - The unique identifier of the group. ### Response #### Success Response (200) - **inviteCode** (string) - The invite code for the group. - **inviteUrl** (string) - The full URL to join the group. ``` -------------------------------- ### Get Group Participants Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves the list of participants for a specific WhatsApp group, identified by its `groupJid`. ```bash curl -s "http://localhost:8080/group/participants/my-bot?groupJid=120363123456789@g.us" \ -H "apikey: YOUR_INSTANCE_TOKEN" ``` -------------------------------- ### RouterBroker Pattern Example Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Extends RouterBroker to handle POST requests with data validation and controller execution. ```typescript export class ExampleRouter extends RouterBroker { constructor(...guards: any[]) { super(); this.router.post(this.routerPath('create'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: exampleSchema, // JSONSchema7 ClassRef: ExampleDto, execute: (instance, data) => controller.createExample(instance, data), }); res.status(201).json(response); }); } } ``` -------------------------------- ### Run Development Server Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Use this command to run the server in development mode with hot reloading enabled. ```bash npm run dev:server ``` -------------------------------- ### List All Instances Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Fetches all registered instances visible to the authenticated API key. A global key returns all; an instance key returns only its own. ```APIDOC ## GET /instance/fetchInstances — List all instances ### Description Fetches all registered instances visible to the authenticated API key. A global key returns all; an instance key returns only its own. ### Method GET ### Endpoint /instance/fetchInstances ### Parameters #### Query Parameters - **instanceName** (string) - Optional - Filter instances by name. ### Request Example ```bash curl -s "http://localhost:8080/instance/fetchInstances?instanceName=my-bot" \ -H "apikey: YOUR_GLOBAL_API_KEY" ``` ### Response #### Success Response (200) - An array of instance objects. - **instance** (object) - Details of an instance. - **instanceName** (string) - The name of the instance. - **instanceId** (string) - The unique ID of the instance. - **owner** (string) - The owner's phone number. - **profileName** (string) - The profile name. - **profilePictureUrl** (string) - URL to the profile picture. - **profileStatus** (string) - The profile status message. - **status** (string) - The current connection status. - **serverUrl** (string) - The API server URL. - **apikey** (string) - The instance-specific API key. - **integration** (string) - The integration type. #### Response Example ```json [ { "instance": { "instanceName": "my-bot", "instanceId": "abc123", "owner": "5511999999999@s.whatsapp.net", "profileName": "My Business", "profilePictureUrl": "https://...", "profileStatus": "Available", "status": "open", "serverUrl": "http://localhost:8080", "apikey": "INSTANCE_API_KEY", "integration": "WHATSAPP-BAILEYS" } } ] ``` ``` -------------------------------- ### Running Evolution API with Docker Source: https://github.com/evolution-foundation/evolution-api/blob/main/README.md Pull the latest Docker image and run the container, mapping the port and providing environment variables. ```bash docker pull evoapicloud/evolution-api:latest docker run -p 8080:8080 --env-file .env evoapicloud/evolution-api:latest ``` -------------------------------- ### Running Evolution API Source: https://github.com/evolution-foundation/evolution-api/blob/main/README.md Commands to run the API in development with hot reload or build and run for production. ```bash # Development with hot reload npm run dev:server # Production build and run npm run build npm run start:prod ``` -------------------------------- ### Get a presigned URL for stored media Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Returns a time-limited presigned URL to directly access a media file stored in S3/MinIO using its ID. ```APIDOC ## POST /s3/getMediaUrl/{instanceName} ### Description Get a presigned URL for a stored media file in S3/MinIO. ### Method POST ### Endpoint /s3/getMediaUrl/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance. #### Request Body - **id** (string) - Required - The ID of the media file. ``` -------------------------------- ### List all registered instances Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Fetches a list of all instances visible to the authenticated API key. A global key returns all instances, while an instance key returns only its own. Supports filtering by instance name. ```bash curl -s "http://localhost:8080/instance/fetchInstances?instanceName=my-bot" \ -H "apikey: YOUR_GLOBAL_API_KEY" ``` ```json [ { "instance": { "instanceName": "my-bot", "instanceId": "abc123", "owner": "5511999999999@s.whatsapp.net", "profileName": "My Business", "profilePictureUrl": "https://...", "profileStatus": "Available", "status": "open", "serverUrl": "http://localhost:8080", "apikey": "INSTANCE_API_KEY", "integration": "WHATSAPP-BAILEYS" } } ] ``` -------------------------------- ### Environment Configuration Reference Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Reference for environment variables used to configure the Evolution API server, database connections, caching, message queues, and storage. ```bash # Core server SERVER_NAME=evolution SERVER_PORT=8080 SERVER_URL=https://api.mycompany.com AUTHENTICATION_API_KEY=your_global_api_key_here # Database (postgresql | mysql | psql_bouncer) DATABASE_PROVIDER=postgresql DATABASE_CONNECTION_URI=postgresql://user:pass@localhost:5432/evolution?schema=public DATABASE_SAVE_DATA_NEW_MESSAGE=true DATABASE_SAVE_DATA_CONTACTS=true DATABASE_SAVE_DATA_CHATS=true # Redis cache REDIS_ENABLED=true CACHE_REDIS_URI=redis://localhost:6379 CACHE_REDIS_PREFIX_KEY=evolution CACHE_REDIS_TTL=604800 # RabbitMQ RABBITMQ_ENABLED=false RABBITMQ_URI=amqp://localhost RABBITMQ_EXCHANGE_NAME=evolution # Kafka KAFKA_ENABLED=false KAFKA_BROKERS=localhost:9092 KAFKA_CLIENT_ID=evolution-api # Storage (S3/MinIO) S3_ENABLED=false S3_ACCESS_KEY_ID=minio_access_key S3_SECRET_ACCESS_KEY=minio_secret_key S3_BUCKET=evolution S3_PORT=9000 S3_ENDPOINT=localhost S3_USE_SSL=false ``` -------------------------------- ### Create WhatsApp Business Message Template Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Use this endpoint to create a new message template for WhatsApp. Ensure the template adheres to WhatsApp's policies and includes all necessary components like header, body, and footer. ```bash curl -s -X POST http://localhost:8080/template/create/my-cloud-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "name": "order_confirmation", "category": "UTILITY", "language": "pt_BR", "components": [ { "type": "HEADER", "format": "TEXT", "text": "Order Confirmed ✅" }, { "type": "BODY", "text": "Hi {{1}}, your order {{2}} totaling {{3}} has been confirmed!", "example": { "body_text": [["John", "#12345", "R$ 99,90"]] }, { "type": "FOOTER", "text": "Thank you for shopping with us" } ] }' ``` -------------------------------- ### Get Group Invite Link Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Generates or retrieves the invite link for a specified WhatsApp group using its `groupJid`. The response contains the invite code and the full invite URL. ```bash curl -s "http://localhost:8080/group/inviteCode/my-bot?groupJid=120363123456789@g.us" \ -H "apikey: YOUR_INSTANCE_TOKEN" # Response { "inviteCode": "ABCDEF123456", "inviteUrl": "https://chat.whatsapp.com/ABCDEF123456" } ``` -------------------------------- ### List Available OpenAI Models Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves a list of available OpenAI models for the specified instance, requiring OpenAI credentials. ```bash curl -s "http://localhost:8080/openai/getModels/my-bot?openaiCredsId=creds_abc123" \ -H "apikey: YOUR_INSTANCE_TOKEN" ``` -------------------------------- ### Configure RabbitMQ event forwarding Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sets up event forwarding to a RabbitMQ exchange. ```APIDOC ## POST /rabbitmq/set/{instanceName} ### Description Configures RabbitMQ event forwarding for a specified instance. ### Method POST ### Endpoint /rabbitmq/set/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance to configure. #### Request Body - **enabled** (boolean) - Required - Whether to enable RabbitMQ forwarding. - **events** (array) - Required - A list of event types to forward to RabbitMQ. ### Request Example ```json { "enabled": true, "events": [ "MESSAGES_UPSERT", "CONNECTION_UPDATE", "SEND_MESSAGE" ] } ``` ### Notes Messages are published to queues named: `evolution.{instanceName}.{EVENT_TYPE}`. In global mode, messages are published to: `evolution.{EVENT_TYPE}`. ``` -------------------------------- ### Configure Instance Behaviour Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sets various configuration options for the instance's behavior. ```APIDOC ## POST /settings/set/{instanceName} — Configure instance behaviour ### Description Allows configuration of various instance settings to control its behavior. ### Method POST ### Endpoint /settings/set/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance to configure. #### Request Body - **rejectCall** (boolean) - Optional - If true, the instance will reject incoming calls. - **msgCall** (string) - Optional - A message to send when a call is rejected. - **groupsIgnore** (boolean) - Optional - If true, the instance will ignore messages from groups. - **alwaysOnline** (boolean) - Optional - If true, the instance will appear online constantly. - **readMessages** (boolean) - Optional - If true, the instance will automatically read incoming messages. - **readStatus** (boolean) - Optional - If true, the instance will automatically read status updates. - **syncFullHistory** (boolean) - Optional - If true, the instance will attempt to sync the full message history. ``` -------------------------------- ### Set Proxy Configuration Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Configures a proxy server for the instance to route its WhatsApp traffic through. ```APIDOC ## POST /proxy/set/{instanceName} — Set a proxy for the instance ### Description Configures the proxy settings for the instance, routing all WhatsApp traffic through the specified proxy. ### Method POST ### Endpoint /proxy/set/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance to configure. #### Request Body - **enabled** (boolean) - Required - Whether the proxy is enabled. - **host** (string) - Required - The hostname or IP address of the proxy server. - **port** (string) - Required - The port number of the proxy server. - **protocol** (string) - Required - The protocol to use (e.g., 'http', 'https', 'socks4', 'socks5'). - **username** (string) - Optional - The username for proxy authentication. - **password** (string) - Optional - The password for proxy authentication. ``` -------------------------------- ### Configure Kafka Event Streaming Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Enables and configures Apache Kafka for event streaming. Requires Kafka broker details in the environment. Topic names follow the pattern 'evolution.instanceName.event-name'. ```bash curl -s -X POST http://localhost:8080/kafka/set/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "enabled": true, "events": ["MESSAGES_UPSERT", "MESSAGES_UPDATE", "CONNECTION_UPDATE"] }' # Requires KAFKA_ENABLED=true, KAFKA_BROKERS=localhost:9092 in .env # Topic name pattern: evolution.my-bot.messages-upsert ``` -------------------------------- ### Create a new WhatsApp instance (Baileys) Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Use this endpoint to create and register a new WhatsApp connection slot for Baileys. The response includes a QR code for pairing. ```bash curl -s -X POST http://localhost:8080/instance/create \ -H "Content-Type: application/json" \ -H "apikey: YOUR_GLOBAL_API_KEY" \ -d '{ "instanceName": "my-bot", "qrcode": true, "integration": "WHATSAPP-BAILEYS" }' ``` ```json { "instance": { "instanceName": "my-bot", "instanceId": "abc123", "status": "created", "integration": "WHATSAPP-BAILEYS" }, "qrcode": { "pairingCode": null, "code": "2@XXXXXXXX...", "base64": "data:image/png;base64,..." } } ``` -------------------------------- ### Configure SQS event forwarding Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sets up event forwarding to an Amazon SQS queue. ```APIDOC ## POST /sqs/set/{instanceName} ### Description Configures event forwarding to an Amazon SQS queue for a specified instance. ### Method POST ### Endpoint /sqs/set/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance to configure. #### Request Body - **enabled** (boolean) - Required - Whether to enable SQS forwarding. - **events** (array) - Required - A list of event types to forward to SQS. ### Request Example ```json { "enabled": true, "events": ["MESSAGES_UPSERT", "SEND_MESSAGE", "CONNECTION_UPDATE"] } ``` ### Notes Requires `SQS_ACCESS_KEY_ID`, `SQS_SECRET_ACCESS_KEY`, `SQS_ACCOUNT_ID`, `SQS_REGION` environment variables to be set. The queue name follows the pattern: `evolution_{instanceName}_{EVENT_TYPE}`. ``` -------------------------------- ### Configure Instance Behavior Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sets various instance behaviors such as call rejection, message for calls, ignoring groups, always online status, read messages, read status, and history sync. Set boolean values to `true` or `false`. ```bash curl -s -X POST http://localhost:8080/settings/set/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "rejectCall": true, "msgCall": "Sorry, I cannot take calls. Please send a message.", "groupsIgnore": false, "alwaysOnline": false, "readMessages": false, "readStatus": false, "syncFullHistory": false }' ``` -------------------------------- ### Connect to Chatwoot Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Connects the WhatsApp instance to a Chatwoot inbox for seamless human-agent handoff. Requires Chatwoot account details and user token. ```bash curl -s -X POST http://localhost:8080/chatwoot/set/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "enabled": true, "accountId": "1", "token": "CHATWOOT_USER_ACCESS_TOKEN", "url": "https://app.chatwoot.com", "signMsg": true, "reopenConversation": true, "conversationPending": false, "importContacts": true, "nameInbox": "WhatsApp - My Bot", "mergeBrazilContacts": true, "importMessages": true, "daysLimitImportMessages": 7, "autoCreate": false }' ``` -------------------------------- ### List All Labels Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Fetches a list of all labels associated with the WhatsApp instance. This endpoint requires only the instance name and the API key. ```bash curl -s http://localhost:8080/label/findLabels/my-bot \ -H "apikey: YOUR_INSTANCE_TOKEN" ``` -------------------------------- ### Configure Webhook Destination Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sets the URL and event types to forward to an external HTTP endpoint. Ensure 'apikey' is replaced with your actual instance token. ```bash curl -s -X POST http://localhost:8080/webhook/set/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "enabled": true, "url": "https://my-server.com/webhook", "webhookByEvents": false, "webhookBase64": false, "headers": { "Authorization": "Bearer my-secret" }, "events": [ "MESSAGES_UPSERT", "MESSAGES_UPDATE", "MESSAGES_DELETE", "SEND_MESSAGE", "CONNECTION_UPDATE", "QRCODE_UPDATED", "CONTACTS_UPSERT", "GROUPS_UPSERT" ] }' ``` -------------------------------- ### Create an OpenAI chatbot Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Connects an OpenAI assistant to the instance for automated AI-powered responses. Configures various parameters for the chatbot's behavior. ```APIDOC ## POST /openai/create/{instanceName} ### Description Create an OpenAI chatbot for the specified instance, enabling automated AI-powered responses. ### Method POST ### Endpoint /openai/create/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance. #### Request Body - **enabled** (boolean) - Required - Whether the OpenAI integration is enabled. - **openaiCredsId** (string) - Required - The ID of the registered OpenAI credentials. - **botType** (string) - Optional - The type of bot (e.g., "assistant"). - **assistantId** (string) - Optional - The ID of the OpenAI assistant. - **functionUrl** (string) - Optional - URL for custom functions. - **model** (string) - Optional - The OpenAI model to use (e.g., "gpt-4o"). - **systemMessages** (string) - Optional - System-level messages for the assistant. - **assistantMessages** (string) - Optional - Assistant-specific messages. - **userMessages** (string) - Optional - User-specific messages. - **maxTokens** (integer) - Optional - Maximum number of tokens for the response. - **triggerType** (string) - Optional - Type of trigger for the bot (e.g., "all"). - **triggerOperator** (string) - Optional - Operator for the trigger (e.g., "contains"). - **triggerValue** (string) - Optional - Value for the trigger. - **expire** (integer) - Optional - Session expiration time in seconds. - **keywordFinish** (string) - Optional - Keyword to finish the session. - **delayMessage** (integer) - Optional - Delay between messages in milliseconds. - **unknownMessage** (string) - Optional - Message to send when input is not recognized. - **listeningFromMe** (boolean) - Optional - Whether to listen to messages sent from the instance. - **stopBotFromMe** (boolean) - Optional - Whether to stop the bot from messages sent from the instance. - **keepOpen** (boolean) - Optional - Whether to keep the session open. - **debounceTime** (integer) - Optional - Debounce time in milliseconds. - **splitMessages** (boolean) - Optional - Whether to split messages. - **timePerChar** (integer) - Optional - Time per character in milliseconds. ``` -------------------------------- ### Generate Prisma Client Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Generates the Prisma client based on the current database schema and the configured DATABASE_PROVIDER environment variable. ```bash npm run db:generate ``` -------------------------------- ### Set Database Provider Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Configures the database provider for Prisma. Supports 'postgresql' or 'mysql'. ```bash export DATABASE_PROVIDER=postgresql # or mysql ``` -------------------------------- ### Create a WhatsApp Group Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Creates a new WhatsApp group with a specified subject, description, and initial participants. The response includes the group's JID and subject. ```bash curl -s -X POST http://localhost:8080/group/create/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "subject": "Project Alpha Team", "description": "Internal coordination group", "participants": [ "5511888888888@s.whatsapp.net", "5511777777777@s.whatsapp.net" ] }' # Response { "groupJid": "120363123456789@g.us", "subject": "Project Alpha Team", "participants": [...] } ``` -------------------------------- ### Build for Production Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Executes TypeScript checks and builds the project for production using tsup. ```bash npm run build ``` -------------------------------- ### Run Tests Source: https://github.com/evolution-foundation/evolution-api/blob/main/CLAUDE.md Executes all defined tests for the project, with watch mode enabled for continuous testing during development. ```bash npm test ``` -------------------------------- ### Retrieve Stored Media from S3/MinIO Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Fetches a media file stored in S3/MinIO using its ID and returns the file buffer. Optionally converts the media to MP4. ```bash curl -s -X POST http://localhost:8080/s3/getMedia/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "id": "BAE5E90A1C2D1234", "convertToMp4": false }' ``` -------------------------------- ### Configure Kafka event streaming Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sets up event streaming to an Apache Kafka topic. ```APIDOC ## POST /kafka/set/{instanceName} ### Description Configures event streaming to an Apache Kafka topic for a specified instance. ### Method POST ### Endpoint /kafka/set/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance to configure. #### Request Body - **enabled** (boolean) - Required - Whether to enable Kafka streaming. - **events** (array) - Required - A list of event types to stream to Kafka. ### Request Example ```json { "enabled": true, "events": ["MESSAGES_UPSERT", "MESSAGES_UPDATE", "CONNECTION_UPDATE"] } ``` ### Notes Requires `KAFKA_ENABLED=true` and `KAFKA_BROKERS=localhost:9092` to be set in the environment. The topic name follows the pattern: `evolution.{instanceName}.{event-name-in-kebab-case}`. ``` -------------------------------- ### Prisma Repository Pattern Usage Source: https://github.com/evolution-foundation/evolution-api/blob/main/AGENTS.md Demonstrates the use of PrismaRepository for database operations, specifically finding a unique instance by name. ```typescript // Always use PrismaRepository for database operations const result = await this.prismaRepository.instance.findUnique({ where: { name: instanceName }, }); ``` -------------------------------- ### Create OpenAI Chatbot Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Creates and configures an OpenAI chatbot assistant for automated responses, including model selection and system messages. ```bash curl -s -X POST http://localhost:8080/openai/create/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "enabled": true, "openaiCredsId": "creds_abc123", "botType": "assistant", "assistantId": "asst_XXXXXXXXXXXX", "functionUrl": "https://my-server.com/functions", "model": "gpt-4o", "systemMessages": "You are a helpful customer support agent for ACME Corp.", "assistantMessages": "", "userMessages": "", "maxTokens": 300, "triggerType": "all", "triggerOperator": "contains", "triggerValue": "", "expire": 30, "keywordFinish": "#human", "delayMessage": 1000, "unknownMessage": "I could not understand that.", "listeningFromMe": false, "stopBotFromMe": true, "keepOpen": false, "debounceTime": 10, "splitMessages": true, "timePerChar": 50 }' ``` -------------------------------- ### Configure Chatwoot Webhook Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sets up a webhook URL in Chatwoot to receive agent replies and conversation status updates back to WhatsApp. This URL should be configured in Chatwoot's webhook settings. ```bash # Set in Chatwoot webhook settings: # URL: http://localhost:8080/chatwoot/webhook/my-bot # Events: conversation_status_changed, message_created ``` -------------------------------- ### Update Instance Profile Name Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Updates the profile name for the WhatsApp instance. Requires the new name as a string. ```bash curl -s -X POST http://localhost:8080/chat/updateProfileName/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "name": "My New Business Name" }' ``` -------------------------------- ### Send Media via URL Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sends media (image, video, document, audio) using a URL. Requires specifying the media type, MIME type, and optionally a caption and filename. ```bash # Send via URL curl -s -X POST http://localhost:8080/message/sendMedia/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "number": "5511999999999", "mediatype": "image", "mimetype": "image/jpeg", "caption": "Check this out!", "media": "https://example.com/photo.jpg", "fileName": "photo.jpg" }' ``` -------------------------------- ### List All Labels Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves a list of all labels created within the instance. ```APIDOC ## GET /label/findLabels/{instanceName} — List all labels ### Description Fetches all available labels for the given instance. ### Method GET ### Endpoint /label/findLabels/{instanceName} ### Parameters #### Path Parameters - **instanceName** (string) - Required - The name of the instance. ``` -------------------------------- ### Enable WebSocket Events Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Enables WebSocket events for a specific instance. This allows real-time event subscriptions. ```bash curl -s -X POST http://localhost:8080/websocket/set/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "enabled": true, "events": ["MESSAGES_UPSERT", "CONNECTION_UPDATE", "QRCODE_UPDATED"] }' ``` -------------------------------- ### List All WhatsApp Groups Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Fetches a list of all groups the instance is a part of. The `getParticipants` parameter can be set to `true` to include participants in the response. ```bash curl -s "http://localhost:8080/group/fetchAllGroups/my-bot?getParticipants=false" \ -H "apikey: YOUR_INSTANCE_TOKEN" ``` -------------------------------- ### Check the connection state of an instance Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Retrieves the current connection state of a Baileys/WhatsApp instance. Possible states are 'open', 'connecting', or 'close'. Requires the instance token. ```bash curl -s http://localhost:8080/instance/connectionState/my-bot \ -H "apikey: YOUR_INSTANCE_TOKEN" ``` ```json { "instance": { "instanceName": "my-bot", "state": "open" } } ``` -------------------------------- ### Configure RabbitMQ Event Forwarding Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Enables and configures RabbitMQ for event forwarding. Messages are published to queues named 'evolution.instanceName.EVENT_TYPE'. ```bash curl -s -X POST http://localhost:8080/rabbitmq/set/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "enabled": true, "events": [ "MESSAGES_UPSERT", "CONNECTION_UPDATE", "SEND_MESSAGE" ] }' # Messages are published to queues named: evolution.my-bot.MESSAGES_UPSERT # Global mode publishes to: evolution.MESSAGES_UPSERT ``` -------------------------------- ### Send a message with reply buttons Source: https://context7.com/evolution-foundation/evolution-api/llms.txt Sends a message with up to 3 quick-reply buttons. Each button requires a 'type', 'displayText', and 'id'. ```bash curl -s -X POST http://localhost:8080/message/sendButtons/my-bot \ -H "Content-Type: application/json" \ -H "apikey: YOUR_INSTANCE_TOKEN" \ -d '{ "number": "5511999999999", "title": "Confirm your order", "description": "Order #12345 — Total: R$ 99,90", "footer": "Tap to respond", "buttons": [ { "type": "reply", "displayText": "✅ Confirm", "id": "confirm_order" }, { "type": "reply", "displayText": "❌ Cancel", "id": "cancel_order" } ] }' ```