diff --git a/.gitignore b/.gitignore index c2586448..18b4b05c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ yarn-debug.log* yarn-error.log* lerna-debug.log* +/store/* + # Package /yarn.lock /package-lock.json diff --git a/Dockerfile b/Dockerfile index fd34317b..74ac6c89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,9 @@ COPY ./package.json . ENV DOCKER_ENV=true +ENV SERVER_TYPE="http" +ENV SERVER_PORT=8083 + ENV CORS_ORIGIN="*" ENV CORS_METHODS="POST,GET,PUT,DELETE" ENV CORS_CREDENTIALS=true @@ -16,12 +19,12 @@ ENV CORS_CREDENTIALS=true ENV LOG_LEVEL="ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK" ENV LOG_COLOR=true -ENV DEL_INSTANCE=false +ENV DEL_INSTANCE=$DEL_INSTANCE -ENV STORE_CLEANING_INTERVAL=7200 -ENV STORE_MESSAGE=true -ENV STORE_CONTACTS=true -ENV STORE_CHATS=true +ENV STORE_CLEANING_INTERVAL=$STORE_CLEANING_INTERVAL +ENV STORE_MESSAGE=$STORE_MESSAGE +ENV STORE_CONTACTS=$STORE_CONTACTS +ENV STORE_CHATS=$STORE_CHATS ENV DATABASE_ENABLED=$DATABASE_ENABLED ENV DATABASE_CONNECTION_URI=$DATABASE_CONNECTION_URI @@ -37,7 +40,7 @@ ENV REDIS_ENABLED=$REDIS_ENABLED ENV REDIS_URI=$REDIS_URI ENV WEBHOOK_GLOBAL_URL=$WEBHOOK_GLOBAL_URL -ENV WEBHOOK_GLOBAL_ENABLED=true +ENV WEBHOOK_GLOBAL_ENABLED=$WEBHOOK_GLOBAL_ENABLED ENV WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=$WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS ENV WEBHOOK_EVENTS_STATUS_INSTANCE=$WEBHOOK_EVENTS_STATUS_INSTANCE @@ -59,19 +62,19 @@ ENV WEBHOOK_EVENTS_GROUPS_UPSERT=$WEBHOOK_EVENTS_GROUPS_UPSERT ENV WEBHOOK_EVENTS_GROUPS_UPDATE=$WEBHOOK_EVENTS_GROUPS_UPDATE ENV WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=$WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE -ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=true +ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=$WEBHOOK_EVENTS_NEW_JWT_TOKEN -ENV CONFIG_SESSION_PHONE_CLIENT="Evolution API" -ENV CONFIG_SESSION_PHONE_NAME="Chrome" +ENV CONFIG_SESSION_PHONE_CLIENT=$CONFIG_SESSION_PHONE_CLIENT +ENV CONFIG_SESSION_PHONE_NAME=$CONFIG_SESSION_PHONE_NAME -ENV QRCODE_LIMIT=30 +ENV QRCODE_LIMIT=$QRCODE_LIMIT -ENV AUTHENTICATION_TYPE="apikey" +ENV AUTHENTICATION_TYPE=$AUTHENTICATION_TYPE ENV AUTHENTICATION_API_KEY=$AUTHENTICATION_API_KEY -ENV AUTHENTICATION_JWT_EXPIRIN_IN=0 -ENV AUTHENTICATION_JWT_SECRET="L0YWtjb2w554WFqPG" +ENV AUTHENTICATION_JWT_EXPIRIN_IN=$AUTHENTICATION_JWT_EXPIRIN_IN +ENV AUTHENTICATION_JWT_SECRET="L=0YWt]b2w[WF>#>:&E`" ENV AUTHENTICATION_INSTANCE_NAME=$AUTHENTICATION_INSTANCE_NAME ENV AUTHENTICATION_INSTANCE_WEBHOOK_URL=$AUTHENTICATION_INSTANCE_WEBHOOK_URL diff --git a/docker-compose.yaml b/docker-compose.yaml index f2639ec8..87f3e81b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,14 +5,120 @@ networks: driver: bridge services: - base: + api: container_name: evolution_api - image: davidsongomes/evolution-api:latest + # image: davidsongomes/evolution-api:latest + build: + context: . + dockerfile: Dockerfile ports: - 8080:8080 - volumes: - - /data/instances:/evolution/instances + # volumes: + # - /data/instances:/evolution/instances + environment: + # Determine how long the instance should be deleted from memory in case of no connection. + # Default time: 5 minutes + # If you don't even want an expiration, enter the value false + - DEL_INSTANCE=5 # or false + # Temporary data storage + - STORE_CLEANING_INTERVAL=7200 # seconds === 2h + - STORE_MESSAGE=true + - STORE_CONTACTS=true + - STORE_CHATS=true + # Permanent data storage + - DATABASE_ENABLED=false + - DATABASE_CONNECTION_URI=mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true + - DATABASE_CONNECTION_DB_PREFIX_NAME=evolution + # Choose the data you want to save in the application's database or store + - DATABASE_SAVE_DATA_INSTANCE=false + - DATABASE_SAVE_DATA_OLD_MESSAGE=false + - DATABASE_SAVE_DATA_NEW_MESSAGE=true + - DATABASE_SAVE_MESSAGE_UPDATE=false + - DATABASE_SAVE_DATA_CONTACTS=true + - DATABASE_SAVE_DATA_CHATS=true + - REDIS_ENABLED=false + - REDIS_URI=redis://localhost:6379 + - REDIS_PREFIX_KEY=evolution + # Webhook Settings + # Define a global webhook that will listen for enabled events from all instances + - WEBHOOK_GLOBAL_URL=https://webhooks.n8n.evolution-api.com/webhook/0e66d93a-1671-474f-a07f-3f44b581d320 + - WEBHOOK_GLOBAL_ENABLED=false + # With this option activated, you work with a url per webhook event, respecting the global url and the name of each event + - WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false + # Automatically maps webhook paths + # Set the events you want to hear + - WEBHOOK_EVENTS_STATUS_INSTANCE=true + - WEBHOOK_EVENTS_APPLICATION_STARTUP=true + - WEBHOOK_EVENTS_QRCODE_UPDATED=true + - WEBHOOK_EVENTS_MESSAGES_SET=true + - WEBHOOK_EVENTS_MESSAGES_UPDATE=true + - WEBHOOK_EVENTS_MESSAGES_UPSERT=true + - WEBHOOK_EVENTS_SEND_MESSAGE=true + - WEBHOOK_EVENTS_CONTACTS_SET=true + - WEBHOOK_EVENTS_CONTACTS_UPSERT=true + - WEBHOOK_EVENTS_CONTACTS_UPDATE=true + - WEBHOOK_EVENTS_PRESENCE_UPDATE=true + - WEBHOOK_EVENTS_CHATS_SET=true + - WEBHOOK_EVENTS_CHATS_UPSERT=true + - WEBHOOK_EVENTS_CHATS_UPDATE=true + - WEBHOOK_EVENTS_CONNECTION_UPDATE=true + - WEBHOOK_EVENTS_GROUPS_UPSERT=true + - WEBHOOK_EVENTS_GROUPS_UPDATE=true + - WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true + # This event fires every time a new token is requested via the refresh route + - WEBHOOK_EVENTS_NEW_JWT_TOKEN=true + # Name that will be displayed on smartphone connection + - CONFIG_SESSION_PHONE_CLIENT="Evolution API" + - CONFIG_SESSION_PHONE_NAME="Chrome" # firefox | edge | opera | safari + # Set qrcode display limit + - QRCODE_LIMIT=30 + # Defines an authentication type for the api + - AUTHENTICATION_TYPE="apikey" # jwt or apikey + # Define a global apikey to access all instances + # OBS: This key must be inserted in the request header to create an instance. + - AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976 + # Set the secret key to encrypt and decrypt your token and its expiration time. + - AUTHENTICATION_JWT_EXPIRIN_IN=0 # seconds - 3600s === 1h | zero (0) - never expires + # Set the instance name and webhook url to create an instance in init the application + # With this option activated, you work with a url per webhook event, respecting the local url and the name of each event + - AUTHENTICATION_INSTANCE_WEBHOOK_BY_EVENTS=false + - AUTHENTICATION_INSTANCE_MODE=server # container or server + # if you are using container mode, set the container name and the webhook url to default instance + - AUTHENTICATION_INSTANCE_NAME=evolution + - AUTHENTICATION_INSTANCE_WEBHOOK_URL=https://webhooks.n8n.evolution-api.com/webhook/0e66d93a-1671-474f-a07f-3f44b581d320 command: ['node', './dist/src/main.js'] - networks: - - evolution-net \ No newline at end of file + - evolution-net + + mongodb: + container_name: mongodb + # This image already has a single replica set + image: mongo + restart: always + # volumes: + # sudo mkdir -p /data/mongodb + # - /data/mongodb:/data/db + ports: + - 27017:27017 + environment: + MONGO_INITDB_ROOT_USERNAME: root + # Set a password to access the bank + MONGO_INITDB_ROOT_PASSWORD: root + networks: + - evolution-net + expose: + - 27017 + + redis: + container_name: redis + image: redis:latest + restart: always + # volumes: + # sudo mkdir -p /data/redis + # - /data/redis:/data + ports: + - 6379:6379 + networks: + - evolution-net + expose: + - 6379 \ No newline at end of file diff --git a/src/whatsapp/routers/instance.router.ts b/src/whatsapp/routers/instance.router.ts index bba5e8d2..1a38da40 100644 --- a/src/whatsapp/routers/instance.router.ts +++ b/src/whatsapp/routers/instance.router.ts @@ -7,7 +7,6 @@ import { HttpStatus } from './index.router'; import { OldToken } from '../services/auth.service'; import { Auth, ConfigService, Database } from '../../config/env.config'; import { dbserver } from '../../db/db.connect'; -import { BadRequestException, InternalServerErrorException } from '../../exceptions'; export class InstanceRouter extends RouterBroker { constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) {