mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 11:52:20 -06:00
Compare commits
89 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e3a175bdc | ||
|
|
4a1aa9130b | ||
|
|
5a3f5f60b6 | ||
|
|
8c1600be55 | ||
|
|
7d3ae2347b | ||
|
|
27add47db4 | ||
|
|
836bcab036 | ||
|
|
2d20a07dfb | ||
|
|
24c5c70466 | ||
|
|
22ead22499 | ||
|
|
65e1620b43 | ||
|
|
acac09375e | ||
|
|
83cf859da3 | ||
|
|
956c391f13 | ||
|
|
7767a2607e | ||
|
|
429d1ac183 | ||
|
|
f42928f88f | ||
|
|
2d816ab92d | ||
|
|
aa75380662 | ||
|
|
3cf0ced62e | ||
|
|
41fa700fb3 | ||
|
|
a4ef9fb9b7 | ||
|
|
1db23b5277 | ||
|
|
584f0cbac0 | ||
|
|
dc432a19a3 | ||
|
|
6727b1cfca | ||
|
|
8c7b0698f3 | ||
|
|
69e1622e82 | ||
|
|
af7a5d3248 | ||
|
|
7b1a4554ad | ||
|
|
b3e213c133 | ||
|
|
a9fafec79d | ||
|
|
7cacf7bbaf | ||
|
|
44bf39f7b7 | ||
|
|
0db8f7295b | ||
|
|
c1226062b1 | ||
|
|
819ed168da | ||
|
|
19940953e2 | ||
|
|
f4af3eaf5d | ||
|
|
718563fe6a | ||
|
|
7e996ad6fa | ||
|
|
0b07fb6a49 | ||
|
|
0cb87e6ed9 | ||
|
|
71a3e75ae2 | ||
|
|
a2448ea4c1 | ||
|
|
8a14141021 | ||
|
|
69353892d9 | ||
|
|
7a2fcc3469 | ||
|
|
dfa6dd5011 | ||
|
|
654400c0cf | ||
|
|
3c15fc1b0d | ||
|
|
4b32485e3c | ||
|
|
b90736ed25 | ||
|
|
f28d5c7781 | ||
|
|
0654627478 | ||
|
|
2e91a2ecdb | ||
|
|
66a8ceb27a | ||
|
|
e6b0addb6c | ||
|
|
c00f132145 | ||
|
|
b9eb8d45b2 | ||
|
|
ec7ad70458 | ||
|
|
64e19699fb | ||
|
|
6d3e1b0cbe | ||
|
|
d3a53e1d3c | ||
|
|
23bbb3ee32 | ||
|
|
56bfcd52b7 | ||
|
|
1c19b6de1e | ||
|
|
85bed0bdf1 | ||
|
|
0102796769 | ||
|
|
50b2a72f1b | ||
|
|
04cc239756 | ||
|
|
0c20da2481 | ||
|
|
72d2a563f3 | ||
|
|
6f3f8c944d | ||
|
|
ed60fd2e82 | ||
|
|
636fef4693 | ||
|
|
77775e2f85 | ||
|
|
b260959a6e | ||
|
|
2a04f7b378 | ||
|
|
d4766f9c81 | ||
|
|
7f4c9b5b11 | ||
|
|
70f7c8ce89 | ||
|
|
f33a6aba39 | ||
|
|
236d717f10 | ||
|
|
0fc160f57c | ||
|
|
666023d89a | ||
|
|
8c4f2991c7 | ||
|
|
4453dff36d | ||
|
|
90b043561f |
63
CHANGELOG.md
63
CHANGELOG.md
@@ -1,4 +1,65 @@
|
||||
# 1.2.0 (homolog)
|
||||
# 1.3.1 (2023-07-20 07:48)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Adjust in create store files
|
||||
|
||||
# 1.3.0 (2023-07-19 11:33)
|
||||
|
||||
### Features
|
||||
|
||||
* Added messages.delete event
|
||||
* Added restart instance endpoint
|
||||
* Created automation for creating instances in the chatwoot bot with the command '#inbox_whatsapp:<INSTANCE_NAME>'
|
||||
* Change Baileys version to: 6.4.0
|
||||
* Send contact in chatwoot
|
||||
* Send contact array in chatwoot
|
||||
* Added apiKey in webhook and serverUrl in fetchInstance if EXPOSE_IN_FETCH_INSTANCES: true
|
||||
* Translation set to default (english) in chatwoot
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed error to send message in large groups
|
||||
* Docker files adjusted
|
||||
* Fixed in the postman collection the webhookByEvent parameter by webhook_by_events
|
||||
* Added validations in create instance
|
||||
* Removed link preview endpoint, now it's done automatically from sending conventional text
|
||||
* Added group membership validation before sending message to groups
|
||||
* Adjusts in docker files
|
||||
* Adjusts in returns in endpoints chatwoot and webhook
|
||||
* Fixed ghost mentions in send text message
|
||||
* Fixed bug that saved contacts from groups came without number in chatwoot
|
||||
* Fixed problem to receive csat in chatwoot
|
||||
* Fixed require fileName for document only in base64 for send media message
|
||||
* Bug fix when sending mobile message change contact name to number in chatwoot
|
||||
* Bug fix when connecting whatsapp does not send confirmation message
|
||||
* Fixed quoted message with id or message directly
|
||||
* Adjust in validation for mexican and argentine numbers
|
||||
* Adjust in create store files
|
||||
|
||||
### Integrations
|
||||
|
||||
- Chatwoot: v2.18.0
|
||||
|
||||
# 1.2.2 (2023-07-15 09:36)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Tweak in route "/" with version info
|
||||
* Adjusts chatwoot version
|
||||
|
||||
### Integrations
|
||||
|
||||
- Chatwoot: v2.18.0
|
||||
|
||||
# 1.2.1 (2023-07-14 19:04)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Adjusts in docker files
|
||||
* Save picture url groups in chatwoot
|
||||
|
||||
# 1.2.0 (2023-07-14 15:28)
|
||||
|
||||
### Features
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
SERVER_URL='<url>' # ex.: http://localhost:3333
|
||||
# Server URL - Set your application url
|
||||
SERVER_URL='http://localhost:8080'
|
||||
|
||||
CORS_ORIGIN='*' # Or separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
|
||||
# Cors - * for all or set separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
|
||||
CORS_ORIGIN='*'
|
||||
CORS_METHODS='POST,GET,PUT,DELETE'
|
||||
CORS_CREDENTIALS=true
|
||||
|
||||
# Determine the logs to be displayed
|
||||
LOG_LEVEL='ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS'
|
||||
LOG_COLOR=true
|
||||
LOG_BAILEYS=error # "fatal" | "error" | "warn" | "info" | "debug" | "trace"
|
||||
# Log Baileys - "fatal" | "error" | "warn" | "info" | "debug" | "trace"
|
||||
LOG_BAILEYS=error
|
||||
|
||||
# Determine how long the instance should be deleted from memory in case of no connection.
|
||||
# Default time: 5 minutes
|
||||
@@ -20,7 +23,8 @@ STORE_MESSAGE_UP=true
|
||||
STORE_CONTACTS=true
|
||||
STORE_CHATS=true
|
||||
|
||||
CLEAN_STORE_CLEANING_INTERVAL=7200 # seconds === 2h
|
||||
# Set Store Interval in Seconds (7200 = 2h)
|
||||
CLEAN_STORE_CLEANING_INTERVAL=7200
|
||||
CLEAN_STORE_MESSAGES=true
|
||||
CLEAN_STORE_MESSAGE_UP=true
|
||||
CLEAN_STORE_CONTACTS=true
|
||||
@@ -45,7 +49,7 @@ REDIS_PREFIX_KEY=evolution
|
||||
# Global Webhook Settings
|
||||
# Each instance's Webhook URL and events will be requested at the time it is created
|
||||
## Define a global webhook that will listen for enabled events from all instances
|
||||
WEBHOOK_GLOBAL_URL='<url>'
|
||||
WEBHOOK_GLOBAL_URL=''
|
||||
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
|
||||
@@ -55,6 +59,7 @@ WEBHOOK_EVENTS_QRCODE_UPDATED=true
|
||||
WEBHOOK_EVENTS_MESSAGES_SET=true
|
||||
WEBHOOK_EVENTS_MESSAGES_UPSERT=true
|
||||
WEBHOOK_EVENTS_MESSAGES_UPDATE=true
|
||||
WEBHOOK_EVENTS_MESSAGES_DELETE=true
|
||||
WEBHOOK_EVENTS_SEND_MESSAGE=true
|
||||
WEBHOOK_EVENTS_CONTACTS_SET=true
|
||||
WEBHOOK_EVENTS_CONTACTS_UPSERT=true
|
||||
@@ -73,7 +78,8 @@ WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
|
||||
|
||||
# Name that will be displayed on smartphone connection
|
||||
CONFIG_SESSION_PHONE_CLIENT='Evolution API'
|
||||
CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari
|
||||
# Browser Name = chrome | firefox | edge | opera | safari
|
||||
CONFIG_SESSION_PHONE_NAME=chrome
|
||||
|
||||
# Set qrcode display limit
|
||||
QRCODE_LIMIT=30
|
||||
@@ -81,20 +87,23 @@ QRCODE_LIMIT=30
|
||||
# Defines an authentication type for the api
|
||||
# We recommend using the apikey because it will allow you to use a custom token,
|
||||
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
|
||||
AUTHENTICATION_TYPE='apikey' # jwt or 'apikey'
|
||||
# jwt or 'apikey'
|
||||
AUTHENTICATION_TYPE='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'
|
||||
AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
||||
## 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
|
||||
# seconds - 3600s ===1h | zero (0) - never expires
|
||||
AUTHENTICATION_JWT_EXPIRIN_IN=0
|
||||
AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
|
||||
# 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_MODE=server # container or server
|
||||
# container or server
|
||||
AUTHENTICATION_INSTANCE_MODE=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='<url>'
|
||||
AUTHENTICATION_INSTANCE_WEBHOOK_URL=''
|
||||
AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
|
||||
AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
|
||||
AUTHENTICATION_INSTANCE_CHATWOOT_URL='<url>'
|
||||
AUTHENTICATION_INSTANCE_CHATWOOT_URL=''
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
version: '3.3'
|
||||
|
||||
networks:
|
||||
evolution-net:
|
||||
driver: bridge
|
||||
|
||||
services:
|
||||
mongodb:
|
||||
container_name: mongodb
|
||||
@@ -19,11 +15,27 @@ services:
|
||||
volumes:
|
||||
- evolution_mongodb_data:/data/db
|
||||
- evolution_mongodb_configdb:/data/configdb
|
||||
networks:
|
||||
- evolution-net
|
||||
expose:
|
||||
- 27017
|
||||
|
||||
mongo-express:
|
||||
image: mongo-express
|
||||
environment:
|
||||
ME_CONFIG_BASICAUTH_USERNAME: root
|
||||
ME_CONFIG_BASICAUTH_PASSWORD: root
|
||||
ME_CONFIG_MONGODB_SERVER: mongodb
|
||||
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
||||
ME_CONFIG_MONGODB_ADMINPASSWORD: root
|
||||
ports:
|
||||
- 8081:8081
|
||||
links:
|
||||
- mongodb
|
||||
|
||||
volumes:
|
||||
evolution_mongodb_data:
|
||||
evolution_mongodb_configdb:
|
||||
|
||||
networks:
|
||||
evolution-net:
|
||||
external: true
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
version: '3.3'
|
||||
|
||||
networks:
|
||||
evolution-net:
|
||||
driver: bridge
|
||||
|
||||
services:
|
||||
redis:
|
||||
image: redis:latest
|
||||
@@ -16,8 +12,17 @@ services:
|
||||
- evolution_redis:/data
|
||||
ports:
|
||||
- 6379:6379
|
||||
networks:
|
||||
- evolution-net
|
||||
|
||||
rebrow:
|
||||
image: marian/rebrow
|
||||
ports:
|
||||
- 5001:5001
|
||||
links:
|
||||
- redis
|
||||
|
||||
volumes:
|
||||
evolution_redis:
|
||||
|
||||
networks:
|
||||
evolution-net:
|
||||
external: true
|
||||
|
||||
130
Dockerfile
130
Dockerfile
@@ -13,86 +13,90 @@ COPY ./package.json .
|
||||
|
||||
ENV DOCKER_ENV=true
|
||||
|
||||
ENV SERVER_TYPE="http"
|
||||
ENV SERVER_PORT=8080
|
||||
ENV SERVER_URL=$SERVER_URL
|
||||
ENV SERVER_URL='http://localhost:8080'
|
||||
|
||||
ENV CORS_ORIGIN="*"
|
||||
ENV CORS_METHODS="POST,GET,PUT,DELETE"
|
||||
ENV CORS_ORIGIN=*
|
||||
ENV CORS_METHODS=POST,GET,PUT,DELETE
|
||||
ENV CORS_CREDENTIALS=true
|
||||
|
||||
ENV LOG_LEVEL=$LOG_LEVEL
|
||||
ENV LOG_COLOR=$LOG_COLOR
|
||||
ENV LOG_LEVEL=ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS
|
||||
ENV LOG_COLOR=true
|
||||
ENV LOG_BAILEYS=error
|
||||
|
||||
ENV DEL_INSTANCE=$DEL_INSTANCE
|
||||
ENV DEL_INSTANCE=false
|
||||
|
||||
ENV STORE_MESSAGES=$STORE_MESSAGE
|
||||
ENV STORE_MESSAGE_UP=$STORE_MESSAGE_UP
|
||||
ENV STORE_CONTACTS=$STORE_CONTACTS
|
||||
ENV STORE_CHATS=$STORE_CHATS
|
||||
ENV STORE_MESSAGES=true
|
||||
ENV STORE_MESSAGE_UP=true
|
||||
ENV STORE_CONTACTS=true
|
||||
ENV STORE_CHATS=true
|
||||
|
||||
ENV CLEAN_STORE_CLEANING_INTERVAL=$CLEAN_STORE_CLEANING_INTERVAL
|
||||
ENV CLEAN_STORE_MESSAGES=$CLEAN_STORE_MESSAGE
|
||||
ENV CLEAN_STORE_MESSAGE_UP=$CLEAN_STORE_MESSAGE_UP
|
||||
ENV CLEAN_STORE_CONTACTS=$CLEAN_STORE_CONTACTS
|
||||
ENV CLEAN_STORE_CHATS=$CLEAN_STORE_CHATS
|
||||
ENV CLEAN_STORE_CLEANING_INTERVAL=7200
|
||||
ENV CLEAN_STORE_MESSAGES=true
|
||||
ENV CLEAN_STORE_MESSAGE_UP=true
|
||||
ENV CLEAN_STORE_CONTACTS=true
|
||||
ENV CLEAN_STORE_CHATS=true
|
||||
|
||||
ENV DATABASE_ENABLED=$DATABASE_ENABLED
|
||||
ENV DATABASE_CONNECTION_URI=$DATABASE_CONNECTION_URI
|
||||
ENV DATABASE_CONNECTION_DB_PREFIX_NAME=$DATABASE_CONNECTION_DB_PREFIX_NAME
|
||||
ENV DATABASE_SAVE_DATA_INSTANCE=$DATABASE_SAVE_DATA_INSTANCE
|
||||
ENV DATABASE_SAVE_DATA_NEW_MESSAGE=$DATABASE_SAVE_DATA_NEW_MESSAGE
|
||||
ENV DATABASE_SAVE_MESSAGE_UPDATE=$DATABASE_SAVE_MESSAGE_UPDATE
|
||||
ENV DATABASE_SAVE_DATA_CONTACTS=$DATABASE_SAVE_DATA_CONTACTS
|
||||
ENV DATABASE_SAVE_DATA_CHATS=$DATABASE_SAVE_DATA_CHATS
|
||||
ENV DATABASE_ENABLED=false
|
||||
ENV DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
|
||||
ENV DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
|
||||
|
||||
ENV REDIS_ENABLED=$REDIS_ENABLED
|
||||
ENV REDIS_URI=$REDIS_URI
|
||||
ENV REDIS_PREFIX_KEY=$REDIS_PREFIX_KEY
|
||||
ENV DATABASE_SAVE_DATA_INSTANCE=false
|
||||
ENV DATABASE_SAVE_DATA_NEW_MESSAGE=false
|
||||
ENV DATABASE_SAVE_MESSAGE_UPDATE=false
|
||||
ENV DATABASE_SAVE_DATA_CONTACTS=false
|
||||
ENV DATABASE_SAVE_DATA_CHATS=false
|
||||
|
||||
ENV WEBHOOK_GLOBAL_URL=$WEBHOOK_GLOBAL_URL
|
||||
ENV WEBHOOK_GLOBAL_ENABLED=$WEBHOOK_GLOBAL_ENABLED
|
||||
ENV WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=$WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS
|
||||
ENV REDIS_ENABLED=false
|
||||
ENV REDIS_URI=redis://redis:6379
|
||||
ENV REDIS_PREFIX_KEY=evolution
|
||||
|
||||
ENV WEBHOOK_EVENTS_APPLICATION_STARTUP=$WEBHOOK_EVENTS_APPLICATION_STARTUP
|
||||
ENV WEBHOOK_EVENTS_QRCODE_UPDATED=$WEBHOOK_EVENTS_QRCODE_UPDATED
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_SET=$WEBHOOK_EVENTS_MESSAGES_SET
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_UPSERT=$WEBHOOK_EVENTS_MESSAGES_UPSERT
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
|
||||
ENV WEBHOOK_EVENTS_SEND_MESSAGE=$WEBHOOK_EVENTS_SEND_MESSAGE
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_SET=$WEBHOOK_EVENTS_CONTACTS_SET
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=$WEBHOOK_EVENTS_CONTACTS_UPSERT
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_UPDATE=$WEBHOOK_EVENTS_CONTACTS_UPDATE
|
||||
ENV WEBHOOK_EVENTS_PRESENCE_UPDATE=$WEBHOOK_EVENTS_PRESENCE_UPDATE
|
||||
ENV WEBHOOK_EVENTS_CHATS_SET=$WEBHOOK_EVENTS_CHATS_SET
|
||||
ENV WEBHOOK_EVENTS_CHATS_UPSERT=$WEBHOOK_EVENTS_CHATS_UPSERT
|
||||
ENV WEBHOOK_EVENTS_CHATS_UPDATE=$WEBHOOK_EVENTS_CHATS_UPDATE
|
||||
ENV WEBHOOK_EVENTS_CONNECTION_UPDATE=$WEBHOOK_EVENTS_CONNECTION_UPDATE
|
||||
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_GLOBAL_URL=<url>
|
||||
ENV WEBHOOK_GLOBAL_ENABLED=false
|
||||
|
||||
ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=$WEBHOOK_EVENTS_NEW_JWT_TOKEN
|
||||
ENV WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
|
||||
|
||||
ENV CONFIG_SESSION_PHONE_CLIENT=$CONFIG_SESSION_PHONE_CLIENT
|
||||
ENV CONFIG_SESSION_PHONE_NAME=$CONFIG_SESSION_PHONE_NAME
|
||||
ENV WEBHOOK_EVENTS_APPLICATION_STARTUP=false
|
||||
ENV WEBHOOK_EVENTS_QRCODE_UPDATED=true
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_SET=true
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_UPSERT=true
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_DELETE=true
|
||||
ENV WEBHOOK_EVENTS_SEND_MESSAGE=true
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_SET=true
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=true
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_PRESENCE_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_CHATS_SET=true
|
||||
ENV WEBHOOK_EVENTS_CHATS_UPSERT=true
|
||||
ENV WEBHOOK_EVENTS_CHATS_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_CHATS_DELETE=true
|
||||
ENV WEBHOOK_EVENTS_GROUPS_UPSERT=true
|
||||
ENV WEBHOOK_EVENTS_GROUPS_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_CONNECTION_UPDATE=true
|
||||
|
||||
ENV QRCODE_LIMIT=$QRCODE_LIMIT
|
||||
ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
|
||||
|
||||
ENV AUTHENTICATION_TYPE=$AUTHENTICATION_TYPE
|
||||
ENV CONFIG_SESSION_PHONE_CLIENT='Evolution API'
|
||||
ENV CONFIG_SESSION_PHONE_NAME=chrome
|
||||
|
||||
ENV AUTHENTICATION_API_KEY=$AUTHENTICATION_API_KEY
|
||||
ENV AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=$AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES
|
||||
ENV QRCODE_LIMIT=30
|
||||
|
||||
ENV AUTHENTICATION_JWT_EXPIRIN_IN=$AUTHENTICATION_JWT_EXPIRIN_IN
|
||||
ENV AUTHENTICATION_JWT_SECRET="L=0YWt]b2w[WF>#>:&E`"
|
||||
ENV AUTHENTICATION_TYPE=apikey
|
||||
|
||||
ENV AUTHENTICATION_INSTANCE_NAME=$AUTHENTICATION_INSTANCE_NAME
|
||||
ENV AUTHENTICATION_INSTANCE_WEBHOOK_URL=$AUTHENTICATION_INSTANCE_WEBHOOK_URL
|
||||
ENV AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=$AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID
|
||||
ENV AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=$AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN
|
||||
ENV AUTHENTICATION_INSTANCE_CHATWOOT_URL=$AUTHENTICATION_INSTANCE_CHATWOOT_URL
|
||||
ENV AUTHENTICATION_INSTANCE_MODE=$AUTHENTICATION_INSTANCE_MODE
|
||||
ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
|
||||
ENV AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
||||
|
||||
ENV AUTHENTICATION_JWT_EXPIRIN_IN=0
|
||||
ENV AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
|
||||
|
||||
ENV AUTHENTICATION_INSTANCE_MODE=server
|
||||
|
||||
ENV AUTHENTICATION_INSTANCE_NAME=evolution
|
||||
ENV AUTHENTICATION_INSTANCE_WEBHOOK_URL=<url>
|
||||
ENV AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
|
||||
ENV AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
|
||||
ENV AUTHENTICATION_INSTANCE_CHATWOOT_URL=<url>
|
||||
|
||||
RUN npm install
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
version: '3.3'
|
||||
|
||||
networks:
|
||||
evolution-net:
|
||||
driver: bridge
|
||||
|
||||
services:
|
||||
api:
|
||||
container_name: evolution_api
|
||||
@@ -17,11 +13,14 @@ services:
|
||||
env_file:
|
||||
- ./Docker/.env
|
||||
command: ['node', './dist/src/main.js']
|
||||
networks:
|
||||
- evolution-net
|
||||
expose:
|
||||
- 8080
|
||||
|
||||
volumes:
|
||||
evolution_instances:
|
||||
evolution_store:
|
||||
|
||||
networks:
|
||||
evolution-net:
|
||||
external: true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "evolution-api",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.1",
|
||||
"description": "Rest api for communication with WhatsApp",
|
||||
"main": "./dist/src/main.js",
|
||||
"scripts": {
|
||||
@@ -42,9 +42,10 @@
|
||||
"dependencies": {
|
||||
"@adiwajshing/keyed-db": "^0.2.4",
|
||||
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
||||
"@hapi/boom": "^10.0.1",
|
||||
"@whiskeysockets/baileys": "github:vphelipe/WhiskeySockets-Baileys#master",
|
||||
"@figuro/chatwoot-sdk": "^1.1.14",
|
||||
"@hapi/boom": "^10.0.1",
|
||||
"@sentry/node": "^7.59.2",
|
||||
"@whiskeysockets/baileys": "^6.4.0",
|
||||
"axios": "^1.3.5",
|
||||
"class-validator": "^0.13.2",
|
||||
"compression": "^1.7.4",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { load } from 'js-yaml';
|
||||
import { join } from 'path';
|
||||
import { SRC_DIR } from './path.config';
|
||||
import { isBooleanString } from 'class-validator';
|
||||
|
||||
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
|
||||
@@ -76,6 +75,7 @@ export type EventsWebhook = {
|
||||
MESSAGES_SET: boolean;
|
||||
MESSAGES_UPSERT: boolean;
|
||||
MESSAGES_UPDATE: boolean;
|
||||
MESSAGES_DELETE: boolean;
|
||||
SEND_MESSAGE: boolean;
|
||||
CONTACTS_SET: boolean;
|
||||
CONTACTS_UPDATE: boolean;
|
||||
@@ -98,9 +98,9 @@ export type Instance = {
|
||||
NAME: string;
|
||||
WEBHOOK_URL: string;
|
||||
MODE: string;
|
||||
CHATWOOT_ACCOUNT_ID?: string;
|
||||
CHATWOOT_TOKEN?: string;
|
||||
CHATWOOT_URL?: string;
|
||||
CHATWOOT_ACCOUNT_ID: string;
|
||||
CHATWOOT_TOKEN: string;
|
||||
CHATWOOT_URL: string;
|
||||
};
|
||||
export type Auth = {
|
||||
API_KEY: ApiKey;
|
||||
@@ -193,7 +193,7 @@ export class ConfigService {
|
||||
CLEAN_STORE: {
|
||||
CLEANING_INTERVAL: Number.isInteger(process.env?.CLEAN_STORE_CLEANING_TERMINAL)
|
||||
? Number.parseInt(process.env.CLEAN_STORE_CLEANING_TERMINAL)
|
||||
: undefined,
|
||||
: 7200,
|
||||
MESSAGES: process.env?.CLEAN_STORE_MESSAGES === 'true',
|
||||
MESSAGE_UP: process.env?.CLEAN_STORE_MESSAGE_UP === 'true',
|
||||
CONTACTS: process.env?.CLEAN_STORE_CONTACTS === 'true',
|
||||
@@ -225,7 +225,7 @@ export class ConfigService {
|
||||
},
|
||||
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
|
||||
? process.env.DEL_INSTANCE === 'true'
|
||||
: Number.parseInt(process.env.DEL_INSTANCE),
|
||||
: Number.parseInt(process.env.DEL_INSTANCE) || false,
|
||||
WEBHOOK: {
|
||||
GLOBAL: {
|
||||
URL: process.env?.WEBHOOK_GLOBAL_URL,
|
||||
@@ -238,6 +238,7 @@ export class ConfigService {
|
||||
MESSAGES_SET: process.env?.WEBHOOK_EVENTS_MESSAGES_SET === 'true',
|
||||
MESSAGES_UPSERT: process.env?.WEBHOOK_EVENTS_MESSAGES_UPSERT === 'true',
|
||||
MESSAGES_UPDATE: process.env?.WEBHOOK_EVENTS_MESSAGES_UPDATE === 'true',
|
||||
MESSAGES_DELETE: process.env?.WEBHOOK_EVENTS_MESSAGES_DELETE === 'true',
|
||||
SEND_MESSAGE: process.env?.WEBHOOK_EVENTS_SEND_MESSAGE === 'true',
|
||||
CONTACTS_SET: process.env?.WEBHOOK_EVENTS_CONTACTS_SET === 'true',
|
||||
CONTACTS_UPDATE: process.env?.WEBHOOK_EVENTS_CONTACTS_UPDATE === 'true',
|
||||
@@ -256,11 +257,11 @@ export class ConfigService {
|
||||
},
|
||||
},
|
||||
CONFIG_SESSION_PHONE: {
|
||||
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT,
|
||||
NAME: process.env?.CONFIG_SESSION_PHONE_NAME,
|
||||
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API',
|
||||
NAME: process.env?.CONFIG_SESSION_PHONE_NAME || 'chrome',
|
||||
},
|
||||
QRCODE: {
|
||||
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT),
|
||||
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,
|
||||
},
|
||||
AUTHENTICATION: {
|
||||
TYPE: process.env.AUTHENTICATION_TYPE as 'jwt',
|
||||
|
||||
@@ -39,7 +39,7 @@ LOG:
|
||||
- DARK
|
||||
- WEBHOOKS
|
||||
COLOR: true
|
||||
BAILEYS: error # "fatal" | "error" | "warn" | "info" | "debug" | "trace"
|
||||
BAILEYS: error # fatal | error | warn | info | debug | trace
|
||||
|
||||
# Determine how long the instance should be deleted from memory in case of no connection.
|
||||
# Default time: 5 minutes
|
||||
@@ -96,6 +96,7 @@ WEBHOOK:
|
||||
MESSAGES_SET: true
|
||||
MESSAGES_UPSERT: true
|
||||
MESSAGES_UPDATE: true
|
||||
MESSAGES_DELETE: true
|
||||
SEND_MESSAGE: true
|
||||
CONTACTS_SET: true
|
||||
CONTACTS_UPSERT: true
|
||||
|
||||
29
src/main.ts
29
src/main.ts
@@ -10,6 +10,7 @@ import { waMonitor } from './whatsapp/whatsapp.module';
|
||||
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
||||
import 'express-async-errors';
|
||||
import { ServerUP } from './utils/server-up';
|
||||
import * as Sentry from '@sentry/node';
|
||||
|
||||
function initWA() {
|
||||
waMonitor.loadInstance();
|
||||
@@ -19,6 +20,27 @@ function bootstrap() {
|
||||
const logger = new Logger('SERVER');
|
||||
const app = express();
|
||||
|
||||
// Sentry.init({
|
||||
// dsn: '',
|
||||
// integrations: [
|
||||
// // enable HTTP calls tracing
|
||||
// new Sentry.Integrations.Http({ tracing: true }),
|
||||
// // enable Express.js middleware tracing
|
||||
// new Sentry.Integrations.Express({ app }),
|
||||
// // Automatically instrument Node.js libraries and frameworks
|
||||
// ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
|
||||
// ],
|
||||
|
||||
// // Set tracesSampleRate to 1.0 to capture 100%
|
||||
// // of transactions for performance monitoring.
|
||||
// // We recommend adjusting this value in production
|
||||
// tracesSampleRate: 1.0,
|
||||
// });
|
||||
|
||||
// app.use(Sentry.Handlers.requestHandler());
|
||||
|
||||
// app.use(Sentry.Handlers.tracingHandler());
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
origin(requestOrigin, callback) {
|
||||
@@ -43,6 +65,13 @@ function bootstrap() {
|
||||
|
||||
app.use('/', router);
|
||||
|
||||
// app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
// app.use(function onError(err, req, res, next) {
|
||||
// res.statusCode = 500;
|
||||
// res.end(res.sentry + '\n');
|
||||
// });
|
||||
|
||||
app.use(
|
||||
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||
if (err) {
|
||||
|
||||
@@ -39,6 +39,7 @@ export const instanceNameSchema: JSONSchema7 = {
|
||||
'MESSAGES_SET',
|
||||
'MESSAGES_UPSERT',
|
||||
'MESSAGES_UPDATE',
|
||||
'MESSAGES_DELETE',
|
||||
'SEND_MESSAGE',
|
||||
'CONTACTS_SET',
|
||||
'CONTACTS_UPSERT',
|
||||
@@ -81,8 +82,8 @@ const quotedOptionsSchema: JSONSchema7 = {
|
||||
remoteJid: { type: 'string' },
|
||||
fromMe: { type: 'boolean', enum: [true, false] },
|
||||
},
|
||||
required: ['id', 'remoteJid', 'fromMe'],
|
||||
...isNotEmpty('id', 'remoteJid'),
|
||||
required: ['id'],
|
||||
...isNotEmpty('id'),
|
||||
},
|
||||
message: { type: 'object' },
|
||||
},
|
||||
@@ -144,24 +145,6 @@ export const textMessageSchema: JSONSchema7 = {
|
||||
required: ['textMessage', 'number'],
|
||||
};
|
||||
|
||||
export const linkPreviewSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
number: { ...numberDefinition },
|
||||
options: { ...optionsSchema },
|
||||
linkPreview: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
text: { type: 'string' },
|
||||
},
|
||||
required: ['text'],
|
||||
...isNotEmpty('text'),
|
||||
},
|
||||
},
|
||||
required: ['linkPreview', 'number'],
|
||||
};
|
||||
|
||||
export const pollMessageSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
@@ -846,6 +829,7 @@ export const webhookSchema: JSONSchema7 = {
|
||||
'MESSAGES_SET',
|
||||
'MESSAGES_UPSERT',
|
||||
'MESSAGES_UPDATE',
|
||||
'MESSAGES_DELETE',
|
||||
'SEND_MESSAGE',
|
||||
'CONTACTS_SET',
|
||||
'CONTACTS_UPSERT',
|
||||
|
||||
@@ -160,8 +160,6 @@ export abstract class RouterBroker {
|
||||
|
||||
const v = validate(ref, schema);
|
||||
|
||||
console.log(v, '@checkei aqui');
|
||||
|
||||
if (!v.valid) {
|
||||
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||
let message: string;
|
||||
@@ -203,8 +201,6 @@ export abstract class RouterBroker {
|
||||
|
||||
const v = validate(ref, schema);
|
||||
|
||||
console.log(v, '@checkei aqui');
|
||||
|
||||
if (!v.valid) {
|
||||
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||
let message: string;
|
||||
|
||||
@@ -66,6 +66,18 @@ export class ChatwootController {
|
||||
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
|
||||
if (Object.keys(result).length === 0) {
|
||||
return {
|
||||
enabled: false,
|
||||
url: '',
|
||||
account_id: '',
|
||||
token: '',
|
||||
sign_msg: false,
|
||||
name_inbox: '',
|
||||
webhook_url: '',
|
||||
};
|
||||
}
|
||||
|
||||
const response = {
|
||||
...result,
|
||||
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||
@@ -78,7 +90,7 @@ export class ChatwootController {
|
||||
logger.verbose(
|
||||
'requested receiveWebhook from ' + instance.instanceName + ' instance',
|
||||
);
|
||||
const chatwootService = new ChatwootService(waMonitor);
|
||||
const chatwootService = new ChatwootService(waMonitor, this.configService);
|
||||
|
||||
return chatwootService.receiveWebhook(instance, data);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { ChatwootService } from '../services/chatwoot.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { wa } from '../types/wa.types';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { isURL } from 'class-validator';
|
||||
|
||||
export class InstanceController {
|
||||
constructor(
|
||||
@@ -63,7 +64,10 @@ export class InstanceController {
|
||||
this.repository,
|
||||
this.cache,
|
||||
);
|
||||
instance.instanceName = instanceName;
|
||||
instance.instanceName = instanceName
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/g, '')
|
||||
.replace(' ', '');
|
||||
this.logger.verbose('instance: ' + instance.instanceName + ' created');
|
||||
|
||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
||||
@@ -82,6 +86,9 @@ export class InstanceController {
|
||||
let getEvents: string[];
|
||||
|
||||
if (webhook) {
|
||||
if (!isURL(webhook, { require_tld: false })) {
|
||||
throw new BadRequestException('Invalid "url" property in webhook');
|
||||
}
|
||||
this.logger.verbose('creating webhook');
|
||||
try {
|
||||
this.webhookService.create(instance, {
|
||||
@@ -132,6 +139,10 @@ export class InstanceController {
|
||||
throw new BadRequestException('url is required');
|
||||
}
|
||||
|
||||
if (!isURL(chatwoot_url, { require_tld: false })) {
|
||||
throw new BadRequestException('Invalid "url" property in chatwoot');
|
||||
}
|
||||
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
|
||||
try {
|
||||
@@ -183,7 +194,10 @@ export class InstanceController {
|
||||
this.repository,
|
||||
this.cache,
|
||||
);
|
||||
instance.instanceName = instanceName;
|
||||
instance.instanceName = instanceName
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/g, '')
|
||||
.replace(' ', '');
|
||||
|
||||
this.logger.verbose('instance: ' + instance.instanceName + ' created');
|
||||
|
||||
@@ -203,6 +217,10 @@ export class InstanceController {
|
||||
let getEvents: string[];
|
||||
|
||||
if (webhook) {
|
||||
if (!isURL(webhook, { require_tld: false })) {
|
||||
throw new BadRequestException('Invalid "url" property in webhook');
|
||||
}
|
||||
|
||||
this.logger.verbose('creating webhook');
|
||||
try {
|
||||
this.webhookService.create(instance, {
|
||||
@@ -266,6 +284,10 @@ export class InstanceController {
|
||||
throw new BadRequestException('url is required');
|
||||
}
|
||||
|
||||
if (!isURL(chatwoot_url, { require_tld: false })) {
|
||||
throw new BadRequestException('Invalid "url" property in chatwoot');
|
||||
}
|
||||
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
|
||||
try {
|
||||
@@ -341,24 +363,8 @@ export class InstanceController {
|
||||
try {
|
||||
this.logger.verbose('requested restartInstance from ' + instanceName + ' instance');
|
||||
|
||||
this.logger.verbose('deleting instance: ' + instanceName);
|
||||
delete this.waMonitor.waInstances[instanceName];
|
||||
|
||||
this.logger.verbose('creating instance: ' + instanceName);
|
||||
const instance = new WAStartupService(
|
||||
this.configService,
|
||||
this.eventEmitter,
|
||||
this.repository,
|
||||
this.cache,
|
||||
);
|
||||
|
||||
instance.instanceName = instanceName;
|
||||
|
||||
this.logger.verbose('instance: ' + instance.instanceName + ' created');
|
||||
|
||||
this.logger.verbose('connecting instance: ' + instanceName);
|
||||
await instance.connectToWhatsapp();
|
||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
||||
this.logger.verbose('logging out instance: ' + instanceName);
|
||||
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
||||
|
||||
return { error: false, message: 'Instance restarted' };
|
||||
} catch (error) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
SendAudioDto,
|
||||
SendButtonDto,
|
||||
SendContactDto,
|
||||
SendLinkPreviewDto,
|
||||
SendListDto,
|
||||
SendLocationDto,
|
||||
SendMediaDto,
|
||||
@@ -31,9 +30,15 @@ export class SendMessageController {
|
||||
|
||||
public async sendMedia({ instanceName }: InstanceDto, data: SendMediaDto) {
|
||||
logger.verbose('requested sendMedia from ' + instanceName + ' instance');
|
||||
if (isBase64(data?.mediaMessage?.media) && !data?.mediaMessage?.fileName) {
|
||||
throw new BadRequestException('For bse64 the file name must be informed.');
|
||||
|
||||
if (
|
||||
isBase64(data?.mediaMessage?.media) &&
|
||||
!data?.mediaMessage?.fileName &&
|
||||
data?.mediaMessage?.mediatype === 'document'
|
||||
) {
|
||||
throw new BadRequestException('For base64 the file name must be informed.');
|
||||
}
|
||||
|
||||
logger.verbose(
|
||||
'isURL: ' +
|
||||
isURL(data?.mediaMessage?.media) +
|
||||
@@ -119,9 +124,4 @@ export class SendMessageController {
|
||||
logger.verbose('requested sendStatus from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].statusMessage(data);
|
||||
}
|
||||
|
||||
public async sendLinkPreview({ instanceName }: InstanceDto, data: SendLinkPreviewDto) {
|
||||
logger.verbose('requested sendLinkPreview from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].linkPreview(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,6 @@ class TextMessage {
|
||||
text: string;
|
||||
}
|
||||
|
||||
class linkPreviewMessage {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export class StatusMessage {
|
||||
type: string;
|
||||
content: string;
|
||||
@@ -52,10 +48,6 @@ export class SendTextDto extends Metadata {
|
||||
textMessage: TextMessage;
|
||||
}
|
||||
|
||||
export class SendLinkPreviewDto extends Metadata {
|
||||
linkPreview: linkPreviewMessage;
|
||||
}
|
||||
|
||||
export class SendStatusDto extends Metadata {
|
||||
statusMessage: StatusMessage;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { cache, waMonitor } from '../whatsapp.module';
|
||||
import { Database, Redis, configService } from '../../config/env.config';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
|
||||
async function getInstance(instanceName: string) {
|
||||
const db = configService.get<Database>('DATABASE');
|
||||
|
||||
@@ -14,6 +14,7 @@ const webhookSchema = new Schema<WebhookRaw>({
|
||||
url: { type: String, required: true },
|
||||
enabled: { type: Boolean, required: true },
|
||||
events: { type: [String], required: true },
|
||||
webhook_by_events: { type: Boolean, required: true },
|
||||
});
|
||||
|
||||
export const WebhookModel = dbserver?.model(WebhookRaw.name, webhookSchema, 'webhook');
|
||||
|
||||
@@ -5,12 +5,13 @@ import { MessageUpRepository } from './messageUp.repository';
|
||||
import { MongoClient } from 'mongodb';
|
||||
import { WebhookRepository } from './webhook.repository';
|
||||
import { ChatwootRepository } from './chatwoot.repository';
|
||||
|
||||
import { AuthRepository } from './auth.repository';
|
||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||
import { execSync } from 'child_process';
|
||||
import { join } from 'path';
|
||||
import fs from 'fs';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
export class RepositoryBroker {
|
||||
constructor(
|
||||
public readonly message: MessageRepository,
|
||||
@@ -23,7 +24,6 @@ export class RepositoryBroker {
|
||||
private configService: ConfigService,
|
||||
dbServer?: MongoClient,
|
||||
) {
|
||||
this.logger.verbose('initializing repository broker');
|
||||
this.dbClient = dbServer;
|
||||
this.__init_repo_without_db__();
|
||||
}
|
||||
@@ -38,39 +38,59 @@ export class RepositoryBroker {
|
||||
private __init_repo_without_db__() {
|
||||
this.logger.verbose('initializing repository without db');
|
||||
if (!this.configService.get<Database>('DATABASE').ENABLED) {
|
||||
this.logger.verbose('database is disabled');
|
||||
|
||||
const storePath = join(process.cwd(), 'store');
|
||||
|
||||
this.logger.verbose('creating store path: ' + storePath);
|
||||
execSync(
|
||||
`mkdir -p ${join(
|
||||
try {
|
||||
const authDir = join(
|
||||
storePath,
|
||||
'auth',
|
||||
this.configService.get<Auth>('AUTHENTICATION').TYPE,
|
||||
)}`,
|
||||
);
|
||||
);
|
||||
const chatsDir = join(storePath, 'chats');
|
||||
const contactsDir = join(storePath, 'contacts');
|
||||
const messagesDir = join(storePath, 'messages');
|
||||
const messageUpDir = join(storePath, 'message-up');
|
||||
const webhookDir = join(storePath, 'webhook');
|
||||
const chatwootDir = join(storePath, 'chatwoot');
|
||||
const tempDir = join(storePath, 'temp');
|
||||
|
||||
this.logger.verbose('creating chats path: ' + join(storePath, 'chats'));
|
||||
execSync(`mkdir -p ${join(storePath, 'chats')}`);
|
||||
|
||||
this.logger.verbose('creating contacts path: ' + join(storePath, 'contacts'));
|
||||
execSync(`mkdir -p ${join(storePath, 'contacts')}`);
|
||||
|
||||
this.logger.verbose('creating messages path: ' + join(storePath, 'messages'));
|
||||
execSync(`mkdir -p ${join(storePath, 'messages')}`);
|
||||
|
||||
this.logger.verbose('creating message-up path: ' + join(storePath, 'message-up'));
|
||||
execSync(`mkdir -p ${join(storePath, 'message-up')}`);
|
||||
|
||||
this.logger.verbose('creating webhook path: ' + join(storePath, 'webhook'));
|
||||
execSync(`mkdir -p ${join(storePath, 'webhook')}`);
|
||||
|
||||
this.logger.verbose('creating chatwoot path: ' + join(storePath, 'chatwoot'));
|
||||
execSync(`mkdir -p ${join(storePath, 'chatwoot')}`);
|
||||
|
||||
this.logger.verbose('creating temp path: ' + join(storePath, 'temp'));
|
||||
execSync(`mkdir -p ${join(storePath, 'temp')}`);
|
||||
// Check if directories exist, create them if not
|
||||
if (!fs.existsSync(authDir)) {
|
||||
this.logger.verbose('creating auth dir: ' + authDir);
|
||||
fs.mkdirSync(authDir, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(chatsDir)) {
|
||||
this.logger.verbose('creating chats dir: ' + chatsDir);
|
||||
fs.mkdirSync(chatsDir, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(contactsDir)) {
|
||||
this.logger.verbose('creating contacts dir: ' + contactsDir);
|
||||
fs.mkdirSync(contactsDir, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(messagesDir)) {
|
||||
this.logger.verbose('creating messages dir: ' + messagesDir);
|
||||
fs.mkdirSync(messagesDir, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(messageUpDir)) {
|
||||
this.logger.verbose('creating message-up dir: ' + messageUpDir);
|
||||
fs.mkdirSync(messageUpDir, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(webhookDir)) {
|
||||
this.logger.verbose('creating webhook dir: ' + webhookDir);
|
||||
fs.mkdirSync(webhookDir, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(chatwootDir)) {
|
||||
this.logger.verbose('creating chatwoot dir: ' + chatwootDir);
|
||||
fs.mkdirSync(chatwootDir, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(tempDir)) {
|
||||
this.logger.verbose('creating temp dir: ' + tempDir);
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { MessageRouter } from './sendMessage.router';
|
||||
import { ViewsRouter } from './view.router';
|
||||
import { WebhookRouter } from './webhook.router';
|
||||
import { ChatwootRouter } from './chatwoot.router';
|
||||
import fs from 'fs';
|
||||
|
||||
enum HttpStatus {
|
||||
OK = 200,
|
||||
@@ -24,11 +25,14 @@ const router = Router();
|
||||
const authType = configService.get<Auth>('AUTHENTICATION').TYPE;
|
||||
const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard[authType]];
|
||||
|
||||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||
|
||||
router
|
||||
.get('/', (req, res) => {
|
||||
res.status(HttpStatus.OK).json({
|
||||
status: HttpStatus.OK,
|
||||
message: 'Welcome to the Evolution API, it is working!',
|
||||
version: packageJson.version,
|
||||
});
|
||||
})
|
||||
.use(
|
||||
|
||||
@@ -23,6 +23,7 @@ export class InstanceRouter extends RouterBroker {
|
||||
|
||||
logger.verbose('request query: ');
|
||||
logger.verbose(req.query);
|
||||
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: instanceNameSchema,
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
audioMessageSchema,
|
||||
buttonMessageSchema,
|
||||
contactMessageSchema,
|
||||
linkPreviewSchema,
|
||||
listMessageSchema,
|
||||
locationMessageSchema,
|
||||
mediaMessageSchema,
|
||||
@@ -17,7 +16,6 @@ import {
|
||||
SendAudioDto,
|
||||
SendButtonDto,
|
||||
SendContactDto,
|
||||
SendLinkPreviewDto,
|
||||
SendListDto,
|
||||
SendLocationDto,
|
||||
SendMediaDto,
|
||||
@@ -199,23 +197,6 @@ export class MessageRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendLinkPreview'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in sendLinkPreview');
|
||||
logger.verbose('request body: ');
|
||||
logger.verbose(req.body);
|
||||
|
||||
logger.verbose('request query: ');
|
||||
logger.verbose(req.query);
|
||||
const response = await this.dataValidate<SendLinkPreviewDto>({
|
||||
request: req,
|
||||
schema: linkPreviewSchema,
|
||||
ClassRef: SendLinkPreviewDto,
|
||||
execute: (instance, data) =>
|
||||
sendMessageController.sendLinkPreview(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendSticker'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in sendSticker');
|
||||
logger.verbose('request body: ');
|
||||
|
||||
@@ -12,6 +12,7 @@ import mimeTypes from 'mime-types';
|
||||
import { SendAudioDto } from '../dto/sendMessage.dto';
|
||||
import { SendMediaDto } from '../dto/sendMessage.dto';
|
||||
import { ROOT_DIR } from '../../config/path.config';
|
||||
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||
|
||||
export class ChatwootService {
|
||||
private messageCacheFile: string;
|
||||
@@ -21,7 +22,10 @@ export class ChatwootService {
|
||||
|
||||
private provider: any;
|
||||
|
||||
constructor(private readonly waMonitor: WAMonitoringService) {
|
||||
constructor(
|
||||
private readonly waMonitor: WAMonitoringService,
|
||||
private readonly configService: ConfigService,
|
||||
) {
|
||||
this.messageCache = new Set();
|
||||
}
|
||||
|
||||
@@ -43,6 +47,12 @@ export class ChatwootService {
|
||||
this.logger.verbose('message cache saved');
|
||||
}
|
||||
|
||||
private clearMessageCache() {
|
||||
this.logger.verbose('clear message cache');
|
||||
this.messageCache.clear();
|
||||
this.saveMessageCache();
|
||||
}
|
||||
|
||||
private async getProvider(instance: InstanceDto) {
|
||||
this.logger.verbose('get provider to instance: ' + instance.instanceName);
|
||||
try {
|
||||
@@ -237,7 +247,7 @@ export class ChatwootService {
|
||||
accountId: this.provider.account_id,
|
||||
conversationId: conversation.id,
|
||||
data: {
|
||||
content: '/iniciar',
|
||||
content: '/init',
|
||||
message_type: 'outgoing',
|
||||
},
|
||||
});
|
||||
@@ -258,6 +268,7 @@ export class ChatwootService {
|
||||
inboxId: number,
|
||||
isGroup: boolean,
|
||||
name?: string,
|
||||
avatar_url?: string,
|
||||
) {
|
||||
this.logger.verbose('create contact to instance: ' + instance.instanceName);
|
||||
|
||||
@@ -275,6 +286,7 @@ export class ChatwootService {
|
||||
inbox_id: inboxId,
|
||||
name: name || phoneNumber,
|
||||
phone_number: `+${phoneNumber}`,
|
||||
avatar_url: avatar_url,
|
||||
};
|
||||
} else {
|
||||
this.logger.verbose('create contact group in chatwoot');
|
||||
@@ -282,6 +294,7 @@ export class ChatwootService {
|
||||
inbox_id: inboxId,
|
||||
name: name || phoneNumber,
|
||||
identifier: phoneNumber,
|
||||
avatar_url: avatar_url,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -404,34 +417,69 @@ export class ChatwootService {
|
||||
nameContact = `${group.subject} (GROUP)`;
|
||||
|
||||
this.logger.verbose('find or create participant in chatwoot');
|
||||
const participant =
|
||||
(await this.findContact(instance, body.key.participant.split('@')[0])) ||
|
||||
((await this.createContact(
|
||||
|
||||
const picture_url = await this.waMonitor.waInstances[
|
||||
instance.instanceName
|
||||
].profilePicture(body.key.participant.split('@')[0]);
|
||||
|
||||
const findParticipant = await this.findContact(
|
||||
instance,
|
||||
body.key.participant.split('@')[0],
|
||||
);
|
||||
|
||||
if (findParticipant) {
|
||||
await this.updateContact(instance, findParticipant.id, {
|
||||
name: body.pushName,
|
||||
avatar_url: picture_url.profilePictureUrl || null,
|
||||
});
|
||||
} else {
|
||||
await this.createContact(
|
||||
instance,
|
||||
body.key.participant.split('@')[0],
|
||||
filterInbox.id,
|
||||
false,
|
||||
body.pushName || body.key.participant.split('@')[0],
|
||||
)) as any);
|
||||
body.pushName,
|
||||
picture_url.profilePictureUrl || null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.verbose('find or create contact in chatwoot');
|
||||
const contact =
|
||||
(await this.findContact(instance, chatId)) ||
|
||||
((await this.createContact(
|
||||
instance,
|
||||
chatId,
|
||||
filterInbox.id,
|
||||
isGroup,
|
||||
nameContact,
|
||||
)) as any);
|
||||
|
||||
const picture_url = await this.waMonitor.waInstances[
|
||||
instance.instanceName
|
||||
].profilePicture(chatId);
|
||||
|
||||
const findContact = await this.findContact(instance, chatId);
|
||||
|
||||
let contact: any;
|
||||
if (body.key.fromMe) {
|
||||
contact = findContact;
|
||||
} else {
|
||||
if (findContact) {
|
||||
contact = await this.updateContact(instance, findContact.id, {
|
||||
name: nameContact,
|
||||
avatar_url: picture_url.profilePictureUrl || null,
|
||||
});
|
||||
} else {
|
||||
contact = await this.createContact(
|
||||
instance,
|
||||
chatId,
|
||||
filterInbox.id,
|
||||
isGroup,
|
||||
nameContact,
|
||||
picture_url.profilePictureUrl || null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!contact) {
|
||||
this.logger.warn('contact not found');
|
||||
return null;
|
||||
}
|
||||
|
||||
const contactId = contact.id || contact.payload.contact.id;
|
||||
const contactId =
|
||||
contact?.payload?.id || contact?.payload?.contact?.id || contact?.id;
|
||||
|
||||
if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) {
|
||||
this.logger.verbose('update contact name in chatwoot');
|
||||
@@ -888,8 +936,8 @@ export class ChatwootService {
|
||||
|
||||
const command = messageReceived.replace('/', '');
|
||||
|
||||
if (command === 'iniciar') {
|
||||
this.logger.verbose('command iniciar found');
|
||||
if (command === 'init' || command === 'iniciar') {
|
||||
this.logger.verbose('command init found');
|
||||
const state = waInstance?.connectionStatus?.state;
|
||||
|
||||
if (state !== 'open') {
|
||||
@@ -899,7 +947,7 @@ export class ChatwootService {
|
||||
this.logger.verbose('whatsapp already connected');
|
||||
await this.createBotMessage(
|
||||
instance,
|
||||
`🚨 Instância ${body.inbox.name} já está conectada.`,
|
||||
`🚨 ${body.inbox.name} instance is connected.`,
|
||||
'incoming',
|
||||
);
|
||||
}
|
||||
@@ -914,7 +962,7 @@ export class ChatwootService {
|
||||
this.logger.verbose('state not found');
|
||||
await this.createBotMessage(
|
||||
instance,
|
||||
`⚠️ Instância ${body.inbox.name} não existe.`,
|
||||
`⚠️ ${body.inbox.name} instance not found.`,
|
||||
'incoming',
|
||||
);
|
||||
}
|
||||
@@ -923,16 +971,16 @@ export class ChatwootService {
|
||||
this.logger.verbose('state: ' + state + ' found');
|
||||
await this.createBotMessage(
|
||||
instance,
|
||||
`⚠️ Status da instância ${body.inbox.name}: *${state}*`,
|
||||
`⚠️ ${body.inbox.name} instance status: *${state}*`,
|
||||
'incoming',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (command === 'desconectar') {
|
||||
this.logger.verbose('command desconectar found');
|
||||
if (command === 'disconnect' || command === 'desconectar') {
|
||||
this.logger.verbose('command disconnect found');
|
||||
|
||||
const msgLogout = `🚨 Desconectando Whatsapp da caixa de entrada *${body.inbox.name}*: `;
|
||||
const msgLogout = `🚨 Disconnecting Whatsapp from inbox *${body.inbox.name}*: `;
|
||||
|
||||
this.logger.verbose('send message to chatwoot');
|
||||
await this.createBotMessage(instance, msgLogout, 'incoming');
|
||||
@@ -941,6 +989,33 @@ export class ChatwootService {
|
||||
await waInstance?.client?.logout('Log out instance: ' + instance.instanceName);
|
||||
await waInstance?.client?.ws?.close();
|
||||
}
|
||||
|
||||
if (command.includes('#inbox_whatsapp')) {
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
||||
|
||||
const data = {
|
||||
instanceName: command.split(':')[1],
|
||||
qrcode: true,
|
||||
chatwoot_account_id: this.provider.account_id,
|
||||
chatwoot_token: this.provider.token,
|
||||
chatwoot_url: this.provider.url,
|
||||
chatwoot_sign_msg: this.provider.sign_msg,
|
||||
};
|
||||
|
||||
const config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: `${urlServer}/instance/create`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
apikey: apiKey,
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
|
||||
await axios.request(config);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -968,6 +1043,9 @@ export class ChatwootService {
|
||||
return { message: 'bot' };
|
||||
}
|
||||
|
||||
this.logger.verbose('clear cache');
|
||||
this.clearMessageCache();
|
||||
|
||||
this.logger.verbose('Format message to send');
|
||||
let formatText: string;
|
||||
if (senderName === null || senderName === undefined) {
|
||||
@@ -1016,7 +1094,11 @@ export class ChatwootService {
|
||||
}
|
||||
}
|
||||
|
||||
if (body.message_type === 'template' && body.content_type === 'input_csat') {
|
||||
if (
|
||||
body.message_type === 'template' &&
|
||||
body.content_type === 'input_csat' &&
|
||||
body.event === 'message_created'
|
||||
) {
|
||||
this.logger.verbose('check if is csat');
|
||||
|
||||
const data: SendTextDto = {
|
||||
@@ -1076,6 +1158,8 @@ export class ChatwootService {
|
||||
documentWithCaptionMessage:
|
||||
msg.documentWithCaptionMessage?.message?.documentMessage?.caption,
|
||||
audioMessage: msg.audioMessage?.caption,
|
||||
contactMessage: msg.contactMessage?.vcard,
|
||||
contactsArrayMessage: msg.contactsArrayMessage,
|
||||
};
|
||||
|
||||
this.logger.verbose('type message: ' + types);
|
||||
@@ -1089,6 +1173,67 @@ export class ChatwootService {
|
||||
|
||||
const result = typeKey ? types[typeKey] : undefined;
|
||||
|
||||
if (typeKey === 'contactMessage') {
|
||||
const vCardData = result.split('\n');
|
||||
const contactInfo = {};
|
||||
|
||||
vCardData.forEach((line) => {
|
||||
const [key, value] = line.split(':');
|
||||
if (key && value) {
|
||||
contactInfo[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
let formattedContact = `**Contact:**
|
||||
**name:** ${contactInfo['FN']}`;
|
||||
|
||||
let numberCount = 1;
|
||||
Object.keys(contactInfo).forEach((key) => {
|
||||
if (key.startsWith('item') && key.includes('TEL')) {
|
||||
const phoneNumber = contactInfo[key];
|
||||
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
|
||||
numberCount++;
|
||||
}
|
||||
});
|
||||
|
||||
this.logger.verbose('message content: ' + formattedContact);
|
||||
return formattedContact;
|
||||
}
|
||||
|
||||
if (typeKey === 'contactsArrayMessage') {
|
||||
const formattedContacts = result.contacts.map((contact) => {
|
||||
const vCardData = contact.vcard.split('\n');
|
||||
const contactInfo = {};
|
||||
|
||||
vCardData.forEach((line) => {
|
||||
const [key, value] = line.split(':');
|
||||
if (key && value) {
|
||||
contactInfo[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
let formattedContact = `**Contact:**
|
||||
**name:** ${contact.displayName}`;
|
||||
|
||||
let numberCount = 1;
|
||||
Object.keys(contactInfo).forEach((key) => {
|
||||
if (key.startsWith('item') && key.includes('TEL')) {
|
||||
const phoneNumber = contactInfo[key];
|
||||
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
|
||||
numberCount++;
|
||||
}
|
||||
});
|
||||
|
||||
return formattedContact;
|
||||
});
|
||||
|
||||
const formattedContactsArray = formattedContacts.join('\n\n');
|
||||
|
||||
this.logger.verbose('formatted contacts: ' + formattedContactsArray);
|
||||
|
||||
return formattedContactsArray;
|
||||
}
|
||||
|
||||
this.logger.verbose('message content: ' + result);
|
||||
|
||||
return result;
|
||||
@@ -1343,7 +1488,7 @@ export class ChatwootService {
|
||||
return;
|
||||
}
|
||||
|
||||
const msgStatus = `⚡️ Status da instância ${inbox.name}: ${data.status}`;
|
||||
const msgStatus = `⚡️ Instance status ${inbox.name}: ${data.status}`;
|
||||
|
||||
this.logger.verbose('send message to chatwoot');
|
||||
await this.createBotMessage(instance, msgStatus, 'incoming');
|
||||
@@ -1351,43 +1496,20 @@ export class ChatwootService {
|
||||
|
||||
if (event === 'connection.update') {
|
||||
this.logger.verbose('event connection.update');
|
||||
if (body.state === 'open') {
|
||||
const msgConnection = `🚀 Conexão realizada com sucesso!`;
|
||||
|
||||
if (body.status === 'open') {
|
||||
const msgConnection = `🚀 Connection successfully established!`;
|
||||
|
||||
this.logger.verbose('send message to chatwoot');
|
||||
await this.createBotMessage(instance, msgConnection, 'incoming');
|
||||
}
|
||||
}
|
||||
|
||||
if (event === 'contacts.update') {
|
||||
this.logger.verbose('event contacts.update');
|
||||
const data = body;
|
||||
|
||||
if (data.length) {
|
||||
this.logger.verbose('contacts found');
|
||||
for (const item of data) {
|
||||
const number = item.id.split('@')[0];
|
||||
const photo = item.profilePictureUrl || null;
|
||||
this.logger.verbose('find contact in chatwoot');
|
||||
const find = await this.findContact(instance, number);
|
||||
|
||||
if (find) {
|
||||
this.logger.verbose('contact found');
|
||||
|
||||
this.logger.verbose('update contact in chatwoot');
|
||||
await this.updateContact(instance, find.id, {
|
||||
avatar_url: photo,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event === 'qrcode.updated') {
|
||||
this.logger.verbose('event qrcode.updated');
|
||||
if (body.statusCode === 500) {
|
||||
this.logger.verbose('qrcode error');
|
||||
const erroQRcode = `🚨 Limite de geração de QRCode atingido, para gerar um novo QRCode, envie a mensagem /iniciar novamente.`;
|
||||
const erroQRcode = `🚨 QRCode generation limit reached, to generate a new QRCode, send the /init message again.`;
|
||||
|
||||
this.logger.verbose('send message to chatwoot');
|
||||
return await this.createBotMessage(instance, erroQRcode, 'incoming');
|
||||
@@ -1412,12 +1534,12 @@ export class ChatwootService {
|
||||
this.logger.verbose('send qrcode to chatwoot');
|
||||
await this.createBotQr(
|
||||
instance,
|
||||
'QRCode gerado com sucesso!',
|
||||
'QRCode successfully generated!',
|
||||
'incoming',
|
||||
fileName,
|
||||
);
|
||||
|
||||
const msgQrCode = `⚡️ QRCode gerado com sucesso!\n\nDigitalize este código QR nos próximos 40 segundos:`;
|
||||
const msgQrCode = `⚡️ QRCode successfully generated!\n\nScan this QR code within the next 40 seconds:`;
|
||||
|
||||
this.logger.verbose('send message to chatwoot');
|
||||
await this.createBotMessage(instance, msgQrCode, 'incoming');
|
||||
|
||||
@@ -99,72 +99,54 @@ export class WAMonitoringService {
|
||||
|
||||
if (value.connectionStatus.state === 'open') {
|
||||
this.logger.verbose('instance: ' + key + ' - connectionStatus: open');
|
||||
let apikey: string;
|
||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||
this.logger.verbose(
|
||||
'instance: ' + key + ' - hash exposed in fetch instances',
|
||||
);
|
||||
const tokenStore = await this.repository.auth.find(key);
|
||||
apikey = tokenStore.apikey || 'Apikey not found';
|
||||
|
||||
instances.push({
|
||||
instance: {
|
||||
instanceName: key,
|
||||
owner: value.wuid,
|
||||
profileName: (await value.getProfileName()) || 'not loaded',
|
||||
profilePictureUrl: value.profilePictureUrl,
|
||||
profileStatus: (await value.getProfileStatus()) || '',
|
||||
status: value.connectionStatus.state,
|
||||
apikey,
|
||||
chatwoot,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.logger.verbose(
|
||||
'instance: ' + key + ' - hash not exposed in fetch instances',
|
||||
);
|
||||
instances.push({
|
||||
instance: {
|
||||
instanceName: key,
|
||||
owner: value.wuid,
|
||||
profileName: (await value.getProfileName()) || 'not loaded',
|
||||
profilePictureUrl: value.profilePictureUrl,
|
||||
profileStatus: (await value.getProfileStatus()) || '',
|
||||
status: value.connectionStatus.state,
|
||||
},
|
||||
});
|
||||
const instanceData = {
|
||||
instance: {
|
||||
instanceName: key,
|
||||
owner: value.wuid,
|
||||
profileName: (await value.getProfileName()) || 'not loaded',
|
||||
profilePictureUrl: value.profilePictureUrl,
|
||||
profileStatus: (await value.getProfileStatus()) || '',
|
||||
status: value.connectionStatus.state,
|
||||
},
|
||||
};
|
||||
|
||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||
instanceData.instance['serverUrl'] =
|
||||
this.configService.get<HttpServer>('SERVER').URL;
|
||||
|
||||
instanceData.instance['apikey'] = (
|
||||
await this.repository.auth.find(key)
|
||||
).apikey;
|
||||
|
||||
instanceData.instance['chatwoot'] = chatwoot;
|
||||
}
|
||||
|
||||
instances.push(instanceData);
|
||||
} else {
|
||||
this.logger.verbose(
|
||||
'instance: ' + key + ' - connectionStatus: ' + value.connectionStatus.state,
|
||||
);
|
||||
let apikey: string;
|
||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||
this.logger.verbose(
|
||||
'instance: ' + key + ' - hash exposed in fetch instances',
|
||||
);
|
||||
const tokenStore = await this.repository.auth.find(key);
|
||||
apikey = tokenStore.apikey || 'Apikey not found';
|
||||
|
||||
instances.push({
|
||||
instance: {
|
||||
instanceName: key,
|
||||
status: value.connectionStatus.state,
|
||||
apikey,
|
||||
chatwoot,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.logger.verbose(
|
||||
'instance: ' + key + ' - hash not exposed in fetch instances',
|
||||
);
|
||||
instances.push({
|
||||
instance: {
|
||||
instanceName: key,
|
||||
status: value.connectionStatus.state,
|
||||
},
|
||||
});
|
||||
const instanceData = {
|
||||
instance: {
|
||||
instanceName: key,
|
||||
status: value.connectionStatus.state,
|
||||
},
|
||||
};
|
||||
|
||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||
instanceData.instance['serverUrl'] =
|
||||
this.configService.get<HttpServer>('SERVER').URL;
|
||||
|
||||
instanceData.instance['apikey'] = (
|
||||
await this.repository.auth.find(key)
|
||||
).apikey;
|
||||
|
||||
instanceData.instance['chatwoot'] = chatwoot;
|
||||
}
|
||||
|
||||
instances.push(instanceData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,17 @@ export class WebhookService {
|
||||
public async find(instance: InstanceDto): Promise<WebhookDto> {
|
||||
try {
|
||||
this.logger.verbose('find webhook: ' + instance.instanceName);
|
||||
return await this.waMonitor.waInstances[instance.instanceName].findWebhook();
|
||||
const result = await this.waMonitor.waInstances[
|
||||
instance.instanceName
|
||||
].findWebhook();
|
||||
|
||||
if (Object.keys(result).length === 0) {
|
||||
throw new Error('Webhook not found');
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
return { enabled: null, url: '' };
|
||||
return { enabled: false, url: '', events: [], webhook_by_events: false };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ import {
|
||||
SendReactionDto,
|
||||
SendTextDto,
|
||||
SendPollDto,
|
||||
SendLinkPreviewDto,
|
||||
SendStickerDto,
|
||||
SendStatusDto,
|
||||
StatusMessage,
|
||||
@@ -150,7 +149,7 @@ export class WAStartupService {
|
||||
private endSession = false;
|
||||
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
|
||||
|
||||
private chatwootService = new ChatwootService(waMonitor);
|
||||
private chatwootService = new ChatwootService(waMonitor, this.configService);
|
||||
|
||||
public set instanceName(name: string) {
|
||||
this.logger.verbose(`Initializing instance '${name}'`);
|
||||
@@ -343,12 +342,19 @@ export class WAStartupService {
|
||||
|
||||
public async sendDataWebhook<T = any>(event: Events, data: T, local = true) {
|
||||
const webhookGlobal = this.configService.get<Webhook>('WEBHOOK');
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const webhookLocal = this.localWebhook.events;
|
||||
const serverUrl = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const we = event.replace(/[\.-]/gm, '_').toUpperCase();
|
||||
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
||||
const instance = this.configService.get<Auth>('AUTHENTICATION').INSTANCE;
|
||||
|
||||
const expose =
|
||||
this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES;
|
||||
const tokenStore = await this.repository.auth.find(this.instanceName);
|
||||
const instanceApikey = tokenStore.apikey || 'Apikey not found';
|
||||
|
||||
const globalApiKey = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
|
||||
|
||||
if (local && instance.MODE !== 'container') {
|
||||
if (Array.isArray(webhookLocal) && webhookLocal.includes(we)) {
|
||||
this.logger.verbose('Sending data to webhook local');
|
||||
@@ -361,27 +367,40 @@ export class WAStartupService {
|
||||
}
|
||||
|
||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||
this.logger.log({
|
||||
const logData = {
|
||||
local: WAStartupService.name + '.sendDataWebhook-local',
|
||||
url: baseURL,
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
destination: this.localWebhook.url,
|
||||
urlServer,
|
||||
});
|
||||
server_url: serverUrl,
|
||||
apikey: (expose && instanceApikey) || null,
|
||||
};
|
||||
|
||||
if (expose && instanceApikey) {
|
||||
logData['apikey'] = instanceApikey;
|
||||
}
|
||||
|
||||
this.logger.log(logData);
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.localWebhook.enabled && isURL(this.localWebhook.url)) {
|
||||
const httpService = axios.create({ baseURL });
|
||||
await httpService.post('', {
|
||||
const postData = {
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
destination: this.localWebhook.url,
|
||||
urlServer,
|
||||
});
|
||||
server_url: serverUrl,
|
||||
};
|
||||
|
||||
if (expose && instanceApikey) {
|
||||
postData['apikey'] = instanceApikey;
|
||||
}
|
||||
|
||||
await httpService.post('', postData);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
@@ -394,6 +413,7 @@ export class WAStartupService {
|
||||
stack: error?.stack,
|
||||
name: error?.name,
|
||||
url: baseURL,
|
||||
server_url: serverUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -421,27 +441,39 @@ export class WAStartupService {
|
||||
}
|
||||
|
||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||
this.logger.log({
|
||||
const logData = {
|
||||
local: WAStartupService.name + '.sendDataWebhook-global',
|
||||
url: globalURL,
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
destination: localUrl,
|
||||
urlServer,
|
||||
});
|
||||
server_url: serverUrl,
|
||||
};
|
||||
|
||||
if (expose && globalApiKey) {
|
||||
logData['apikey'] = globalApiKey;
|
||||
}
|
||||
|
||||
this.logger.log(logData);
|
||||
}
|
||||
|
||||
try {
|
||||
if (globalWebhook && globalWebhook?.ENABLED && isURL(globalURL)) {
|
||||
const httpService = axios.create({ baseURL: globalURL });
|
||||
await httpService.post('', {
|
||||
const postData = {
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
destination: localUrl,
|
||||
urlServer,
|
||||
});
|
||||
server_url: serverUrl,
|
||||
};
|
||||
|
||||
if (expose && globalApiKey) {
|
||||
postData['apikey'] = globalApiKey;
|
||||
}
|
||||
|
||||
await httpService.post('', postData);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
@@ -454,6 +486,7 @@ export class WAStartupService {
|
||||
stack: error?.stack,
|
||||
name: error?.name,
|
||||
url: globalURL,
|
||||
server_url: serverUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -623,6 +656,17 @@ export class WAStartupService {
|
||||
│ CONNECTED TO WHATSAPP │
|
||||
└──────────────────────────────┘`.replace(/^ +/gm, ' '),
|
||||
);
|
||||
|
||||
if (this.localChatwoot.enabled) {
|
||||
this.chatwootService.eventWhatsapp(
|
||||
Events.CONNECTION_UPDATE,
|
||||
{ instanceName: this.instance.name },
|
||||
{
|
||||
instance: this.instance.name,
|
||||
status: 'open',
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,6 +785,7 @@ export class WAStartupService {
|
||||
version,
|
||||
connectTimeoutMs: 60_000,
|
||||
qrTimeout: 40_000,
|
||||
defaultQueryTimeoutMs: undefined,
|
||||
emitOwnEvents: false,
|
||||
msgRetryCounterCache: this.msgRetryCounterCache,
|
||||
getMessage: async (key) =>
|
||||
@@ -908,14 +953,6 @@ export class WAStartupService {
|
||||
this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE');
|
||||
await this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw);
|
||||
|
||||
if (this.localChatwoot.enabled) {
|
||||
await this.chatwootService.eventWhatsapp(
|
||||
Events.CONTACTS_UPDATE,
|
||||
{ instanceName: this.instance.name },
|
||||
contactsRaw,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.verbose('Updating contacts in database');
|
||||
await this.repository.contact.update(
|
||||
contactsRaw,
|
||||
@@ -1126,11 +1163,7 @@ export class WAStartupService {
|
||||
5: 'PLAYED',
|
||||
};
|
||||
for await (const { key, update } of args) {
|
||||
if (
|
||||
key.remoteJid !== 'status@broadcast' &&
|
||||
!key?.remoteJid?.match(/(:\d+)/) &&
|
||||
key.fromMe
|
||||
) {
|
||||
if (key.remoteJid !== 'status@broadcast' && !key?.remoteJid?.match(/(:\d+)/)) {
|
||||
this.logger.verbose('Message update is valid');
|
||||
|
||||
let pollUpdates: any;
|
||||
@@ -1150,6 +1183,16 @@ export class WAStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
if (status[update.status] === 'READ' && !key.fromMe) return;
|
||||
|
||||
if (update.message === null && update.status === undefined) {
|
||||
this.logger.verbose('Message deleted');
|
||||
|
||||
this.logger.verbose('Sending data to webhook in event MESSAGE_DELETE');
|
||||
await this.sendDataWebhook(Events.MESSAGES_DELETE, key);
|
||||
return;
|
||||
}
|
||||
|
||||
const message: MessageUpdateRaw = {
|
||||
...key,
|
||||
status: status[update.status],
|
||||
@@ -1294,16 +1337,12 @@ export class WAStartupService {
|
||||
|
||||
// Check if the number is MX or AR
|
||||
private formatMXOrARNumber(jid: string): string {
|
||||
const regexp = new RegExp(/^(\d{2})(\d{2})\d{1}(\d{8})$/);
|
||||
if (regexp.test(jid)) {
|
||||
const match = regexp.exec(jid);
|
||||
if (match && (match[1] === '52' || match[1] === '54')) {
|
||||
const joker = Number.parseInt(match[3][0]);
|
||||
const ddd = Number.parseInt(match[2]);
|
||||
if (joker < 7 || ddd < 11) {
|
||||
return match[0];
|
||||
}
|
||||
return match[1] === '52' ? '52' + match[3] : '54' + match[3];
|
||||
const countryCode = jid.substring(0, 2);
|
||||
|
||||
if (Number(countryCode) === 52 || Number(countryCode) === 54) {
|
||||
if (jid.length === 13) {
|
||||
const number = countryCode + jid.substring(3);
|
||||
return number;
|
||||
}
|
||||
|
||||
return jid;
|
||||
@@ -1332,6 +1371,7 @@ export class WAStartupService {
|
||||
|
||||
private createJid(number: string): string {
|
||||
this.logger.verbose('Creating jid with number: ' + number);
|
||||
|
||||
if (number.includes('@g.us') || number.includes('@s.whatsapp.net')) {
|
||||
this.logger.verbose('Number already contains @g.us or @s.whatsapp.net');
|
||||
return number;
|
||||
@@ -1342,22 +1382,31 @@ export class WAStartupService {
|
||||
return number;
|
||||
}
|
||||
|
||||
const formattedBRNumber = this.formatBRNumber(number);
|
||||
if (formattedBRNumber !== number) {
|
||||
this.logger.verbose(
|
||||
'Jid created is whatsapp in format BR: ' + `${formattedBRNumber}@s.whatsapp.net`,
|
||||
);
|
||||
return `${formattedBRNumber}@s.whatsapp.net`;
|
||||
const countryCode = number.substring(0, 2);
|
||||
|
||||
if (Number(countryCode) === 55) {
|
||||
const formattedBRNumber = this.formatBRNumber(number);
|
||||
if (formattedBRNumber !== number) {
|
||||
this.logger.verbose(
|
||||
'Jid created is whatsapp in format BR: ' +
|
||||
`${formattedBRNumber}@s.whatsapp.net`,
|
||||
);
|
||||
return `${formattedBRNumber}@s.whatsapp.net`;
|
||||
}
|
||||
}
|
||||
|
||||
const formattedMXARNumber = this.formatMXOrARNumber(number);
|
||||
if (Number(countryCode) === 52 || Number(countryCode) === 54) {
|
||||
console.log('numero mexicano');
|
||||
|
||||
if (formattedMXARNumber !== number) {
|
||||
this.logger.verbose(
|
||||
'Jid created is whatsapp in format MXAR: ' +
|
||||
`${formattedMXARNumber}@s.whatsapp.net`,
|
||||
);
|
||||
return `${formattedMXARNumber}@s.whatsapp.net`;
|
||||
const formattedMXARNumber = this.formatMXOrARNumber(number);
|
||||
|
||||
if (formattedMXARNumber !== number) {
|
||||
this.logger.verbose(
|
||||
'Jid created is whatsapp in format MXAR: ' +
|
||||
`${formattedMXARNumber}@s.whatsapp.net`,
|
||||
);
|
||||
return `${formattedMXARNumber}@s.whatsapp.net`;
|
||||
}
|
||||
}
|
||||
|
||||
if (number.includes('-')) {
|
||||
@@ -1427,13 +1476,29 @@ export class WAStartupService {
|
||||
let quoted: WAMessage;
|
||||
|
||||
if (options?.quoted) {
|
||||
quoted = options?.quoted;
|
||||
const m = options?.quoted;
|
||||
|
||||
const msg = m?.message
|
||||
? m
|
||||
: ((await this.getMessage(m.key, true)) as proto.IWebMessageInfo);
|
||||
|
||||
if (!msg) {
|
||||
throw 'Message not found';
|
||||
}
|
||||
|
||||
quoted = msg;
|
||||
this.logger.verbose('Quoted message');
|
||||
}
|
||||
|
||||
let mentions: string[];
|
||||
if (isJidGroup(sender)) {
|
||||
try {
|
||||
const groupMetadata = await this.client.groupMetadata(sender);
|
||||
|
||||
if (!groupMetadata) {
|
||||
throw new NotFoundException('Group not found');
|
||||
}
|
||||
|
||||
if (options?.mentions) {
|
||||
this.logger.verbose('Mentions defined');
|
||||
|
||||
@@ -1448,7 +1513,6 @@ export class WAStartupService {
|
||||
this.logger.verbose('Mentions everyone');
|
||||
|
||||
this.logger.verbose('Getting group metadata');
|
||||
const groupMetadata = await this.client.groupMetadata(sender);
|
||||
mentions = groupMetadata.participants.map((participant) => participant.id);
|
||||
this.logger.verbose('Getting group metadata for mentions');
|
||||
} else {
|
||||
@@ -1475,9 +1539,9 @@ export class WAStartupService {
|
||||
if (
|
||||
!message['audio'] &&
|
||||
!message['poll'] &&
|
||||
!message['linkPreview'] &&
|
||||
!message['sticker'] &&
|
||||
!sender.includes('@broadcast')
|
||||
!message['conversation'] &&
|
||||
sender !== 'status@broadcast'
|
||||
) {
|
||||
if (!message['audio']) {
|
||||
this.logger.verbose('Sending message');
|
||||
@@ -1495,18 +1559,19 @@ export class WAStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
if (message['linkPreview']) {
|
||||
if (message['conversation']) {
|
||||
this.logger.verbose('Sending message');
|
||||
return await this.client.sendMessage(
|
||||
sender,
|
||||
{
|
||||
text: message['linkPreview'].text,
|
||||
text: message['conversation'],
|
||||
mentions,
|
||||
} as unknown as AnyMessageContent,
|
||||
option as unknown as MiscMessageGenerationOptions,
|
||||
);
|
||||
}
|
||||
|
||||
if (sender.includes('@broadcast')) {
|
||||
if (sender === 'status@broadcast') {
|
||||
this.logger.verbose('Sending message');
|
||||
return await this.client.sendMessage(
|
||||
sender,
|
||||
@@ -1582,19 +1647,6 @@ export class WAStartupService {
|
||||
);
|
||||
}
|
||||
|
||||
public async linkPreview(data: SendLinkPreviewDto) {
|
||||
this.logger.verbose('Sending link preview');
|
||||
return await this.sendMessageWithTyping(
|
||||
data.number,
|
||||
{
|
||||
linkPreview: {
|
||||
text: data.linkPreview.text,
|
||||
},
|
||||
},
|
||||
data?.options,
|
||||
);
|
||||
}
|
||||
|
||||
public async pollMessage(data: SendPollDto) {
|
||||
this.logger.verbose('Sending poll message');
|
||||
return await this.sendMessageWithTyping(
|
||||
@@ -1730,8 +1782,10 @@ export class WAStartupService {
|
||||
|
||||
public async statusMessage(data: SendStatusDto) {
|
||||
this.logger.verbose('Sending status message');
|
||||
const status = await this.formatStatusMessage(data.statusMessage);
|
||||
|
||||
return await this.sendMessageWithTyping('status@broadcast', {
|
||||
status: await this.formatStatusMessage(data.statusMessage),
|
||||
status,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2110,6 +2164,7 @@ export class WAStartupService {
|
||||
const onWhatsapp: OnWhatsAppDto[] = [];
|
||||
for await (const number of data.numbers) {
|
||||
const jid = this.createJid(number);
|
||||
// const jid = `${number}@s.whatsapp.net`;
|
||||
if (isJidGroup(jid)) {
|
||||
const group = await this.findGroup({ groupJid: jid }, 'inner');
|
||||
|
||||
@@ -2645,9 +2700,7 @@ export class WAStartupService {
|
||||
const msg = `${description}\n\n${inviteUrl}`;
|
||||
|
||||
const message = {
|
||||
linkPreview: {
|
||||
text: msg,
|
||||
},
|
||||
conversation: msg,
|
||||
};
|
||||
|
||||
for await (const number of numbers) {
|
||||
|
||||
@@ -9,6 +9,7 @@ export enum Events {
|
||||
MESSAGES_SET = 'messages.set',
|
||||
MESSAGES_UPSERT = 'messages.upsert',
|
||||
MESSAGES_UPDATE = 'messages.update',
|
||||
MESSAGES_DELETE = 'messages.delete',
|
||||
SEND_MESSAGE = 'send.message',
|
||||
CONTACTS_SET = 'contacts.set',
|
||||
CONTACTS_UPSERT = 'contacts.upsert',
|
||||
|
||||
@@ -72,7 +72,7 @@ const webhookService = new WebhookService(waMonitor);
|
||||
|
||||
export const webhookController = new WebhookController(webhookService);
|
||||
|
||||
const chatwootService = new ChatwootService(waMonitor);
|
||||
const chatwootService = new ChatwootService(waMonitor, configService);
|
||||
|
||||
export const chatwootController = new ChatwootController(chatwootService, configService);
|
||||
|
||||
@@ -116,16 +116,16 @@ export async function initInstance() {
|
||||
configService.get<Auth>('AUTHENTICATION').INSTANCE.WEBHOOK_URL;
|
||||
logger.verbose('Instance webhook: ' + instanceWebhook);
|
||||
|
||||
const chatwootAccountId =
|
||||
configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_ACCOUNT_ID;
|
||||
logger.verbose('Chatwoot account id: ' + chatwootAccountId);
|
||||
// const chatwootAccountId =
|
||||
// configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_ACCOUNT_ID;
|
||||
// logger.verbose('Chatwoot account id: ' + chatwootAccountId);
|
||||
|
||||
const chatwootToken =
|
||||
configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_TOKEN;
|
||||
logger.verbose('Chatwoot token: ' + chatwootToken);
|
||||
// const chatwootToken =
|
||||
// configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_TOKEN;
|
||||
// logger.verbose('Chatwoot token: ' + chatwootToken);
|
||||
|
||||
const chatwootUrl = configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_URL;
|
||||
logger.verbose('Chatwoot url: ' + chatwootUrl);
|
||||
// const chatwootUrl = configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_URL;
|
||||
// logger.verbose('Chatwoot url: ' + chatwootUrl);
|
||||
|
||||
instance.instanceName = instanceName;
|
||||
|
||||
@@ -148,21 +148,21 @@ export async function initInstance() {
|
||||
}
|
||||
}
|
||||
|
||||
if (chatwootUrl && chatwootToken && chatwootAccountId) {
|
||||
logger.verbose('Creating chatwoot for instance: ' + instanceName);
|
||||
try {
|
||||
chatwootService.create(instance, {
|
||||
enabled: true,
|
||||
url: chatwootUrl,
|
||||
token: chatwootToken,
|
||||
account_id: chatwootAccountId,
|
||||
sign_msg: false,
|
||||
});
|
||||
logger.verbose('Chatwoot created');
|
||||
} catch (error) {
|
||||
logger.log(error);
|
||||
}
|
||||
}
|
||||
// if (chatwootUrl && chatwootToken && chatwootAccountId) {
|
||||
// logger.verbose('Creating chatwoot for instance: ' + instanceName);
|
||||
// try {
|
||||
// chatwootService.create(instance, {
|
||||
// enabled: true,
|
||||
// url: chatwootUrl,
|
||||
// token: chatwootToken,
|
||||
// account_id: chatwootAccountId,
|
||||
// sign_msg: false,
|
||||
// });
|
||||
// logger.verbose('Chatwoot created');
|
||||
// } catch (error) {
|
||||
// logger.log(error);
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
const state = instance.connectionStatus?.state;
|
||||
|
||||
Reference in New Issue
Block a user