# documentation: https://doc.evolution-api.com/v1/pt/get-started/introduction
# slogan: Evolution API Installation with Postgres and Redis
# tags: evolution-api,evo-api,evolution,whatsapp,api,postgres,redis
# logo: svgs/evolution-api.svg
# port: 8080

version: '3.8'
services:
  api:
    image: 'atendai/evolution-api:latest' # Change to specific version if needed.
    restart: always
    depends_on:
      - redis
      - postgres
    environment:
      - SERVICE_FQDN_EVO_8080
      - SERVER_URL=$SERVICE_FQDN_EVO
      - DB_TYPE=${DB_TYPE:-postgresdb}
      - 'DB_POSTGRESDB_DATABASE=${POSTGRES_DB:-postgres}'
      - DB_POSTGRESDB_HOST=${DB_POSTGRESDB_HOST:-postgres}
      - DB_POSTGRESDB_PORT=${DB_POSTGRESDB_PORT:-5432}
      - 'DB_POSTGRESDB_USER=${SERVICE_USER_POSTGRES}'
      - 'DB_POSTGRESDB_PASSWORD=${SERVICE_PASSWORD_POSTGRES}'
      - DATABASE_PROVIDER=${DATABASE_PROVIDER:-postgresql}
      - 'DATABASE_URL=postgresql://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@postgres:5432/${POSTGRES_DB:-postgres}'
      - 'DATABASE_CONNECTION_URI=postgresql://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@postgres:5432/${POSTGRES_DB:-postgres}'
      - DEL_INSTANCE=${DEL_INSTANCE:-false}
      - DATABASE_SAVE_DATA_INSTANCE=${DATABASE_SAVE_DATA_INSTANCE:-true}
      - DATABASE_SAVE_DATA_NEW_MESSAGE=${DATABASE_SAVE_DATA_NEW_MESSAGE:-true}
      - DATABASE_SAVE_MESSAGE_UPDATE=${DATABASE_SAVE_MESSAGE_UPDATE:-true}
      - DATABASE_SAVE_DATA_CONTACTS=${DATABASE_SAVE_DATA_CONTACTS:-true}
      - DATABASE_SAVE_DATA_CHATS=${DATABASE_SAVE_DATA_CHATS:-true}
      - DATABASE_SAVE_DATA_LABELS=${DATABASE_SAVE_DATA_LABELS:-true}
      - DATABASE_SAVE_DATA_HISTORIC=${DATABASE_SAVE_DATA_HISTORIC:-true}
      - DATABASE_CONNECTION_CLIENT_NAME=${DATABASE_CONNECTION_CLIENT_NAME:-evolution_v2}
      - RABBITMQ_ENABLED=${RABBITMQ_ENABLED:-false}
      - 'RABBITMQ_URI=${RABBITMQ_URI:-amqp://admin:admin@rabbitmq:5672/default}'
      - RABBITMQ_EXCHANGE_NAME=${RABBITMQ_EXCHANGE_NAME:-evolution_v2}
      - RABBITMQ_GLOBAL_ENABLED=${RABBITMQ_GLOBAL_ENABLED:-false}
      - RABBITMQ_EVENTS_APPLICATION_STARTUP=${RABBITMQ_EVENTS_APPLICATION_STARTUP:-false}
      - RABBITMQ_EVENTS_INSTANCE_CREATE=${RABBITMQ_EVENTS_INSTANCE_CREATE:-false}
      - RABBITMQ_EVENTS_INSTANCE_DELETE=${RABBITMQ_EVENTS_INSTANCE_DELETE:-false}
      - RABBITMQ_EVENTS_QRCODE_UPDATED=${RABBITMQ_EVENTS_QRCODE_UPDATED:-false}
      - RABBITMQ_EVENTS_MESSAGES_SET=${RABBITMQ_EVENTS_MESSAGES_SET:-false}
      - RABBITMQ_EVENTS_MESSAGES_UPSERT=${RABBITMQ_EVENTS_MESSAGES_UPSERT:-true}
      - RABBITMQ_EVENTS_MESSAGES_EDITED=${RABBITMQ_EVENTS_MESSAGES_EDITED:-false}
      - RABBITMQ_EVENTS_MESSAGES_UPDATE=${RABBITMQ_EVENTS_MESSAGES_UPDATE:-false}
      - RABBITMQ_EVENTS_MESSAGES_DELETE=${RABBITMQ_EVENTS_MESSAGES_DELETE:-false}
      - RABBITMQ_EVENTS_SEND_MESSAGE=${RABBITMQ_EVENTS_SEND_MESSAGE:-false}
      - RABBITMQ_EVENTS_CONTACTS_SET=${RABBITMQ_EVENTS_CONTACTS_SET:-false}
      - RABBITMQ_EVENTS_CONTACTS_UPSERT=${RABBITMQ_EVENTS_CONTACTS_UPSERT:-false}
      - RABBITMQ_EVENTS_CONTACTS_UPDATE=${RABBITMQ_EVENTS_CONTACTS_UPDATE:-false}
      - RABBITMQ_EVENTS_PRESENCE_UPDATE=${RABBITMQ_EVENTS_PRESENCE_UPDATE:-false}
      - RABBITMQ_EVENTS_CHATS_SET=${RABBITMQ_EVENTS_CHATS_SET:-false}
      - RABBITMQ_EVENTS_CHATS_UPSERT=${RABBITMQ_EVENTS_CHATS_UPSERT:-false}
      - RABBITMQ_EVENTS_CHATS_UPDATE=${RABBITMQ_EVENTS_CHATS_UPDATE:-false}
      - RABBITMQ_EVENTS_CHATS_DELETE=${RABBITMQ_EVENTS_CHATS_DELETE:-false}
      - RABBITMQ_EVENTS_GROUPS_UPSERT=${RABBITMQ_EVENTS_GROUPS_UPSERT:-false}
      - RABBITMQ_EVENTS_GROUP_UPDATE=${RABBITMQ_EVENTS_GROUP_UPDATE:-false}
      - RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE=${RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE:-false}
      - RABBITMQ_EVENTS_CONNECTION_UPDATE=${RABBITMQ_EVENTS_CONNECTION_UPDATE:-true}
      - RABBITMQ_EVENTS_CALL=${RABBITMQ_EVENTS_CALL:-false}
      - RABBITMQ_EVENTS_TYPEBOT_START=${RABBITMQ_EVENTS_TYPEBOT_START:-false}
      - RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS=${RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS:-false}
      - SQS_ENABLED=${SQS_ENABLED:-false}
      - SQS_ACCESS_KEY_ID=${SQS_ACCESS_KEY_ID:-}
      - SQS_SECRET_ACCESS_KEY=${SQS_SECRET_ACCESS_KEY:-}
      - SQS_ACCOUNT_ID=${SQS_ACCOUNT_ID:-}
      - SQS_REGION=${SQS_REGION:-}
      - WEBSOCKET_ENABLED=${WEBSOCKET_ENABLED:-false}
      - WEBSOCKET_GLOBAL_EVENTS=${WEBSOCKET_GLOBAL_EVENTS:-false}
      - WA_BUSINESS_TOKEN_WEBHOOK=${WA_BUSINESS_TOKEN_WEBHOOK:-evolution}
      - 'WA_BUSINESS_URL=${WA_BUSINESS_URL:-https://graph.facebook.com}'
      - WA_BUSINESS_VERSION=${WA_BUSINESS_VERSION:-v20.0}
      - WA_BUSINESS_LANGUAGE=${WA_BUSINESS_LANGUAGE:-pt_BR}
      - "WEBHOOK_GLOBAL_URL=${WEBHOOK_GLOBAL_URL:-''}"
      - WEBHOOK_GLOBAL_ENABLED=${WEBHOOK_GLOBAL_ENABLED:-false}
      - WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=${WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS:-false}
      - WEBHOOK_EVENTS_APPLICATION_STARTUP=${WEBHOOK_EVENTS_APPLICATION_STARTUP:-false}
      - WEBHOOK_EVENTS_QRCODE_UPDATED=${WEBHOOK_EVENTS_QRCODE_UPDATED:-true}
      - WEBHOOK_EVENTS_MESSAGES_SET=${WEBHOOK_EVENTS_MESSAGES_SET:-true}
      - WEBHOOK_EVENTS_MESSAGES_UPSERT=${WEBHOOK_EVENTS_MESSAGES_UPSERT:-true}
      - WEBHOOK_EVENTS_MESSAGES_EDITED=${WEBHOOK_EVENTS_MESSAGES_EDITED:-true}
      - WEBHOOK_EVENTS_MESSAGES_UPDATE=${WEBHOOK_EVENTS_MESSAGES_UPDATE:-true}
      - WEBHOOK_EVENTS_MESSAGES_DELETE=${WEBHOOK_EVENTS_MESSAGES_DELETE:-true}
      - WEBHOOK_EVENTS_SEND_MESSAGE=${WEBHOOK_EVENTS_SEND_MESSAGE:-true}
      - WEBHOOK_EVENTS_CONTACTS_SET=${WEBHOOK_EVENTS_CONTACTS_SET:-true}
      - WEBHOOK_EVENTS_CONTACTS_UPSERT=${WEBHOOK_EVENTS_CONTACTS_UPSERT:-true}
      - WEBHOOK_EVENTS_CONTACTS_UPDATE=${WEBHOOK_EVENTS_CONTACTS_UPDATE:-true}
      - WEBHOOK_EVENTS_PRESENCE_UPDATE=${WEBHOOK_EVENTS_PRESENCE_UPDATE:-true}
      - WEBHOOK_EVENTS_CHATS_SET=${WEBHOOK_EVENTS_CHATS_SET:-true}
      - WEBHOOK_EVENTS_CHATS_UPSERT=${WEBHOOK_EVENTS_CHATS_UPSERT:-true}
      - WEBHOOK_EVENTS_CHATS_UPDATE=${WEBHOOK_EVENTS_CHATS_UPDATE:-true}
      - WEBHOOK_EVENTS_CHATS_DELETE=${WEBHOOK_EVENTS_CHATS_DELETE:-true}
      - WEBHOOK_EVENTS_GROUPS_UPSERT=${WEBHOOK_EVENTS_GROUPS_UPSERT:-true}
      - WEBHOOK_EVENTS_GROUPS_UPDATE=${WEBHOOK_EVENTS_GROUPS_UPDATE:-true}
      - WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=${WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE:-true}
      - WEBHOOK_EVENTS_CONNECTION_UPDATE=${WEBHOOK_EVENTS_CONNECTION_UPDATE:-true}
      - WEBHOOK_EVENTS_LABELS_EDIT=${WEBHOOK_EVENTS_LABELS_EDIT:-true}
      - WEBHOOK_EVENTS_LABELS_ASSOCIATION=${WEBHOOK_EVENTS_LABELS_ASSOCIATION:-true}
      - WEBHOOK_EVENTS_CALL=${WEBHOOK_EVENTS_CALL:-true}
      - WEBHOOK_EVENTS_TYPEBOT_START=${WEBHOOK_EVENTS_TYPEBOT_START:-false}
      - WEBHOOK_EVENTS_TYPEBOT_CHANGE_STATUS=${WEBHOOK_EVENTS_TYPEBOT_CHANGE_STATUS:-false}
      - WEBHOOK_EVENTS_ERRORS=${WEBHOOK_EVENTS_ERRORS:-false}
      - WEBHOOK_EVENTS_ERRORS_WEBHOOK=${WEBHOOK_EVENTS_ERRORS_WEBHOOK:-}
      - 'CONFIG_SESSION_PHONE_CLIENT=${CONFIG_SESSION_PHONE_CLIENT:-Evolution API V2}'
      - CONFIG_SESSION_PHONE_NAME=${CONFIG_SESSION_PHONE_NAME:-Chrome}
      - CONFIG_SESSION_PHONE_VERSION=${CONFIG_SESSION_PHONE_VERSION:-2.3000.1015901307}
      - QRCODE_LIMIT=${QRCODE_LIMIT:-30}
      - OPENAI_ENABLED=${OPENAI_ENABLED:-true}
      - DIFY_ENABLED=${DIFY_ENABLED:-true}
      - TYPEBOT_ENABLED=${TYPEBOT_ENABLED:-true}
      - TYPEBOT_API_VERSION=${TYPEBOT_API_VERSION:-latest}
      - CHATWOOT_ENABLED=${CHATWOOT_ENABLED:-true}
      - CHATWOOT_MESSAGE_READ=${CHATWOOT_MESSAGE_READ:-true}
      - CHATWOOT_MESSAGE_DELETE=${CHATWOOT_MESSAGE_DELETE:-true}
      - 'CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgresql://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@postgres:5432/${POSTGRES_DB:-chatwoot}'
      - CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE=${CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE:-true}
      - CACHE_REDIS_ENABLED=${CACHE_REDIS_ENABLED:-true}
      - 'CACHE_REDIS_URI=${CACHE_REDIS_URI:-redis://redis:6379/6}'
      - CACHE_REDIS_PREFIX_KEY=${CACHE_REDIS_PREFIX_KEY:-evolution_v2}
      - CACHE_REDIS_SAVE_INSTANCES=${CACHE_REDIS_SAVE_INSTANCES:-false}
      - CACHE_LOCAL_ENABLED=${CACHE_LOCAL_ENABLED:-false}
      - S3_ENABLED=${S3_ENABLED:-false}
      - S3_ACCESS_KEY=${S3_ACCESS_KEY:-}
      - S3_SECRET_KEY=${S3_SECRET_KEY:-}
      - S3_BUCKET=${S3_BUCKET:-evolution}
      - S3_PORT=${S3_PORT:-443}
      - S3_ENDPOINT=${S3_ENDPOINT:-files.site.com}
      - S3_USE_SSL=${S3_USE_SSL:-true}
      - 'AUTHENTICATION_API_KEY=${SERVICE_PASSWORD_AUTHENTICATIONAPIKEY}'
      - AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=${AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES:-true}
      - LANGUAGE=${LANGUAGE:-en}
    volumes:
      - 'evolution_instances:/evolution/instances'
    expose:
      - 8080
  redis:
    image: 'redis:latest'
    command: "redis-server --port 6379 --appendonly yes\n"
    restart: always
    volumes:
      - 'evolution_redis:/data'
  postgres:
    image: 'postgres:16-alpine'
    command:
      - postgres
      - '-c'
      - max_connections=1000
    environment:
      - 'POSTGRES_USER=${SERVICE_USER_POSTGRES}'
      - 'POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRES}'
      - 'POSTGRES_DB=${POSTGRES_DB:-postgres}'
      - 'AUTHENTICATION_API_KEY=${SERVICE_PASSWORD_AUTHENTICATIONAPIKEY}'
    restart: always
    volumes:
      - 'postgres_data:/var/lib/postgresql/data'
volumes:
  evolution_instances: null
  evolution_redis: null
  postgres_data: null
