mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 11:52:20 -06:00
Compare commits
130 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3545b80050 | ||
|
|
379855714e | ||
|
|
ff06cd7643 | ||
|
|
ade3952016 | ||
|
|
f246516a6e | ||
|
|
c296bf4178 | ||
|
|
1568554a1c | ||
|
|
ae66be197e | ||
|
|
3e904aa160 | ||
|
|
64c1440c46 | ||
|
|
f069a41390 | ||
|
|
d4a33e2290 | ||
|
|
7ee5bcecff | ||
|
|
48f6ee8846 | ||
|
|
7a24f52782 | ||
|
|
324d46120b | ||
|
|
87baec5ff8 | ||
|
|
b2e144f35c | ||
|
|
87a8e25662 | ||
|
|
8e88f00fb2 | ||
|
|
d14505d59a | ||
|
|
1e6d4347fa | ||
|
|
b8d9a8c072 | ||
|
|
fd15ae5e8c | ||
|
|
fb6377414b | ||
|
|
9a5dbe055e | ||
|
|
42dd280aca | ||
|
|
41b2946cdc | ||
|
|
a90f0f2c59 | ||
|
|
4222c0e53b | ||
|
|
ee0f0f0be0 | ||
|
|
f8d874453c | ||
|
|
aa891489f0 | ||
|
|
4c69b059d4 | ||
|
|
359bd9f762 | ||
|
|
2de0b61726 | ||
|
|
d75163aa57 | ||
|
|
e49f30641e | ||
|
|
1631c2c342 | ||
|
|
cf7de369b2 | ||
|
|
78c03d8f2f | ||
|
|
876320b849 | ||
|
|
a1d13f8ff3 | ||
|
|
3c19bdfaa9 | ||
|
|
4fa895086e | ||
|
|
9945d8debb | ||
|
|
4362de2198 | ||
|
|
a5c5879e4f | ||
|
|
1a57f4f33d | ||
|
|
a99e173168 | ||
|
|
e02a28f61e | ||
|
|
26d3ff97ce | ||
|
|
57fb3c9785 | ||
|
|
edeb970a82 | ||
|
|
e17baddf01 | ||
|
|
a277d36696 | ||
|
|
6c9e86e17a | ||
|
|
e75ef21eb6 | ||
|
|
04e5443b82 | ||
|
|
8b4cdf3b9b | ||
|
|
37f1620f7c | ||
|
|
b0a0e805cf | ||
|
|
c619e253a2 | ||
|
|
2bd111f1e2 | ||
|
|
40174b50eb | ||
|
|
e0fe28717f | ||
|
|
ac5fc22043 | ||
|
|
e30f196dad | ||
|
|
9e4e1ce8ec | ||
|
|
f710898844 | ||
|
|
94633484ca | ||
|
|
0817c2589f | ||
|
|
8a99386b33 | ||
|
|
52d6a563d6 | ||
|
|
d0a5ae1da4 | ||
|
|
783c00a1d9 | ||
|
|
bc70ec8b07 | ||
|
|
50e1efe5d7 | ||
|
|
d8629e53f1 | ||
|
|
cc9df1dabb | ||
|
|
cd6cb8182e | ||
|
|
5b0e90e5b9 | ||
|
|
3c3bbc84b3 | ||
|
|
23615cff4f | ||
|
|
daadc6cb68 | ||
|
|
e157a2a36b | ||
|
|
d8d7debfee | ||
|
|
a82b206fe6 | ||
|
|
a4416214c8 | ||
|
|
8fe75cd210 | ||
|
|
303effebbc | ||
|
|
f32a34190d | ||
|
|
8588ef1d8a | ||
|
|
51ec4821f3 | ||
|
|
957033a7bb | ||
|
|
62c74deac3 | ||
|
|
29fd448998 | ||
|
|
e55cb08a6a | ||
|
|
047359e8dc | ||
|
|
eb814e181a | ||
|
|
857031ff5a | ||
|
|
d5eeb68714 | ||
|
|
966b287026 | ||
|
|
a348729109 | ||
|
|
1f29b7733e | ||
|
|
e26ae30f6f | ||
|
|
547943a05c | ||
|
|
46aa229531 | ||
|
|
28bd796289 | ||
|
|
6a3f82ed7e | ||
|
|
523f3301c0 | ||
|
|
f085343a99 | ||
|
|
f76a924700 | ||
|
|
f8e3b76a4a | ||
|
|
b8f1e8a7ef | ||
|
|
d007fc49d8 | ||
|
|
f6d8ebd8d3 | ||
|
|
6ff9c4578a | ||
|
|
33acfe1464 | ||
|
|
f5eeb16bb1 | ||
|
|
c35c5faaa4 | ||
|
|
8425ebc13f | ||
|
|
6fc37a4298 | ||
|
|
99f3e77c12 | ||
|
|
a9c087c45f | ||
|
|
3f4333087f | ||
|
|
e1ac29683d | ||
|
|
5c74cbfe19 | ||
|
|
3fdb3fa673 | ||
|
|
ba584974cb |
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@@ -5,7 +5,9 @@
|
|||||||
"editor.smoothScrolling": true,
|
"editor.smoothScrolling": true,
|
||||||
"editor.tabSize": 2,
|
"editor.tabSize": 2,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true,
|
"source.fixAll.eslint": "explicit",
|
||||||
"source.fixAll": true
|
"source.fixAll": "explicit"
|
||||||
}
|
},
|
||||||
|
"prisma-smart-formatter.typescript.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"prisma-smart-formatter.prisma.defaultFormatter": "Prisma.prisma"
|
||||||
}
|
}
|
||||||
65
CHANGELOG.md
65
CHANGELOG.md
@@ -1,3 +1,68 @@
|
|||||||
|
# 1.6.1 (develop)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed Lid Messages
|
||||||
|
|
||||||
|
# 1.6.0 (2023-12-12 17:24)
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
* Added AWS SQS Integration
|
||||||
|
* Added support for new typebot API
|
||||||
|
* Added endpoint sendPresence
|
||||||
|
* New Instance Manager
|
||||||
|
* Added auto_create to the chatwoot set to create the inbox automatically or not
|
||||||
|
* Added reply, delete and message reaction in chatwoot v3.3.1
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Adjusts in proxy
|
||||||
|
* Adjusts in start session for Typebot
|
||||||
|
* Added mimetype field when sending media
|
||||||
|
* Ajusts in validations to messages.upsert
|
||||||
|
* Fixed messages not received: error handling when updating contact in chatwoot
|
||||||
|
* Fix workaround to manage param data as an array in mongodb
|
||||||
|
* Removed await from webhook when sending a message
|
||||||
|
* Update typebot.service.ts - element.underline change ~ for *
|
||||||
|
* Adjusts in proxy
|
||||||
|
* Removed api restart on receiving an error
|
||||||
|
* Fixes in mongodb and chatwoot
|
||||||
|
* Adjusted return from queries in mongodb
|
||||||
|
* Added restart instance when update profile picture
|
||||||
|
* Correction of chatwoot functioning with admin flows
|
||||||
|
* Fixed problem that did not generate qrcode with the chatwoot_conversation_pending option enabled
|
||||||
|
* Fixed issue where CSAT opened a new ticket when reopen_conversation was disabled
|
||||||
|
* Fixed issue sending contact to Chatwoot via iOS
|
||||||
|
|
||||||
|
### Integrations
|
||||||
|
|
||||||
|
- Chatwoot: v3.3.1
|
||||||
|
- Typebot: v2.20.0
|
||||||
|
|
||||||
|
# 1.5.4 (2023-10-09 20:43)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Baileys logger typing issue resolved
|
||||||
|
* Solved problem with duplicate messages in chatwoot
|
||||||
|
|
||||||
|
# 1.5.3 (2023-10-06 18:55)
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
|
||||||
|
* Swagger documentation
|
||||||
|
* Added base 64 sending option via webhook
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Remove rabbitmq queues when delete instances
|
||||||
|
* Improvement in restart instance to completely redo the connection
|
||||||
|
* Update node version: v20
|
||||||
|
* Correction of messages sent by the api and typebot not appearing in chatwoot
|
||||||
|
* Adjustment to start typebot, added startSession parameter
|
||||||
|
* Chatwoot now receives messages sent via api and typebot
|
||||||
|
* Fixed problem with starting with an input in typebot
|
||||||
|
* Added check to ensure variables are not empty before executing foreach in start typebot
|
||||||
|
|
||||||
# 1.5.2 (2023-09-28 17:56)
|
# 1.5.2 (2023-09-28 17:56)
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
|||||||
|
|
||||||
WEBSOCKET_ENABLED=false
|
WEBSOCKET_ENABLED=false
|
||||||
|
|
||||||
|
SQS_ENABLED=false
|
||||||
|
SQS_ACCESS_KEY_ID=
|
||||||
|
SQS_SECRET_ACCESS_KEY=
|
||||||
|
SQS_ACCOUNT_ID=
|
||||||
|
SQS_REGION=
|
||||||
|
|
||||||
# Global Webhook Settings
|
# Global Webhook Settings
|
||||||
# Each instance's Webhook URL and events will be requested at the time it is created
|
# 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
|
## Define a global webhook that will listen for enabled events from all instances
|
||||||
@@ -99,6 +105,9 @@ CONFIG_SESSION_PHONE_NAME=Chrome
|
|||||||
QRCODE_LIMIT=30
|
QRCODE_LIMIT=30
|
||||||
QRCODE_COLOR=#198754
|
QRCODE_COLOR=#198754
|
||||||
|
|
||||||
|
# old | latest
|
||||||
|
TYPEBOT_API_VERSION=latest
|
||||||
|
|
||||||
# Defines an authentication type for the api
|
# Defines an authentication type for the api
|
||||||
# We recommend using the apikey because it will allow you to use a custom token,
|
# 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
|
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
|
||||||
|
|||||||
12
Dockerfile
12
Dockerfile
@@ -1,6 +1,6 @@
|
|||||||
FROM node:16.18-alpine
|
FROM node:20.7.0-alpine
|
||||||
|
|
||||||
LABEL version="1.5.2" description="Api to control whatsapp features through http requests."
|
LABEL version="1.6.0" description="Api to control whatsapp features through http requests."
|
||||||
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
||||||
LABEL contact="contato@agenciadgcode.com"
|
LABEL contact="contato@agenciadgcode.com"
|
||||||
|
|
||||||
@@ -56,6 +56,12 @@ ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
|||||||
|
|
||||||
ENV WEBSOCKET_ENABLED=false
|
ENV WEBSOCKET_ENABLED=false
|
||||||
|
|
||||||
|
ENV SQS_ENABLED=false
|
||||||
|
ENV SQS_ACCESS_KEY_ID=
|
||||||
|
ENV SQS_SECRET_ACCESS_KEY=
|
||||||
|
ENV SQS_ACCOUNT_ID=
|
||||||
|
ENV SQS_REGION=
|
||||||
|
|
||||||
ENV WEBHOOK_GLOBAL_URL=
|
ENV WEBHOOK_GLOBAL_URL=
|
||||||
ENV WEBHOOK_GLOBAL_ENABLED=false
|
ENV WEBHOOK_GLOBAL_ENABLED=false
|
||||||
|
|
||||||
@@ -98,6 +104,8 @@ ENV CONFIG_SESSION_PHONE_NAME=Chrome
|
|||||||
ENV QRCODE_LIMIT=30
|
ENV QRCODE_LIMIT=30
|
||||||
ENV QRCODE_COLOR=#198754
|
ENV QRCODE_COLOR=#198754
|
||||||
|
|
||||||
|
ENV TYPEBOT_API_VERSION=latest
|
||||||
|
|
||||||
ENV AUTHENTICATION_TYPE=apikey
|
ENV AUTHENTICATION_TYPE=apikey
|
||||||
|
|
||||||
ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
|
ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -39,12 +39,13 @@ This code was produced based on the baileys library and it is still under develo
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
#### Buy me coffe
|
#### Buy me coffe - PIX
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<a href="https://bmc.link/evolutionapi" target="_blank" rel="noopener noreferrer">
|
<a href="https://bmc.link/evolutionapi" target="_blank" rel="noopener noreferrer">
|
||||||
<img src="./public/images/bmc_qr.png" style="width: 50% !important;">
|
<img src="./public/images/qrcode-pix.png" style="width: 50% !important;">
|
||||||
</a>
|
</a>
|
||||||
|
<p><b>CHAVE PIX (Telefone):</b> (74)99987-9409</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.5.2",
|
"version": "1.6.0",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "./dist/src/main.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -48,6 +48,7 @@
|
|||||||
"@sentry/node": "^7.59.2",
|
"@sentry/node": "^7.59.2",
|
||||||
"@whiskeysockets/baileys": "^6.5.0",
|
"@whiskeysockets/baileys": "^6.5.0",
|
||||||
"amqplib": "^0.10.3",
|
"amqplib": "^0.10.3",
|
||||||
|
"aws-sdk": "^2.1499.0",
|
||||||
"axios": "^1.3.5",
|
"axios": "^1.3.5",
|
||||||
"class-validator": "^0.13.2",
|
"class-validator": "^0.13.2",
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
@@ -55,6 +56,7 @@
|
|||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"eventemitter2": "^6.4.9",
|
"eventemitter2": "^6.4.9",
|
||||||
|
"evolution-manager": "^0.4.4",
|
||||||
"exiftool-vendored": "^22.0.0",
|
"exiftool-vendored": "^22.0.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-async-errors": "^3.1.1",
|
"express-async-errors": "^3.1.1",
|
||||||
@@ -78,7 +80,9 @@
|
|||||||
"sharp": "^0.30.7",
|
"sharp": "^0.30.7",
|
||||||
"socket.io": "^4.7.1",
|
"socket.io": "^4.7.1",
|
||||||
"socks-proxy-agent": "^8.0.1",
|
"socks-proxy-agent": "^8.0.1",
|
||||||
"uuid": "^9.0.0"
|
"swagger-ui-express": "^5.0.0",
|
||||||
|
"uuid": "^9.0.0",
|
||||||
|
"yamljs": "^0.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/compression": "^1.7.2",
|
"@types/compression": "^1.7.2",
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
BIN
public/images/qrcode-pix.png
Normal file
BIN
public/images/qrcode-pix.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
@@ -66,12 +66,16 @@ export type Rabbitmq = {
|
|||||||
URI: string;
|
URI: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Websocket = {
|
export type Sqs = {
|
||||||
ENABLED: boolean;
|
ENABLED: boolean;
|
||||||
|
ACCESS_KEY_ID: string;
|
||||||
|
SECRET_ACCESS_KEY: string;
|
||||||
|
ACCOUNT_ID: string;
|
||||||
|
REGION: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Chatwoot = {
|
export type Websocket = {
|
||||||
USE_REPLY_ID: boolean;
|
ENABLED: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EventsWebhook = {
|
export type EventsWebhook = {
|
||||||
@@ -124,6 +128,7 @@ export type SslConf = { PRIVKEY: string; FULLCHAIN: string };
|
|||||||
export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook };
|
export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook };
|
||||||
export type ConfigSessionPhone = { CLIENT: string; NAME: string };
|
export type ConfigSessionPhone = { CLIENT: string; NAME: string };
|
||||||
export type QrCode = { LIMIT: number; COLOR: string };
|
export type QrCode = { LIMIT: number; COLOR: string };
|
||||||
|
export type Typebot = { API_VERSION: string };
|
||||||
export type Production = boolean;
|
export type Production = boolean;
|
||||||
|
|
||||||
export interface Env {
|
export interface Env {
|
||||||
@@ -135,15 +140,16 @@ export interface Env {
|
|||||||
DATABASE: Database;
|
DATABASE: Database;
|
||||||
REDIS: Redis;
|
REDIS: Redis;
|
||||||
RABBITMQ: Rabbitmq;
|
RABBITMQ: Rabbitmq;
|
||||||
|
SQS: Sqs;
|
||||||
WEBSOCKET: Websocket;
|
WEBSOCKET: Websocket;
|
||||||
LOG: Log;
|
LOG: Log;
|
||||||
DEL_INSTANCE: DelInstance;
|
DEL_INSTANCE: DelInstance;
|
||||||
WEBHOOK: Webhook;
|
WEBHOOK: Webhook;
|
||||||
CONFIG_SESSION_PHONE: ConfigSessionPhone;
|
CONFIG_SESSION_PHONE: ConfigSessionPhone;
|
||||||
QRCODE: QrCode;
|
QRCODE: QrCode;
|
||||||
|
TYPEBOT: Typebot;
|
||||||
AUTHENTICATION: Auth;
|
AUTHENTICATION: Auth;
|
||||||
PRODUCTION?: Production;
|
PRODUCTION?: Production;
|
||||||
CHATWOOT?: Chatwoot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Key = keyof Env;
|
export type Key = keyof Env;
|
||||||
@@ -226,6 +232,13 @@ export class ConfigService {
|
|||||||
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
||||||
URI: process.env.RABBITMQ_URI || '',
|
URI: process.env.RABBITMQ_URI || '',
|
||||||
},
|
},
|
||||||
|
SQS: {
|
||||||
|
ENABLED: process.env?.SQS_ENABLED === 'true',
|
||||||
|
ACCESS_KEY_ID: process.env.SQS_ACCESS_KEY_ID || '',
|
||||||
|
SECRET_ACCESS_KEY: process.env.SQS_SECRET_ACCESS_KEY || '',
|
||||||
|
ACCOUNT_ID: process.env.SQS_ACCOUNT_ID || '',
|
||||||
|
REGION: process.env.SQS_REGION || '',
|
||||||
|
},
|
||||||
WEBSOCKET: {
|
WEBSOCKET: {
|
||||||
ENABLED: process.env?.WEBSOCKET_ENABLED === 'true',
|
ENABLED: process.env?.WEBSOCKET_ENABLED === 'true',
|
||||||
},
|
},
|
||||||
@@ -289,6 +302,9 @@ export class ConfigService {
|
|||||||
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,
|
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,
|
||||||
COLOR: process.env.QRCODE_COLOR || '#198754',
|
COLOR: process.env.QRCODE_COLOR || '#198754',
|
||||||
},
|
},
|
||||||
|
TYPEBOT: {
|
||||||
|
API_VERSION: process.env?.TYPEBOT_API_VERSION || 'old',
|
||||||
|
},
|
||||||
AUTHENTICATION: {
|
AUTHENTICATION: {
|
||||||
TYPE: process.env.AUTHENTICATION_TYPE as 'apikey',
|
TYPE: process.env.AUTHENTICATION_TYPE as 'apikey',
|
||||||
API_KEY: {
|
API_KEY: {
|
||||||
@@ -302,9 +318,6 @@ export class ConfigService {
|
|||||||
SECRET: process.env.AUTHENTICATION_JWT_SECRET || 'L=0YWt]b2w[WF>#>:&E`',
|
SECRET: process.env.AUTHENTICATION_JWT_SECRET || 'L=0YWt]b2w[WF>#>:&E`',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CHATWOOT: {
|
|
||||||
USE_REPLY_ID: process.env?.USE_REPLY_ID === 'true',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export function onUnexpectedError() {
|
|||||||
stderr: process.stderr.fd,
|
stderr: process.stderr.fd,
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
process.exit(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('unhandledRejection', (error, origin) => {
|
process.on('unhandledRejection', (error, origin) => {
|
||||||
@@ -18,6 +17,5 @@ export function onUnexpectedError() {
|
|||||||
stderr: process.stderr.fd,
|
stderr: process.stderr.fd,
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
process.exit(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,13 @@ RABBITMQ:
|
|||||||
ENABLED: false
|
ENABLED: false
|
||||||
URI: "amqp://guest:guest@localhost:5672"
|
URI: "amqp://guest:guest@localhost:5672"
|
||||||
|
|
||||||
|
SQS:
|
||||||
|
ENABLED: true
|
||||||
|
ACCESS_KEY_ID: ""
|
||||||
|
SECRET_ACCESS_KEY: ""
|
||||||
|
ACCOUNT_ID: ""
|
||||||
|
REGION: "us-east-1"
|
||||||
|
|
||||||
WEBSOCKET:
|
WEBSOCKET:
|
||||||
ENABLED: false
|
ENABLED: false
|
||||||
|
|
||||||
@@ -139,6 +146,9 @@ QRCODE:
|
|||||||
LIMIT: 30
|
LIMIT: 30
|
||||||
COLOR: "#198754"
|
COLOR: "#198754"
|
||||||
|
|
||||||
|
TYPEBOT:
|
||||||
|
API_VERSION: 'old' # old | latest
|
||||||
|
|
||||||
# Defines an authentication type for the api
|
# Defines an authentication type for the api
|
||||||
# We recommend using the apikey because it will allow you to use a custom token,
|
# 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
|
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
|
||||||
@@ -154,7 +164,3 @@ AUTHENTICATION:
|
|||||||
JWT:
|
JWT:
|
||||||
EXPIRIN_IN: 0 # seconds - 3600s === 1h | zero (0) - never expires
|
EXPIRIN_IN: 0 # seconds - 3600s === 1h | zero (0) - never expires
|
||||||
SECRET: L=0YWt]b2w[WF>#>:&E`
|
SECRET: L=0YWt]b2w[WF>#>:&E`
|
||||||
|
|
||||||
# Configure to chatwoot
|
|
||||||
CHATWOOT:
|
|
||||||
USE_REPLY_ID: false
|
|
||||||
|
|||||||
17
src/docs/swagger.conf.ts
Normal file
17
src/docs/swagger.conf.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { join } from 'path';
|
||||||
|
import swaggerUi from 'swagger-ui-express';
|
||||||
|
import YAML from 'yamljs';
|
||||||
|
|
||||||
|
const document = YAML.load(join(process.cwd(), 'src', 'docs', 'swagger.yaml'));
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
export const swaggerRouter = router.use('/docs', swaggerUi.serve).get(
|
||||||
|
'/docs',
|
||||||
|
swaggerUi.setup(document, {
|
||||||
|
customCssUrl: '/css/dark-theme-swagger.css',
|
||||||
|
customSiteTitle: 'Evolution API',
|
||||||
|
customfavIcon: '/images/logo.svg',
|
||||||
|
}),
|
||||||
|
);
|
||||||
2597
src/docs/swagger.yaml
Normal file
2597
src/docs/swagger.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -71,3 +71,30 @@ export const initQueues = (instanceName: string, events: string[]) => {
|
|||||||
amqp.bindQueue(queueName, exchangeName, event);
|
amqp.bindQueue(queueName, exchangeName, event);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const removeQueues = (instanceName: string, events: string[]) => {
|
||||||
|
if (!events || !events.length) return;
|
||||||
|
|
||||||
|
const channel = getAMQP();
|
||||||
|
|
||||||
|
const queues = events.map((event) => {
|
||||||
|
return `${event.replace(/_/g, '.').toLowerCase()}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const exchangeName = instanceName ?? 'evolution_exchange';
|
||||||
|
|
||||||
|
queues.forEach((event) => {
|
||||||
|
const amqp = getAMQP();
|
||||||
|
|
||||||
|
amqp.assertExchange(exchangeName, 'topic', {
|
||||||
|
durable: true,
|
||||||
|
autoDelete: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const queueName = `${instanceName}.${event}`;
|
||||||
|
|
||||||
|
amqp.deleteQueue(queueName);
|
||||||
|
});
|
||||||
|
|
||||||
|
channel.deleteExchange(exchangeName);
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,49 +5,55 @@ import { Redis } from '../config/env.config';
|
|||||||
import { Logger } from '../config/logger.config';
|
import { Logger } from '../config/logger.config';
|
||||||
|
|
||||||
export class RedisCache {
|
export class RedisCache {
|
||||||
async disconnect() {
|
private readonly logger = new Logger(RedisCache.name);
|
||||||
await this.client.disconnect();
|
private client: RedisClientType;
|
||||||
this.statusConnection = false;
|
|
||||||
}
|
|
||||||
constructor() {
|
|
||||||
this.logger.verbose('instance created');
|
|
||||||
process.on('beforeExit', async () => {
|
|
||||||
this.logger.verbose('instance destroyed');
|
|
||||||
if (this.statusConnection) {
|
|
||||||
this.logger.verbose('instance disconnect');
|
|
||||||
await this.client.disconnect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private statusConnection = false;
|
private statusConnection = false;
|
||||||
private instanceName: string;
|
private instanceName: string;
|
||||||
private redisEnv: Redis;
|
private redisEnv: Redis;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.logger.verbose('RedisCache instance created');
|
||||||
|
process.on('beforeExit', () => {
|
||||||
|
this.logger.verbose('RedisCache instance destroyed');
|
||||||
|
this.disconnect();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public set reference(reference: string) {
|
public set reference(reference: string) {
|
||||||
this.logger.verbose('set reference: ' + reference);
|
this.logger.verbose('set reference: ' + reference);
|
||||||
this.instanceName = reference;
|
this.instanceName = reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async connect(redisEnv: Redis) {
|
public async connect(redisEnv: Redis) {
|
||||||
this.logger.verbose('connecting');
|
this.logger.verbose('Connecting to Redis...');
|
||||||
this.client = createClient({ url: redisEnv.URI });
|
this.client = createClient({ url: redisEnv.URI });
|
||||||
this.logger.verbose('connected in ' + redisEnv.URI);
|
this.client.on('error', (err) => this.logger.error('Redis Client Error ' + err));
|
||||||
|
|
||||||
await this.client.connect();
|
await this.client.connect();
|
||||||
this.statusConnection = true;
|
this.statusConnection = true;
|
||||||
this.redisEnv = redisEnv;
|
this.redisEnv = redisEnv;
|
||||||
|
this.logger.verbose(`Connected to ${redisEnv.URI}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly logger = new Logger(RedisCache.name);
|
public async disconnect() {
|
||||||
private client: RedisClientType;
|
if (this.statusConnection) {
|
||||||
|
await this.client.disconnect();
|
||||||
|
this.statusConnection = false;
|
||||||
|
this.logger.verbose('Redis client disconnected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async instanceKeys(): Promise<string[]> {
|
public async instanceKeys(): Promise<string[]> {
|
||||||
|
const keys: string[] = [];
|
||||||
try {
|
try {
|
||||||
this.logger.verbose('instance keys: ' + this.redisEnv.PREFIX_KEY + ':*');
|
this.logger.verbose('Fetching instance keys');
|
||||||
return await this.client.sendCommand(['keys', this.redisEnv.PREFIX_KEY + ':*']);
|
for await (const key of this.client.scanIterator({ MATCH: `${this.redisEnv.PREFIX_KEY}:*` })) {
|
||||||
|
keys.push(key);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error('Error fetching instance keys ' + error);
|
||||||
}
|
}
|
||||||
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async keyExists(key?: string) {
|
public async keyExists(key?: string) {
|
||||||
|
|||||||
97
src/libs/sqs.server.ts
Normal file
97
src/libs/sqs.server.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import { SQS } from 'aws-sdk';
|
||||||
|
|
||||||
|
import { configService, Sqs } from '../config/env.config';
|
||||||
|
import { Logger } from '../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('SQS');
|
||||||
|
|
||||||
|
let sqs: SQS;
|
||||||
|
|
||||||
|
export const initSQS = () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
const awsConfig = configService.get<Sqs>('SQS');
|
||||||
|
sqs = new SQS({
|
||||||
|
accessKeyId: awsConfig.ACCESS_KEY_ID,
|
||||||
|
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
|
||||||
|
region: awsConfig.REGION,
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info('SQS initialized');
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getSQS = (): SQS => {
|
||||||
|
return sqs;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const initQueues = (instanceName: string, events: string[]) => {
|
||||||
|
if (!events || !events.length) return;
|
||||||
|
|
||||||
|
const queues = events.map((event) => {
|
||||||
|
return `${event.replace(/_/g, '_').toLowerCase()}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const sqs = getSQS();
|
||||||
|
|
||||||
|
queues.forEach((event) => {
|
||||||
|
const queueName = `${instanceName}_${event}.fifo`;
|
||||||
|
|
||||||
|
sqs.createQueue(
|
||||||
|
{
|
||||||
|
QueueName: queueName,
|
||||||
|
Attributes: {
|
||||||
|
FifoQueue: 'true',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
(err, data) => {
|
||||||
|
if (err) {
|
||||||
|
logger.error(`Error creating queue ${queueName}: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logger.info(`Queue ${queueName} created: ${data.QueueUrl}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const removeQueues = (instanceName: string, events: string[]) => {
|
||||||
|
if (!events || !events.length) return;
|
||||||
|
|
||||||
|
const sqs = getSQS();
|
||||||
|
|
||||||
|
const queues = events.map((event) => {
|
||||||
|
return `${event.replace(/_/g, '_').toLowerCase()}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
queues.forEach((event) => {
|
||||||
|
const queueName = `${instanceName}_${event}.fifo`;
|
||||||
|
|
||||||
|
sqs.getQueueUrl(
|
||||||
|
{
|
||||||
|
QueueName: queueName,
|
||||||
|
},
|
||||||
|
(err, data) => {
|
||||||
|
if (err) {
|
||||||
|
logger.error(`Error getting queue URL for ${queueName}: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
const queueUrl = data.QueueUrl;
|
||||||
|
|
||||||
|
sqs.deleteQueue(
|
||||||
|
{
|
||||||
|
QueueUrl: queueUrl,
|
||||||
|
},
|
||||||
|
(deleteErr) => {
|
||||||
|
if (deleteErr) {
|
||||||
|
logger.error(`Error deleting queue ${queueName}: ${deleteErr.message}`);
|
||||||
|
} else {
|
||||||
|
logger.info(`Queue ${queueName} deleted`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -6,12 +6,14 @@ import cors from 'cors';
|
|||||||
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
import { Auth, configService, Cors, HttpServer, Rabbitmq, Webhook } from './config/env.config';
|
import { Auth, configService, Cors, HttpServer, Rabbitmq, Sqs, Webhook } from './config/env.config';
|
||||||
import { onUnexpectedError } from './config/error.config';
|
import { onUnexpectedError } from './config/error.config';
|
||||||
import { Logger } from './config/logger.config';
|
import { Logger } from './config/logger.config';
|
||||||
import { ROOT_DIR } from './config/path.config';
|
import { ROOT_DIR } from './config/path.config';
|
||||||
|
import { swaggerRouter } from './docs/swagger.conf';
|
||||||
import { initAMQP } from './libs/amqp.server';
|
import { initAMQP } from './libs/amqp.server';
|
||||||
import { initIO } from './libs/socket.server';
|
import { initIO } from './libs/socket.server';
|
||||||
|
import { initSQS } from './libs/sqs.server';
|
||||||
import { ServerUP } from './utils/server-up';
|
import { ServerUP } from './utils/server-up';
|
||||||
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
||||||
import { waMonitor } from './whatsapp/whatsapp.module';
|
import { waMonitor } from './whatsapp/whatsapp.module';
|
||||||
@@ -51,6 +53,7 @@ function bootstrap() {
|
|||||||
app.use('/store', express.static(join(ROOT_DIR, 'store')));
|
app.use('/store', express.static(join(ROOT_DIR, 'store')));
|
||||||
|
|
||||||
app.use('/', router);
|
app.use('/', router);
|
||||||
|
app.use(swaggerRouter);
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||||
@@ -126,6 +129,8 @@ function bootstrap() {
|
|||||||
|
|
||||||
if (configService.get<Rabbitmq>('RABBITMQ')?.ENABLED) initAMQP();
|
if (configService.get<Rabbitmq>('RABBITMQ')?.ENABLED) initAMQP();
|
||||||
|
|
||||||
|
if (configService.get<Sqs>('SQS')?.ENABLED) initSQS();
|
||||||
|
|
||||||
onUnexpectedError();
|
onUnexpectedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,14 @@ export async function useMultiFileAuthStateDb(
|
|||||||
const writeData = async (data: any, key: string): Promise<any> => {
|
const writeData = async (data: any, key: string): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
return await collection.replaceOne({ _id: key }, JSON.parse(JSON.stringify(data, BufferJSON.replacer)), {
|
let msgParsed = JSON.parse(JSON.stringify(data, BufferJSON.replacer));
|
||||||
|
if (Array.isArray(msgParsed)) {
|
||||||
|
msgParsed = {
|
||||||
|
_id: key,
|
||||||
|
content_array: msgParsed,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return await collection.replaceOne({ _id: key }, msgParsed, {
|
||||||
upsert: true,
|
upsert: true,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -36,7 +43,10 @@ export async function useMultiFileAuthStateDb(
|
|||||||
const readData = async (key: string): Promise<any> => {
|
const readData = async (key: string): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
const data = await collection.findOne({ _id: key });
|
let data = (await collection.findOne({ _id: key })) as any;
|
||||||
|
if (data?.content_array) {
|
||||||
|
data = data.content_array;
|
||||||
|
}
|
||||||
const creds = JSON.stringify(data);
|
const creds = JSON.stringify(data);
|
||||||
return JSON.parse(creds, BufferJSON.reviver);
|
return JSON.parse(creds, BufferJSON.reviver);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -91,7 +101,7 @@ export async function useMultiFileAuthStateDb(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
saveCreds: async () => {
|
saveCreds: async () => {
|
||||||
return writeData(creds, 'creds');
|
return await writeData(creds, 'creds');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,6 +149,16 @@ export const textMessageSchema: JSONSchema7 = {
|
|||||||
required: ['textMessage', 'number'],
|
required: ['textMessage', 'number'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const presenceSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
number: { ...numberDefinition },
|
||||||
|
options: { ...optionsSchema, required: ['presence', 'delay'] },
|
||||||
|
},
|
||||||
|
required: ['options', 'number'],
|
||||||
|
};
|
||||||
|
|
||||||
export const pollMessageSchema: JSONSchema7 = {
|
export const pollMessageSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@@ -881,6 +891,7 @@ export const chatwootSchema: JSONSchema7 = {
|
|||||||
sign_msg: { type: 'boolean', enum: [true, false] },
|
sign_msg: { type: 'boolean', enum: [true, false] },
|
||||||
reopen_conversation: { type: 'boolean', enum: [true, false] },
|
reopen_conversation: { type: 'boolean', enum: [true, false] },
|
||||||
conversation_pending: { type: 'boolean', enum: [true, false] },
|
conversation_pending: { type: 'boolean', enum: [true, false] },
|
||||||
|
auto_create: { type: 'boolean', enum: [true, false] },
|
||||||
},
|
},
|
||||||
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'],
|
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'],
|
||||||
...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'),
|
...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'),
|
||||||
@@ -987,6 +998,49 @@ export const rabbitmqSchema: JSONSchema7 = {
|
|||||||
...isNotEmpty('enabled'),
|
...isNotEmpty('enabled'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const sqsSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
enabled: { type: 'boolean', enum: [true, false] },
|
||||||
|
events: {
|
||||||
|
type: 'array',
|
||||||
|
minItems: 0,
|
||||||
|
items: {
|
||||||
|
type: 'string',
|
||||||
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'CALL',
|
||||||
|
'NEW_JWT_TOKEN',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
'CHAMA_AI_ACTION',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['enabled'],
|
||||||
|
...isNotEmpty('enabled'),
|
||||||
|
};
|
||||||
|
|
||||||
export const typebotSchema: JSONSchema7 = {
|
export const typebotSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
ProfilePictureDto,
|
ProfilePictureDto,
|
||||||
ProfileStatusDto,
|
ProfileStatusDto,
|
||||||
ReadMessageDto,
|
ReadMessageDto,
|
||||||
|
SendPresenceDto,
|
||||||
WhatsAppNumberDto,
|
WhatsAppNumberDto,
|
||||||
} from '../dto/chat.dto';
|
} from '../dto/chat.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
@@ -77,6 +78,11 @@ export class ChatController {
|
|||||||
return await this.waMonitor.waInstances[instanceName].fetchChats();
|
return await this.waMonitor.waInstances[instanceName].fetchChats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async sendPresence({ instanceName }: InstanceDto, data: SendPresenceDto) {
|
||||||
|
logger.verbose('requested sendPresence from ' + instanceName + ' instance');
|
||||||
|
return await this.waMonitor.waInstances[instanceName].sendPresence(data);
|
||||||
|
}
|
||||||
|
|
||||||
public async fetchPrivacySettings({ instanceName }: InstanceDto) {
|
public async fetchPrivacySettings({ instanceName }: InstanceDto) {
|
||||||
logger.verbose('requested fetchPrivacySettings from ' + instanceName + ' instance');
|
logger.verbose('requested fetchPrivacySettings from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
||||||
|
|||||||
@@ -5,13 +5,18 @@ import { Logger } from '../../config/logger.config';
|
|||||||
import { BadRequestException } from '../../exceptions';
|
import { BadRequestException } from '../../exceptions';
|
||||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
import { ChatwootService } from '../services/chatwoot.service';
|
import { ChatwootService } from '../services/chatwoot.service';
|
||||||
import { waMonitor } from '../whatsapp.module';
|
import { waMonitor } from '../whatsapp.module';
|
||||||
|
|
||||||
const logger = new Logger('ChatwootController');
|
const logger = new Logger('ChatwootController');
|
||||||
|
|
||||||
export class ChatwootController {
|
export class ChatwootController {
|
||||||
constructor(private readonly chatwootService: ChatwootService, private readonly configService: ConfigService) {}
|
constructor(
|
||||||
|
private readonly chatwootService: ChatwootService,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
private readonly repository: RepositoryBroker,
|
||||||
|
) {}
|
||||||
|
|
||||||
public async createChatwoot(instance: InstanceDto, data: ChatwootDto) {
|
public async createChatwoot(instance: InstanceDto, data: ChatwootDto) {
|
||||||
logger.verbose('requested createChatwoot from ' + instance.instanceName + ' instance');
|
logger.verbose('requested createChatwoot from ' + instance.instanceName + ' instance');
|
||||||
@@ -42,11 +47,12 @@ export class ChatwootController {
|
|||||||
data.sign_msg = false;
|
data.sign_msg = false;
|
||||||
data.reopen_conversation = false;
|
data.reopen_conversation = false;
|
||||||
data.conversation_pending = false;
|
data.conversation_pending = false;
|
||||||
|
data.auto_create = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.name_inbox = instance.instanceName;
|
data.name_inbox = instance.instanceName;
|
||||||
|
|
||||||
const result = this.chatwootService.create(instance, data);
|
const result = await this.chatwootService.create(instance, data);
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
@@ -64,7 +70,7 @@ export class ChatwootController {
|
|||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
if (Object.keys(result).length === 0) {
|
if (Object.keys(result || {}).length === 0) {
|
||||||
return {
|
return {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
url: '',
|
url: '',
|
||||||
@@ -86,7 +92,7 @@ export class ChatwootController {
|
|||||||
|
|
||||||
public async receiveWebhook(instance: InstanceDto, data: any) {
|
public async receiveWebhook(instance: InstanceDto, data: any) {
|
||||||
logger.verbose('requested receiveWebhook from ' + instance.instanceName + ' instance');
|
logger.verbose('requested receiveWebhook from ' + instance.instanceName + ' instance');
|
||||||
const chatwootService = new ChatwootService(waMonitor, this.configService);
|
const chatwootService = new ChatwootService(waMonitor, this.configService, this.repository);
|
||||||
|
|
||||||
return chatwootService.receiveWebhook(instance, data);
|
return chatwootService.receiveWebhook(instance, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import { RepositoryBroker } from '../repository/repository.manager';
|
|||||||
import { AuthService, OldToken } from '../services/auth.service';
|
import { AuthService, OldToken } from '../services/auth.service';
|
||||||
import { ChatwootService } from '../services/chatwoot.service';
|
import { ChatwootService } from '../services/chatwoot.service';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
|
import { ProxyService } from '../services/proxy.service';
|
||||||
import { RabbitmqService } from '../services/rabbitmq.service';
|
import { RabbitmqService } from '../services/rabbitmq.service';
|
||||||
import { SettingsService } from '../services/settings.service';
|
import { SettingsService } from '../services/settings.service';
|
||||||
|
import { SqsService } from '../services/sqs.service';
|
||||||
import { TypebotService } from '../services/typebot.service';
|
import { TypebotService } from '../services/typebot.service';
|
||||||
import { WebhookService } from '../services/webhook.service';
|
import { WebhookService } from '../services/webhook.service';
|
||||||
import { WebsocketService } from '../services/websocket.service';
|
import { WebsocketService } from '../services/websocket.service';
|
||||||
@@ -31,6 +33,8 @@ export class InstanceController {
|
|||||||
private readonly settingsService: SettingsService,
|
private readonly settingsService: SettingsService,
|
||||||
private readonly websocketService: WebsocketService,
|
private readonly websocketService: WebsocketService,
|
||||||
private readonly rabbitmqService: RabbitmqService,
|
private readonly rabbitmqService: RabbitmqService,
|
||||||
|
private readonly proxyService: ProxyService,
|
||||||
|
private readonly sqsService: SqsService,
|
||||||
private readonly typebotService: TypebotService,
|
private readonly typebotService: TypebotService,
|
||||||
private readonly cache: RedisCache,
|
private readonly cache: RedisCache,
|
||||||
) {}
|
) {}
|
||||||
@@ -41,6 +45,7 @@ export class InstanceController {
|
|||||||
instanceName,
|
instanceName,
|
||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
|
webhook_base64,
|
||||||
events,
|
events,
|
||||||
qrcode,
|
qrcode,
|
||||||
number,
|
number,
|
||||||
@@ -61,6 +66,8 @@ export class InstanceController {
|
|||||||
websocket_events,
|
websocket_events,
|
||||||
rabbitmq_enabled,
|
rabbitmq_enabled,
|
||||||
rabbitmq_events,
|
rabbitmq_events,
|
||||||
|
sqs_enabled,
|
||||||
|
sqs_events,
|
||||||
typebot_url,
|
typebot_url,
|
||||||
typebot,
|
typebot,
|
||||||
typebot_expire,
|
typebot_expire,
|
||||||
@@ -68,6 +75,7 @@ export class InstanceController {
|
|||||||
typebot_delay_message,
|
typebot_delay_message,
|
||||||
typebot_unknown_message,
|
typebot_unknown_message,
|
||||||
typebot_listening_from_me,
|
typebot_listening_from_me,
|
||||||
|
proxy,
|
||||||
}: InstanceDto) {
|
}: InstanceDto) {
|
||||||
try {
|
try {
|
||||||
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
|
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
|
||||||
@@ -139,6 +147,7 @@ export class InstanceController {
|
|||||||
url: webhook,
|
url: webhook,
|
||||||
events: newEvents,
|
events: newEvents,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
|
webhook_base64,
|
||||||
});
|
});
|
||||||
|
|
||||||
webhookEvents = (await this.webhookService.find(instance)).events;
|
webhookEvents = (await this.webhookService.find(instance)).events;
|
||||||
@@ -241,6 +250,69 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (proxy) {
|
||||||
|
this.logger.verbose('creating proxy');
|
||||||
|
try {
|
||||||
|
this.proxyService.create(
|
||||||
|
instance,
|
||||||
|
{
|
||||||
|
enabled: true,
|
||||||
|
proxy,
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sqsEvents: string[];
|
||||||
|
|
||||||
|
if (sqs_enabled) {
|
||||||
|
this.logger.verbose('creating sqs');
|
||||||
|
try {
|
||||||
|
let newEvents: string[] = [];
|
||||||
|
if (sqs_events.length === 0) {
|
||||||
|
newEvents = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'CALL',
|
||||||
|
'NEW_JWT_TOKEN',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
'CHAMA_AI_ACTION',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
newEvents = sqs_events;
|
||||||
|
}
|
||||||
|
this.sqsService.create(instance, {
|
||||||
|
enabled: true,
|
||||||
|
events: newEvents,
|
||||||
|
});
|
||||||
|
|
||||||
|
sqsEvents = (await this.sqsService.find(instance)).events;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (typebot_url) {
|
if (typebot_url) {
|
||||||
try {
|
try {
|
||||||
if (!isURL(typebot_url, { require_tld: false })) {
|
if (!isURL(typebot_url, { require_tld: false })) {
|
||||||
@@ -268,7 +340,7 @@ export class InstanceController {
|
|||||||
const settings: wa.LocalSettings = {
|
const settings: wa.LocalSettings = {
|
||||||
reject_call: reject_call || false,
|
reject_call: reject_call || false,
|
||||||
msg_call: msg_call || '',
|
msg_call: msg_call || '',
|
||||||
groups_ignore: groups_ignore || false,
|
groups_ignore: groups_ignore || true,
|
||||||
always_online: always_online || false,
|
always_online: always_online || false,
|
||||||
read_messages: read_messages || false,
|
read_messages: read_messages || false,
|
||||||
read_status: read_status || false,
|
read_status: read_status || false,
|
||||||
@@ -297,6 +369,7 @@ export class InstanceController {
|
|||||||
webhook: {
|
webhook: {
|
||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
|
webhook_base64,
|
||||||
events: webhookEvents,
|
events: webhookEvents,
|
||||||
},
|
},
|
||||||
websocket: {
|
websocket: {
|
||||||
@@ -307,6 +380,10 @@ export class InstanceController {
|
|||||||
enabled: rabbitmq_enabled,
|
enabled: rabbitmq_enabled,
|
||||||
events: rabbitmqEvents,
|
events: rabbitmqEvents,
|
||||||
},
|
},
|
||||||
|
sqs: {
|
||||||
|
enabled: sqs_enabled,
|
||||||
|
events: sqsEvents,
|
||||||
|
},
|
||||||
typebot: {
|
typebot: {
|
||||||
enabled: typebot_url ? true : false,
|
enabled: typebot_url ? true : false,
|
||||||
url: typebot_url,
|
url: typebot_url,
|
||||||
@@ -319,6 +396,7 @@ export class InstanceController {
|
|||||||
},
|
},
|
||||||
settings,
|
settings,
|
||||||
qrcode: getQrcode,
|
qrcode: getQrcode,
|
||||||
|
proxy,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logger.verbose('instance created');
|
this.logger.verbose('instance created');
|
||||||
@@ -368,15 +446,8 @@ export class InstanceController {
|
|||||||
number,
|
number,
|
||||||
reopen_conversation: chatwoot_reopen_conversation || false,
|
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||||
conversation_pending: chatwoot_conversation_pending || false,
|
conversation_pending: chatwoot_conversation_pending || false,
|
||||||
|
auto_create: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chatwootService.initInstanceChatwoot(
|
|
||||||
instance,
|
|
||||||
instance.instanceName.split('-cwId-')[0],
|
|
||||||
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
|
||||||
qrcode,
|
|
||||||
number,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.log(error);
|
this.logger.log(error);
|
||||||
}
|
}
|
||||||
@@ -390,6 +461,7 @@ export class InstanceController {
|
|||||||
webhook: {
|
webhook: {
|
||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
|
webhook_base64,
|
||||||
events: webhookEvents,
|
events: webhookEvents,
|
||||||
},
|
},
|
||||||
websocket: {
|
websocket: {
|
||||||
@@ -400,6 +472,10 @@ export class InstanceController {
|
|||||||
enabled: rabbitmq_enabled,
|
enabled: rabbitmq_enabled,
|
||||||
events: rabbitmqEvents,
|
events: rabbitmqEvents,
|
||||||
},
|
},
|
||||||
|
sqs: {
|
||||||
|
enabled: sqs_enabled,
|
||||||
|
events: sqsEvents,
|
||||||
|
},
|
||||||
typebot: {
|
typebot: {
|
||||||
enabled: typebot_url ? true : false,
|
enabled: typebot_url ? true : false,
|
||||||
url: typebot_url,
|
url: typebot_url,
|
||||||
@@ -423,6 +499,7 @@ export class InstanceController {
|
|||||||
name_inbox: instance.instanceName,
|
name_inbox: instance.instanceName,
|
||||||
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
||||||
},
|
},
|
||||||
|
proxy,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error.message[0]);
|
this.logger.error(error.message[0]);
|
||||||
@@ -475,10 +552,19 @@ export class InstanceController {
|
|||||||
try {
|
try {
|
||||||
this.logger.verbose('requested restartInstance from ' + instanceName + ' instance');
|
this.logger.verbose('requested restartInstance from ' + instanceName + ' instance');
|
||||||
|
|
||||||
this.logger.verbose('logging out instance: ' + instanceName);
|
const instance = this.waMonitor.waInstances[instanceName];
|
||||||
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
const state = instance?.connectionStatus?.state;
|
||||||
|
|
||||||
return { status: 'SUCCESS', error: false, response: { message: 'Instance restarted' } };
|
switch (state) {
|
||||||
|
case 'open':
|
||||||
|
this.logger.verbose('logging out instance: ' + instanceName);
|
||||||
|
await instance.reloadConnection();
|
||||||
|
await delay(2000);
|
||||||
|
|
||||||
|
return await this.connectionState({ instanceName });
|
||||||
|
default:
|
||||||
|
return await this.connectionState({ instanceName });
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
@@ -534,19 +620,19 @@ export class InstanceController {
|
|||||||
throw new BadRequestException('The "' + instanceName + '" instance needs to be disconnected');
|
throw new BadRequestException('The "' + instanceName + '" instance needs to be disconnected');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
this.waMonitor.waInstances[instanceName]?.removeRabbitmqQueues();
|
||||||
|
|
||||||
if (instance.state === 'connecting') {
|
if (instance.state === 'connecting') {
|
||||||
this.logger.verbose('logging out instance: ' + instanceName);
|
this.logger.verbose('logging out instance: ' + instanceName);
|
||||||
|
|
||||||
await this.logout({ instanceName });
|
await this.logout({ instanceName });
|
||||||
delete this.waMonitor.waInstances[instanceName];
|
|
||||||
return { status: 'SUCCESS', error: false, response: { message: 'Instance deleted' } };
|
|
||||||
} else {
|
|
||||||
this.logger.verbose('deleting instance: ' + instanceName);
|
|
||||||
|
|
||||||
delete this.waMonitor.waInstances[instanceName];
|
|
||||||
this.eventEmitter.emit('remove.instance', instanceName, 'inner');
|
|
||||||
return { status: 'SUCCESS', error: false, response: { message: 'Instance deleted' } };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('deleting instance: ' + instanceName);
|
||||||
|
|
||||||
|
delete this.waMonitor.waInstances[instanceName];
|
||||||
|
this.eventEmitter.emit('remove.instance', instanceName, 'inner');
|
||||||
|
return { status: 'SUCCESS', error: false, response: { message: 'Instance deleted' } };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new BadRequestException(error.toString());
|
throw new BadRequestException(error.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export class SettingsController {
|
|||||||
|
|
||||||
public async findSettings(instance: InstanceDto) {
|
public async findSettings(instance: InstanceDto) {
|
||||||
logger.verbose('requested findSettings from ' + instance.instanceName + ' instance');
|
logger.verbose('requested findSettings from ' + instance.instanceName + ' instance');
|
||||||
return this.settingsService.find(instance);
|
const settings = this.settingsService.find(instance);
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
56
src/whatsapp/controllers/sqs.controller.ts
Normal file
56
src/whatsapp/controllers/sqs.controller.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { SqsDto } from '../dto/sqs.dto';
|
||||||
|
import { SqsService } from '../services/sqs.service';
|
||||||
|
|
||||||
|
const logger = new Logger('SqsController');
|
||||||
|
|
||||||
|
export class SqsController {
|
||||||
|
constructor(private readonly sqsService: SqsService) {}
|
||||||
|
|
||||||
|
public async createSqs(instance: InstanceDto, data: SqsDto) {
|
||||||
|
logger.verbose('requested createSqs from ' + instance.instanceName + ' instance');
|
||||||
|
|
||||||
|
if (!data.enabled) {
|
||||||
|
logger.verbose('sqs disabled');
|
||||||
|
data.events = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.events.length === 0) {
|
||||||
|
logger.verbose('sqs events empty');
|
||||||
|
data.events = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'CALL',
|
||||||
|
'NEW_JWT_TOKEN',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
'CHAMA_AI_ACTION',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.sqsService.create(instance, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async findSqs(instance: InstanceDto) {
|
||||||
|
logger.verbose('requested findSqs from ' + instance.instanceName + ' instance');
|
||||||
|
return this.sqsService.find(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { Request, Response } from 'express';
|
|
||||||
|
|
||||||
import { ConfigService } from '../../config/env.config';
|
|
||||||
import { HttpStatus } from '../routers/index.router';
|
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
|
||||||
|
|
||||||
export class ViewsController {
|
|
||||||
constructor(private readonly waMonit: WAMonitoringService, private readonly configService: ConfigService) {}
|
|
||||||
|
|
||||||
public async manager(request: Request, response: Response) {
|
|
||||||
try {
|
|
||||||
return response.status(HttpStatus.OK).render('manager');
|
|
||||||
} catch (error) {
|
|
||||||
console.log('ERROR: ', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { proto, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '@whiskeysockets/baileys';
|
import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '@whiskeysockets/baileys';
|
||||||
|
|
||||||
export class OnWhatsAppDto {
|
export class OnWhatsAppDto {
|
||||||
constructor(public readonly jid: string, public readonly exists: boolean, public readonly name?: string) {}
|
constructor(public readonly jid: string, public readonly exists: boolean, public readonly name?: string) {}
|
||||||
@@ -83,3 +83,20 @@ export class DeleteMessage {
|
|||||||
remoteJid: string;
|
remoteJid: string;
|
||||||
participant?: string;
|
participant?: string;
|
||||||
}
|
}
|
||||||
|
export class Options {
|
||||||
|
delay?: number;
|
||||||
|
presence?: WAPresence;
|
||||||
|
}
|
||||||
|
class OptionsMessage {
|
||||||
|
options: Options;
|
||||||
|
}
|
||||||
|
export class Metadata extends OptionsMessage {
|
||||||
|
number: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SendPresenceDto extends Metadata {
|
||||||
|
options: {
|
||||||
|
presence: WAPresence;
|
||||||
|
delay: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ export class ChatwootDto {
|
|||||||
number?: string;
|
number?: string;
|
||||||
reopen_conversation?: boolean;
|
reopen_conversation?: boolean;
|
||||||
conversation_pending?: boolean;
|
conversation_pending?: boolean;
|
||||||
|
auto_create?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export class InstanceDto {
|
|||||||
token?: string;
|
token?: string;
|
||||||
webhook?: string;
|
webhook?: string;
|
||||||
webhook_by_events?: boolean;
|
webhook_by_events?: boolean;
|
||||||
|
webhook_base64?: boolean;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
reject_call?: boolean;
|
reject_call?: boolean;
|
||||||
msg_call?: string;
|
msg_call?: string;
|
||||||
@@ -22,6 +23,8 @@ export class InstanceDto {
|
|||||||
websocket_events?: string[];
|
websocket_events?: string[];
|
||||||
rabbitmq_enabled?: boolean;
|
rabbitmq_enabled?: boolean;
|
||||||
rabbitmq_events?: string[];
|
rabbitmq_events?: string[];
|
||||||
|
sqs_enabled?: boolean;
|
||||||
|
sqs_events?: string[];
|
||||||
typebot_url?: string;
|
typebot_url?: string;
|
||||||
typebot?: string;
|
typebot?: string;
|
||||||
typebot_expire?: number;
|
typebot_expire?: number;
|
||||||
@@ -29,6 +32,5 @@ export class InstanceDto {
|
|||||||
typebot_delay_message?: number;
|
typebot_delay_message?: number;
|
||||||
typebot_unknown_message?: string;
|
typebot_unknown_message?: string;
|
||||||
typebot_listening_from_me?: boolean;
|
typebot_listening_from_me?: boolean;
|
||||||
proxy_enabled?: boolean;
|
proxy?: string;
|
||||||
proxy_proxy?: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,13 @@ class PollMessage {
|
|||||||
values: string[];
|
values: string[];
|
||||||
messageSecret?: Uint8Array;
|
messageSecret?: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SendTextDto extends Metadata {
|
export class SendTextDto extends Metadata {
|
||||||
textMessage: TextMessage;
|
textMessage: TextMessage;
|
||||||
}
|
}
|
||||||
|
export class SendPresence extends Metadata {
|
||||||
|
textMessage: TextMessage;
|
||||||
|
}
|
||||||
|
|
||||||
export class SendStatusDto extends Metadata {
|
export class SendStatusDto extends Metadata {
|
||||||
statusMessage: StatusMessage;
|
statusMessage: StatusMessage;
|
||||||
@@ -61,6 +65,7 @@ export class SendPollDto extends Metadata {
|
|||||||
export type MediaType = 'image' | 'document' | 'video' | 'audio';
|
export type MediaType = 'image' | 'document' | 'video' | 'audio';
|
||||||
export class MediaMessage {
|
export class MediaMessage {
|
||||||
mediatype: MediaType;
|
mediatype: MediaType;
|
||||||
|
mimetype?: string;
|
||||||
caption?: string;
|
caption?: string;
|
||||||
// for document
|
// for document
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
|
|||||||
4
src/whatsapp/dto/sqs.dto.ts
Normal file
4
src/whatsapp/dto/sqs.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export class SqsDto {
|
||||||
|
enabled: boolean;
|
||||||
|
events?: string[];
|
||||||
|
}
|
||||||
@@ -3,4 +3,5 @@ export class WebhookDto {
|
|||||||
url?: string;
|
url?: string;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
webhook_by_events?: boolean;
|
webhook_by_events?: boolean;
|
||||||
|
webhook_base64?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export async function instanceLoggedGuard(req: Request, _: Response, next: NextF
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (waMonitor.waInstances[instance.instanceName]) {
|
if (waMonitor.waInstances[instance.instanceName]) {
|
||||||
|
waMonitor.waInstances[instance.instanceName]?.removeRabbitmqQueues();
|
||||||
delete waMonitor.waInstances[instance.instanceName];
|
delete waMonitor.waInstances[instance.instanceName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export * from './message.model';
|
|||||||
export * from './proxy.model';
|
export * from './proxy.model';
|
||||||
export * from './rabbitmq.model';
|
export * from './rabbitmq.model';
|
||||||
export * from './settings.model';
|
export * from './settings.model';
|
||||||
|
export * from './sqs.model';
|
||||||
export * from './typebot.model';
|
export * from './typebot.model';
|
||||||
export * from './webhook.model';
|
export * from './webhook.model';
|
||||||
export * from './websocket.model';
|
export * from './websocket.model';
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export class MessageRaw {
|
|||||||
source?: 'android' | 'web' | 'ios';
|
source?: 'android' | 'web' | 'ios';
|
||||||
source_id?: string;
|
source_id?: string;
|
||||||
source_reply_id?: string;
|
source_reply_id?: string;
|
||||||
|
chatwootMessageId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageSchema = new Schema<MessageRaw>({
|
const messageSchema = new Schema<MessageRaw>({
|
||||||
@@ -39,8 +40,14 @@ const messageSchema = new Schema<MessageRaw>({
|
|||||||
source: { type: String, minlength: 3, enum: ['android', 'web', 'ios'] },
|
source: { type: String, minlength: 3, enum: ['android', 'web', 'ios'] },
|
||||||
messageTimestamp: { type: Number, required: true },
|
messageTimestamp: { type: Number, required: true },
|
||||||
owner: { type: String, required: true, minlength: 1 },
|
owner: { type: String, required: true, minlength: 1 },
|
||||||
|
chatwootMessageId: { type: String, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
messageSchema.index({ chatwootMessageId: 1, owner: 1 });
|
||||||
|
messageSchema.index({ 'key.id': 1 });
|
||||||
|
messageSchema.index({ 'key.id': 1, owner: 1 });
|
||||||
|
messageSchema.index({ owner: 1 });
|
||||||
|
|
||||||
export const MessageModel = dbserver?.model(MessageRaw.name, messageSchema, 'messages');
|
export const MessageModel = dbserver?.model(MessageRaw.name, messageSchema, 'messages');
|
||||||
export type IMessageModel = typeof MessageModel;
|
export type IMessageModel = typeof MessageModel;
|
||||||
|
|
||||||
|
|||||||
18
src/whatsapp/models/sqs.model.ts
Normal file
18
src/whatsapp/models/sqs.model.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Schema } from 'mongoose';
|
||||||
|
|
||||||
|
import { dbserver } from '../../libs/db.connect';
|
||||||
|
|
||||||
|
export class SqsRaw {
|
||||||
|
_id?: string;
|
||||||
|
enabled?: boolean;
|
||||||
|
events?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const sqsSchema = new Schema<SqsRaw>({
|
||||||
|
_id: { type: String, _id: true },
|
||||||
|
enabled: { type: Boolean, required: true },
|
||||||
|
events: { type: [String], required: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
export const SqsModel = dbserver?.model(SqsRaw.name, sqsSchema, 'sqs');
|
||||||
|
export type ISqsModel = typeof SqsModel;
|
||||||
@@ -48,7 +48,7 @@ const typebotSchema = new Schema<TypebotRaw>({
|
|||||||
prefilledVariables: {
|
prefilledVariables: {
|
||||||
remoteJid: { type: String, required: false },
|
remoteJid: { type: String, required: false },
|
||||||
pushName: { type: String, required: false },
|
pushName: { type: String, required: false },
|
||||||
additionalData: { type: Schema.Types.Mixed, required: false }
|
additionalData: { type: Schema.Types.Mixed, required: false },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export class WebhookRaw {
|
|||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
webhook_by_events?: boolean;
|
webhook_by_events?: boolean;
|
||||||
|
webhook_base64?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const webhookSchema = new Schema<WebhookRaw>({
|
const webhookSchema = new Schema<WebhookRaw>({
|
||||||
@@ -16,6 +17,7 @@ const webhookSchema = new Schema<WebhookRaw>({
|
|||||||
enabled: { type: Boolean, required: true },
|
enabled: { type: Boolean, required: true },
|
||||||
events: { type: [String], required: true },
|
events: { type: [String], required: true },
|
||||||
webhook_by_events: { type: Boolean, required: true },
|
webhook_by_events: { type: Boolean, required: true },
|
||||||
|
webhook_base64: { type: Boolean, required: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const WebhookModel = dbserver?.model(WebhookRaw.name, webhookSchema, 'webhook');
|
export const WebhookModel = dbserver?.model(WebhookRaw.name, webhookSchema, 'webhook');
|
||||||
|
|||||||
@@ -144,4 +144,55 @@ export class MessageRepository extends Repository {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async update(data: MessageRaw[], instanceName: string, saveDb?: boolean): Promise<IInsert> {
|
||||||
|
try {
|
||||||
|
if (this.dbSettings.ENABLED && saveDb) {
|
||||||
|
this.logger.verbose('updating messages in db');
|
||||||
|
|
||||||
|
const messages = data.map((message) => {
|
||||||
|
return {
|
||||||
|
updateOne: {
|
||||||
|
filter: { 'key.id': message.key.id },
|
||||||
|
update: { ...message },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const { nModified } = await this.messageModel.bulkWrite(messages);
|
||||||
|
|
||||||
|
this.logger.verbose('messages updated in db: ' + nModified + ' messages');
|
||||||
|
return { insertCount: nModified };
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('updating messages in store');
|
||||||
|
|
||||||
|
const store = this.configService.get<StoreConf>('STORE');
|
||||||
|
|
||||||
|
if (store.MESSAGES) {
|
||||||
|
this.logger.verbose('updating messages in store');
|
||||||
|
data.forEach((message) => {
|
||||||
|
this.writeStore({
|
||||||
|
path: join(this.storePath, 'messages', instanceName),
|
||||||
|
fileName: message.key.id,
|
||||||
|
data: message,
|
||||||
|
});
|
||||||
|
this.logger.verbose(
|
||||||
|
'messages updated in store in path: ' +
|
||||||
|
join(this.storePath, 'messages', instanceName) +
|
||||||
|
'/' +
|
||||||
|
message.key.id,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.verbose('messages updated in store: ' + data.length + ' messages');
|
||||||
|
return { insertCount: data.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('messages not updated');
|
||||||
|
return { insertCount: 0 };
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { MessageUpRepository } from './messageUp.repository';
|
|||||||
import { ProxyRepository } from './proxy.repository';
|
import { ProxyRepository } from './proxy.repository';
|
||||||
import { RabbitmqRepository } from './rabbitmq.repository';
|
import { RabbitmqRepository } from './rabbitmq.repository';
|
||||||
import { SettingsRepository } from './settings.repository';
|
import { SettingsRepository } from './settings.repository';
|
||||||
|
import { SqsRepository } from './sqs.repository';
|
||||||
import { TypebotRepository } from './typebot.repository';
|
import { TypebotRepository } from './typebot.repository';
|
||||||
import { WebhookRepository } from './webhook.repository';
|
import { WebhookRepository } from './webhook.repository';
|
||||||
import { WebsocketRepository } from './websocket.repository';
|
import { WebsocketRepository } from './websocket.repository';
|
||||||
@@ -28,6 +29,7 @@ export class RepositoryBroker {
|
|||||||
public readonly settings: SettingsRepository,
|
public readonly settings: SettingsRepository,
|
||||||
public readonly websocket: WebsocketRepository,
|
public readonly websocket: WebsocketRepository,
|
||||||
public readonly rabbitmq: RabbitmqRepository,
|
public readonly rabbitmq: RabbitmqRepository,
|
||||||
|
public readonly sqs: SqsRepository,
|
||||||
public readonly typebot: TypebotRepository,
|
public readonly typebot: TypebotRepository,
|
||||||
public readonly proxy: ProxyRepository,
|
public readonly proxy: ProxyRepository,
|
||||||
public readonly chamaai: ChamaaiRepository,
|
public readonly chamaai: ChamaaiRepository,
|
||||||
@@ -63,6 +65,7 @@ export class RepositoryBroker {
|
|||||||
const settingsDir = join(storePath, 'settings');
|
const settingsDir = join(storePath, 'settings');
|
||||||
const websocketDir = join(storePath, 'websocket');
|
const websocketDir = join(storePath, 'websocket');
|
||||||
const rabbitmqDir = join(storePath, 'rabbitmq');
|
const rabbitmqDir = join(storePath, 'rabbitmq');
|
||||||
|
const sqsDir = join(storePath, 'sqs');
|
||||||
const typebotDir = join(storePath, 'typebot');
|
const typebotDir = join(storePath, 'typebot');
|
||||||
const proxyDir = join(storePath, 'proxy');
|
const proxyDir = join(storePath, 'proxy');
|
||||||
const chamaaiDir = join(storePath, 'chamaai');
|
const chamaaiDir = join(storePath, 'chamaai');
|
||||||
@@ -108,6 +111,10 @@ export class RepositoryBroker {
|
|||||||
this.logger.verbose('creating rabbitmq dir: ' + rabbitmqDir);
|
this.logger.verbose('creating rabbitmq dir: ' + rabbitmqDir);
|
||||||
fs.mkdirSync(rabbitmqDir, { recursive: true });
|
fs.mkdirSync(rabbitmqDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
if (!fs.existsSync(sqsDir)) {
|
||||||
|
this.logger.verbose('creating sqs dir: ' + sqsDir);
|
||||||
|
fs.mkdirSync(sqsDir, { recursive: true });
|
||||||
|
}
|
||||||
if (!fs.existsSync(typebotDir)) {
|
if (!fs.existsSync(typebotDir)) {
|
||||||
this.logger.verbose('creating typebot dir: ' + typebotDir);
|
this.logger.verbose('creating typebot dir: ' + typebotDir);
|
||||||
fs.mkdirSync(typebotDir, { recursive: true });
|
fs.mkdirSync(typebotDir, { recursive: true });
|
||||||
|
|||||||
62
src/whatsapp/repository/sqs.repository.ts
Normal file
62
src/whatsapp/repository/sqs.repository.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
import { ConfigService } from '../../config/env.config';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
|
import { ISqsModel, SqsRaw } from '../models';
|
||||||
|
|
||||||
|
export class SqsRepository extends Repository {
|
||||||
|
constructor(private readonly sqsModel: ISqsModel, private readonly configService: ConfigService) {
|
||||||
|
super(configService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly logger = new Logger('SqsRepository');
|
||||||
|
|
||||||
|
public async create(data: SqsRaw, instance: string): Promise<IInsert> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('creating sqs');
|
||||||
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('saving sqs to db');
|
||||||
|
const insert = await this.sqsModel.replaceOne({ _id: instance }, { ...data }, { upsert: true });
|
||||||
|
|
||||||
|
this.logger.verbose('sqs saved to db: ' + insert.modifiedCount + ' sqs');
|
||||||
|
return { insertCount: insert.modifiedCount };
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving sqs to store');
|
||||||
|
|
||||||
|
this.writeStore<SqsRaw>({
|
||||||
|
path: join(this.storePath, 'sqs'),
|
||||||
|
fileName: instance,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.verbose('sqs saved to store in path: ' + join(this.storePath, 'sqs') + '/' + instance);
|
||||||
|
|
||||||
|
this.logger.verbose('sqs created');
|
||||||
|
return { insertCount: 1 };
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async find(instance: string): Promise<SqsRaw> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('finding sqs');
|
||||||
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding sqs in db');
|
||||||
|
return await this.sqsModel.findOne({ _id: instance });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding sqs in store');
|
||||||
|
return JSON.parse(
|
||||||
|
readFileSync(join(this.storePath, 'sqs', instance + '.json'), {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
}),
|
||||||
|
) as SqsRaw;
|
||||||
|
} catch (error) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
deleteMessageSchema,
|
deleteMessageSchema,
|
||||||
messageUpSchema,
|
messageUpSchema,
|
||||||
messageValidateSchema,
|
messageValidateSchema,
|
||||||
|
presenceSchema,
|
||||||
privacySettingsSchema,
|
privacySettingsSchema,
|
||||||
profileNameSchema,
|
profileNameSchema,
|
||||||
profilePictureSchema,
|
profilePictureSchema,
|
||||||
@@ -26,6 +27,7 @@ import {
|
|||||||
ProfilePictureDto,
|
ProfilePictureDto,
|
||||||
ProfileStatusDto,
|
ProfileStatusDto,
|
||||||
ReadMessageDto,
|
ReadMessageDto,
|
||||||
|
SendPresenceDto,
|
||||||
WhatsAppNumberDto,
|
WhatsAppNumberDto,
|
||||||
} from '../dto/chat.dto';
|
} from '../dto/chat.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
@@ -228,6 +230,22 @@ export class ChatRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
|
.post(this.routerPath('sendPresence'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendPresence');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.dataValidate<null>({
|
||||||
|
request: req,
|
||||||
|
schema: presenceSchema,
|
||||||
|
ClassRef: SendPresenceDto,
|
||||||
|
execute: (instance, data) => chatController.sendPresence(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
|
})
|
||||||
// Profile routes
|
// Profile routes
|
||||||
.get(this.routerPath('fetchPrivacySettings'), ...guards, async (req, res) => {
|
.get(this.routerPath('fetchPrivacySettings'), ...guards, async (req, res) => {
|
||||||
logger.verbose('request received in fetchPrivacySettings');
|
logger.verbose('request received in fetchPrivacySettings');
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { ProxyRouter } from './proxy.router';
|
|||||||
import { RabbitmqRouter } from './rabbitmq.router';
|
import { RabbitmqRouter } from './rabbitmq.router';
|
||||||
import { MessageRouter } from './sendMessage.router';
|
import { MessageRouter } from './sendMessage.router';
|
||||||
import { SettingsRouter } from './settings.router';
|
import { SettingsRouter } from './settings.router';
|
||||||
|
import { SqsRouter } from './sqs.router';
|
||||||
import { TypebotRouter } from './typebot.router';
|
import { TypebotRouter } from './typebot.router';
|
||||||
import { ViewsRouter } from './view.router';
|
import { ViewsRouter } from './view.router';
|
||||||
import { WebhookRouter } from './webhook.router';
|
import { WebhookRouter } from './webhook.router';
|
||||||
@@ -40,6 +41,8 @@ router
|
|||||||
status: HttpStatus.OK,
|
status: HttpStatus.OK,
|
||||||
message: 'Welcome to the Evolution API, it is working!',
|
message: 'Welcome to the Evolution API, it is working!',
|
||||||
version: packageJson.version,
|
version: packageJson.version,
|
||||||
|
documentation: `${req.protocol}://${req.get('host')}/docs`,
|
||||||
|
manager: `${req.protocol}://${req.get('host')}/manager`,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.use('/instance', new InstanceRouter(configService, ...guards).router)
|
.use('/instance', new InstanceRouter(configService, ...guards).router)
|
||||||
@@ -52,6 +55,7 @@ router
|
|||||||
.use('/settings', new SettingsRouter(...guards).router)
|
.use('/settings', new SettingsRouter(...guards).router)
|
||||||
.use('/websocket', new WebsocketRouter(...guards).router)
|
.use('/websocket', new WebsocketRouter(...guards).router)
|
||||||
.use('/rabbitmq', new RabbitmqRouter(...guards).router)
|
.use('/rabbitmq', new RabbitmqRouter(...guards).router)
|
||||||
|
.use('/sqs', new SqsRouter(...guards).router)
|
||||||
.use('/typebot', new TypebotRouter(...guards).router)
|
.use('/typebot', new TypebotRouter(...guards).router)
|
||||||
.use('/proxy', new ProxyRouter(...guards).router)
|
.use('/proxy', new ProxyRouter(...guards).router)
|
||||||
.use('/chamaai', new ChamaaiRouter(...guards).router);
|
.use('/chamaai', new ChamaaiRouter(...guards).router);
|
||||||
|
|||||||
52
src/whatsapp/routers/sqs.router.ts
Normal file
52
src/whatsapp/routers/sqs.router.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
import { instanceNameSchema, sqsSchema } from '../../validate/validate.schema';
|
||||||
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { SqsDto } from '../dto/sqs.dto';
|
||||||
|
import { sqsController } from '../whatsapp.module';
|
||||||
|
import { HttpStatus } from './index.router';
|
||||||
|
|
||||||
|
const logger = new Logger('SqsRouter');
|
||||||
|
|
||||||
|
export class SqsRouter extends RouterBroker {
|
||||||
|
constructor(...guards: RequestHandler[]) {
|
||||||
|
super();
|
||||||
|
this.router
|
||||||
|
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in setSqs');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.dataValidate<SqsDto>({
|
||||||
|
request: req,
|
||||||
|
schema: sqsSchema,
|
||||||
|
ClassRef: SqsDto,
|
||||||
|
execute: (instance, data) => sqsController.createSqs(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
|
})
|
||||||
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findSqs');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
|
request: req,
|
||||||
|
schema: instanceNameSchema,
|
||||||
|
ClassRef: InstanceDto,
|
||||||
|
execute: (instance) => sqsController.findSqs(instance),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly router = Router();
|
||||||
|
}
|
||||||
@@ -1,14 +1,32 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
import fs from 'fs';
|
||||||
|
import mime from 'mime-types';
|
||||||
|
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import { viewsController } from '../whatsapp.module';
|
|
||||||
|
|
||||||
export class ViewsRouter extends RouterBroker {
|
export class ViewsRouter extends RouterBroker {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.router.get('/', (req, res) => {
|
const basePath = 'evolution-manager/dist';
|
||||||
return viewsController.manager(req, res);
|
|
||||||
|
const indexPath = require.resolve(`${basePath}/index.html`);
|
||||||
|
|
||||||
|
this.router.get('/*', (req, res) => {
|
||||||
|
try {
|
||||||
|
const pathname = req.url.split('?')[0];
|
||||||
|
|
||||||
|
// verify if url is a file in dist folder
|
||||||
|
if (pathname === '/') throw {};
|
||||||
|
const filePath = require.resolve(`${basePath}${pathname}`);
|
||||||
|
|
||||||
|
const contentType = mime.lookup(filePath) || 'text/plain';
|
||||||
|
res.set('Content-Type', contentType);
|
||||||
|
res.end(fs.readFileSync(filePath));
|
||||||
|
} catch {
|
||||||
|
res.set('Content-Type', 'text/html');
|
||||||
|
res.send(fs.readFileSync(indexPath));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import Jimp from 'jimp';
|
|||||||
import mimeTypes from 'mime-types';
|
import mimeTypes from 'mime-types';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { ConfigService } from '../../config/env.config';
|
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { ROOT_DIR } from '../../config/path.config';
|
import { ROOT_DIR } from '../../config/path.config';
|
||||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { SendAudioDto, SendMediaDto, SendTextDto } from '../dto/sendMessage.dto';
|
import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '../dto/sendMessage.dto';
|
||||||
|
import { MessageRaw } from '../models';
|
||||||
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
import { WAMonitoringService } from './monitor.service';
|
import { WAMonitoringService } from './monitor.service';
|
||||||
|
|
||||||
export class ChatwootService {
|
export class ChatwootService {
|
||||||
@@ -22,7 +24,11 @@ export class ChatwootService {
|
|||||||
|
|
||||||
private provider: any;
|
private provider: any;
|
||||||
|
|
||||||
constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {
|
constructor(
|
||||||
|
private readonly waMonitor: WAMonitoringService,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
private readonly repository: RepositoryBroker,
|
||||||
|
) {
|
||||||
this.messageCache = new Set();
|
this.messageCache = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,25 +58,26 @@ export class ChatwootService {
|
|||||||
|
|
||||||
private async getProvider(instance: InstanceDto) {
|
private async getProvider(instance: InstanceDto) {
|
||||||
this.logger.verbose('get provider to instance: ' + instance.instanceName);
|
this.logger.verbose('get provider to instance: ' + instance.instanceName);
|
||||||
try {
|
const provider = await this.waMonitor.waInstances[instance.instanceName]?.findChatwoot();
|
||||||
const provider = await this.waMonitor.waInstances[instance.instanceName].findChatwoot();
|
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
this.logger.warn('provider not found');
|
this.logger.warn('provider not found');
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.verbose('provider found');
|
|
||||||
|
|
||||||
return provider;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('provider not found');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('provider found');
|
||||||
|
|
||||||
|
return provider;
|
||||||
|
// try {
|
||||||
|
// } catch (error) {
|
||||||
|
// this.logger.error('provider not found');
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private async clientCw(instance: InstanceDto) {
|
private async clientCw(instance: InstanceDto) {
|
||||||
this.logger.verbose('get client to instance: ' + instance.instanceName);
|
this.logger.verbose('get client to instance: ' + instance.instanceName);
|
||||||
|
|
||||||
const provider = await this.getProvider(instance);
|
const provider = await this.getProvider(instance);
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
@@ -97,11 +104,24 @@ export class ChatwootService {
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public create(instance: InstanceDto, data: ChatwootDto) {
|
public async create(instance: InstanceDto, data: ChatwootDto) {
|
||||||
this.logger.verbose('create chatwoot: ' + instance.instanceName);
|
this.logger.verbose('create chatwoot: ' + instance.instanceName);
|
||||||
this.waMonitor.waInstances[instance.instanceName].setChatwoot(data);
|
|
||||||
|
await this.waMonitor.waInstances[instance.instanceName].setChatwoot(data);
|
||||||
|
|
||||||
this.logger.verbose('chatwoot created');
|
this.logger.verbose('chatwoot created');
|
||||||
|
|
||||||
|
if (data.auto_create) {
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
await this.initInstanceChatwoot(
|
||||||
|
instance,
|
||||||
|
instance.instanceName.split('-cwId-')[0],
|
||||||
|
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
||||||
|
true,
|
||||||
|
data.number,
|
||||||
|
);
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,10 +249,6 @@ export class ChatwootService {
|
|||||||
inbox_id: inboxId.toString(),
|
inbox_id: inboxId.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.provider.conversation_pending) {
|
|
||||||
data['status'] = 'pending';
|
|
||||||
}
|
|
||||||
|
|
||||||
const conversation = await client.conversations.create({
|
const conversation = await client.conversations.create({
|
||||||
accountId: this.provider.account_id,
|
accountId: this.provider.account_id,
|
||||||
data,
|
data,
|
||||||
@@ -338,14 +354,18 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('update contact in chatwoot');
|
this.logger.verbose('update contact in chatwoot');
|
||||||
const contact = await client.contacts.update({
|
try {
|
||||||
accountId: this.provider.account_id,
|
const contact = await client.contacts.update({
|
||||||
id,
|
accountId: this.provider.account_id,
|
||||||
data,
|
id,
|
||||||
});
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
this.logger.verbose('contact updated');
|
this.logger.verbose('contact updated');
|
||||||
return contact;
|
return contact;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findContact(instance: InstanceDto, phoneNumber: string) {
|
public async findContact(instance: InstanceDto, phoneNumber: string) {
|
||||||
@@ -488,6 +508,9 @@ export class ChatwootService {
|
|||||||
avatar_url: picture_url.profilePictureUrl || null,
|
avatar_url: picture_url.profilePictureUrl || null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!contact) {
|
||||||
|
contact = await this.findContact(instance, chatId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const jid = isGroup ? null : body.key.remoteJid;
|
const jid = isGroup ? null : body.key.remoteJid;
|
||||||
contact = await this.createContact(
|
contact = await this.createContact(
|
||||||
@@ -619,6 +642,7 @@ export class ChatwootService {
|
|||||||
encoding: string;
|
encoding: string;
|
||||||
filename: string;
|
filename: string;
|
||||||
}[],
|
}[],
|
||||||
|
messageBody?: any,
|
||||||
) {
|
) {
|
||||||
this.logger.verbose('create message to instance: ' + instance.instanceName);
|
this.logger.verbose('create message to instance: ' + instance.instanceName);
|
||||||
|
|
||||||
@@ -629,6 +653,8 @@ export class ChatwootService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const replyToIds = await this.getReplyToIds(messageBody, instance);
|
||||||
|
|
||||||
this.logger.verbose('create message in chatwoot');
|
this.logger.verbose('create message in chatwoot');
|
||||||
const message = await client.messages.create({
|
const message = await client.messages.create({
|
||||||
accountId: this.provider.account_id,
|
accountId: this.provider.account_id,
|
||||||
@@ -638,6 +664,9 @@ export class ChatwootService {
|
|||||||
message_type: messageType,
|
message_type: messageType,
|
||||||
attachments: attachments,
|
attachments: attachments,
|
||||||
private: privateMessage || false,
|
private: privateMessage || false,
|
||||||
|
content_attributes: {
|
||||||
|
...replyToIds,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -733,6 +762,8 @@ export class ChatwootService {
|
|||||||
file: string,
|
file: string,
|
||||||
messageType: 'incoming' | 'outgoing' | undefined,
|
messageType: 'incoming' | 'outgoing' | undefined,
|
||||||
content?: string,
|
content?: string,
|
||||||
|
instance?: InstanceDto,
|
||||||
|
messageBody?: any,
|
||||||
) {
|
) {
|
||||||
this.logger.verbose('send data to chatwoot');
|
this.logger.verbose('send data to chatwoot');
|
||||||
|
|
||||||
@@ -749,6 +780,16 @@ export class ChatwootService {
|
|||||||
this.logger.verbose('temp file found');
|
this.logger.verbose('temp file found');
|
||||||
data.append('attachments[]', createReadStream(file));
|
data.append('attachments[]', createReadStream(file));
|
||||||
|
|
||||||
|
if (messageBody && instance) {
|
||||||
|
const replyToIds = await this.getReplyToIds(messageBody, instance);
|
||||||
|
|
||||||
|
if (replyToIds.in_reply_to || replyToIds.in_reply_to_external_id) {
|
||||||
|
data.append('content_attributes', {
|
||||||
|
...replyToIds,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.verbose('get client to instance: ' + this.provider.instanceName);
|
this.logger.verbose('get client to instance: ' + this.provider.instanceName);
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
@@ -869,7 +910,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendAttachment(waInstance: any, number: string, media: any, caption?: string) {
|
public async sendAttachment(waInstance: any, number: string, media: any, caption?: string, options?: Options) {
|
||||||
this.logger.verbose('send attachment to instance: ' + waInstance.instanceName);
|
this.logger.verbose('send attachment to instance: ' + waInstance.instanceName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -911,13 +952,14 @@ export class ChatwootService {
|
|||||||
options: {
|
options: {
|
||||||
delay: 1200,
|
delay: 1200,
|
||||||
presence: 'recording',
|
presence: 'recording',
|
||||||
|
...options,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await waInstance?.audioWhatsapp(data);
|
const messageSent = await waInstance?.audioWhatsapp(data, true);
|
||||||
|
|
||||||
this.logger.verbose('audio sent');
|
this.logger.verbose('audio sent');
|
||||||
return;
|
return messageSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('send media to instance: ' + waInstance.instanceName);
|
this.logger.verbose('send media to instance: ' + waInstance.instanceName);
|
||||||
@@ -931,6 +973,7 @@ export class ChatwootService {
|
|||||||
options: {
|
options: {
|
||||||
delay: 1200,
|
delay: 1200,
|
||||||
presence: 'composing',
|
presence: 'composing',
|
||||||
|
...options,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -939,10 +982,10 @@ export class ChatwootService {
|
|||||||
data.mediaMessage.caption = caption;
|
data.mediaMessage.caption = caption;
|
||||||
}
|
}
|
||||||
|
|
||||||
await waInstance?.mediaMessage(data);
|
const messageSent = await waInstance?.mediaMessage(data, true);
|
||||||
|
|
||||||
this.logger.verbose('media sent');
|
this.logger.verbose('media sent');
|
||||||
return;
|
return messageSent;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
@@ -961,7 +1004,13 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('check if is bot');
|
this.logger.verbose('check if is bot');
|
||||||
if (!body?.conversation || body.private || body.event === 'message_updated') return { message: 'bot' };
|
if (
|
||||||
|
!body?.conversation ||
|
||||||
|
body.private ||
|
||||||
|
(body.event === 'message_updated' && !body.content_attributes?.deleted)
|
||||||
|
) {
|
||||||
|
return { message: 'bot' };
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.verbose('check if is group');
|
this.logger.verbose('check if is group');
|
||||||
const chatId =
|
const chatId =
|
||||||
@@ -970,6 +1019,21 @@ export class ChatwootService {
|
|||||||
const senderName = body?.sender?.name;
|
const senderName = body?.sender?.name;
|
||||||
const waInstance = this.waMonitor.waInstances[instance.instanceName];
|
const waInstance = this.waMonitor.waInstances[instance.instanceName];
|
||||||
|
|
||||||
|
this.logger.verbose('check if is a message deletion');
|
||||||
|
if (body.event === 'message_updated' && body.content_attributes?.deleted) {
|
||||||
|
const message = await this.repository.message.find({
|
||||||
|
where: {
|
||||||
|
owner: instance.instanceName,
|
||||||
|
chatwootMessageId: body.id,
|
||||||
|
},
|
||||||
|
limit: 1,
|
||||||
|
});
|
||||||
|
if (message.length && message[0].key?.id) {
|
||||||
|
await waInstance?.client.sendMessage(message[0].key.remoteJid, { delete: message[0].key });
|
||||||
|
}
|
||||||
|
return { message: 'bot' };
|
||||||
|
}
|
||||||
|
|
||||||
if (chatId === '123456' && body.message_type === 'outgoing') {
|
if (chatId === '123456' && body.message_type === 'outgoing') {
|
||||||
this.logger.verbose('check if is command');
|
this.logger.verbose('check if is command');
|
||||||
|
|
||||||
@@ -980,6 +1044,10 @@ export class ChatwootService {
|
|||||||
const state = waInstance?.connectionStatus?.state;
|
const state = waInstance?.connectionStatus?.state;
|
||||||
|
|
||||||
if (state !== 'open') {
|
if (state !== 'open') {
|
||||||
|
if (state === 'close') {
|
||||||
|
this.logger.verbose('request cleaning up instance: ' + instance.instanceName);
|
||||||
|
// await this.waMonitor.cleaningUp(instance.instanceName);
|
||||||
|
}
|
||||||
this.logger.verbose('connect to whatsapp');
|
this.logger.verbose('connect to whatsapp');
|
||||||
const number = command.split(':')[1];
|
const number = command.split(':')[1];
|
||||||
await waInstance.connectToWhatsapp(number);
|
await waInstance.connectToWhatsapp(number);
|
||||||
@@ -1057,7 +1125,26 @@ export class ChatwootService {
|
|||||||
formatText = null;
|
formatText = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.sendAttachment(waInstance, chatId, attachment.data_url, formatText);
|
const options: Options = {
|
||||||
|
quoted: await this.getQuotedMessage(body, instance),
|
||||||
|
};
|
||||||
|
|
||||||
|
const messageSent = await this.sendAttachment(
|
||||||
|
waInstance,
|
||||||
|
chatId,
|
||||||
|
attachment.data_url,
|
||||||
|
formatText,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.updateChatwootMessageId(
|
||||||
|
{
|
||||||
|
...messageSent,
|
||||||
|
owner: instance.instanceName,
|
||||||
|
},
|
||||||
|
body.id,
|
||||||
|
instance,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('message is text');
|
this.logger.verbose('message is text');
|
||||||
@@ -1071,10 +1158,20 @@ export class ChatwootService {
|
|||||||
options: {
|
options: {
|
||||||
delay: 1200,
|
delay: 1200,
|
||||||
presence: 'composing',
|
presence: 'composing',
|
||||||
|
quoted: await this.getQuotedMessage(body, instance),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await waInstance?.textMessage(data);
|
const messageSent = await waInstance?.textMessage(data, true);
|
||||||
|
|
||||||
|
this.updateChatwootMessageId(
|
||||||
|
{
|
||||||
|
...messageSent,
|
||||||
|
owner: instance.instanceName,
|
||||||
|
},
|
||||||
|
body.id,
|
||||||
|
instance,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1106,6 +1203,65 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateChatwootMessageId(message: MessageRaw, chatwootMessageId: string, instance: InstanceDto) {
|
||||||
|
if (!chatwootMessageId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
message.chatwootMessageId = chatwootMessageId;
|
||||||
|
this.repository.message.update([message], instance.instanceName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getReplyToIds(
|
||||||
|
msg: any,
|
||||||
|
instance: InstanceDto,
|
||||||
|
): Promise<{ in_reply_to: string; in_reply_to_external_id: string }> {
|
||||||
|
let inReplyTo = null;
|
||||||
|
let inReplyToExternalId = null;
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
inReplyToExternalId = msg.message?.extendedTextMessage?.contextInfo?.stanzaId;
|
||||||
|
if (inReplyToExternalId) {
|
||||||
|
const message = await this.repository.message.find({
|
||||||
|
where: {
|
||||||
|
key: {
|
||||||
|
id: inReplyToExternalId,
|
||||||
|
},
|
||||||
|
owner: instance.instanceName,
|
||||||
|
},
|
||||||
|
limit: 1,
|
||||||
|
});
|
||||||
|
if (message.length && message[0]?.chatwootMessageId) {
|
||||||
|
inReplyTo = message[0].chatwootMessageId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
in_reply_to: inReplyTo,
|
||||||
|
in_reply_to_external_id: inReplyToExternalId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getQuotedMessage(msg: any, instance: InstanceDto): Promise<Quoted> {
|
||||||
|
if (msg?.content_attributes?.in_reply_to) {
|
||||||
|
const message = await this.repository.message.find({
|
||||||
|
where: {
|
||||||
|
chatwootMessageId: msg?.content_attributes?.in_reply_to,
|
||||||
|
owner: instance.instanceName,
|
||||||
|
},
|
||||||
|
limit: 1,
|
||||||
|
});
|
||||||
|
if (message.length && message[0]?.key?.id) {
|
||||||
|
return {
|
||||||
|
key: message[0].key,
|
||||||
|
message: message[0].message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private isMediaMessage(message: any) {
|
private isMediaMessage(message: any) {
|
||||||
this.logger.verbose('check if is media message');
|
this.logger.verbose('check if is media message');
|
||||||
const media = [
|
const media = [
|
||||||
@@ -1132,13 +1288,25 @@ export class ChatwootService {
|
|||||||
thumbnailUrl: string;
|
thumbnailUrl: string;
|
||||||
sourceUrl: string;
|
sourceUrl: string;
|
||||||
}
|
}
|
||||||
const adsMessage: AdsMessage | undefined = msg.extendedTextMessage?.contextInfo.externalAdReply;
|
const adsMessage: AdsMessage | undefined = msg.extendedTextMessage?.contextInfo?.externalAdReply;
|
||||||
|
|
||||||
this.logger.verbose('Get ads message if it exist');
|
this.logger.verbose('Get ads message if it exist');
|
||||||
adsMessage && this.logger.verbose('Ads message: ' + adsMessage);
|
adsMessage && this.logger.verbose('Ads message: ' + adsMessage);
|
||||||
return adsMessage;
|
return adsMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getReactionMessage(msg: any) {
|
||||||
|
interface ReactionMessage {
|
||||||
|
key: MessageRaw['key'];
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
const reactionMessage: ReactionMessage | undefined = msg?.reactionMessage;
|
||||||
|
|
||||||
|
this.logger.verbose('Get reaction message if it exists');
|
||||||
|
reactionMessage && this.logger.verbose('Reaction message: ' + reactionMessage);
|
||||||
|
return reactionMessage;
|
||||||
|
}
|
||||||
|
|
||||||
private getTypeMessage(msg: any) {
|
private getTypeMessage(msg: any) {
|
||||||
this.logger.verbose('get type message');
|
this.logger.verbose('get type message');
|
||||||
|
|
||||||
@@ -1205,6 +1373,11 @@ export class ChatwootService {
|
|||||||
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
|
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
|
||||||
numberCount++;
|
numberCount++;
|
||||||
}
|
}
|
||||||
|
if (key.includes('TEL')) {
|
||||||
|
const phoneNumber = contactInfo[key];
|
||||||
|
formattedContact += `\n**number:** ${phoneNumber}`;
|
||||||
|
numberCount++;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.verbose('message content: ' + formattedContact);
|
this.logger.verbose('message content: ' + formattedContact);
|
||||||
@@ -1233,6 +1406,11 @@ export class ChatwootService {
|
|||||||
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
|
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
|
||||||
numberCount++;
|
numberCount++;
|
||||||
}
|
}
|
||||||
|
if (key.includes('TEL')) {
|
||||||
|
const phoneNumber = contactInfo[key];
|
||||||
|
formattedContact += `\n**number:** ${phoneNumber}`;
|
||||||
|
numberCount++;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return formattedContact;
|
return formattedContact;
|
||||||
@@ -1265,13 +1443,6 @@ export class ChatwootService {
|
|||||||
public async eventWhatsapp(event: string, instance: InstanceDto, body: any) {
|
public async eventWhatsapp(event: string, instance: InstanceDto, body: any) {
|
||||||
this.logger.verbose('event whatsapp to instance: ' + instance.instanceName);
|
this.logger.verbose('event whatsapp to instance: ' + instance.instanceName);
|
||||||
try {
|
try {
|
||||||
const client = await this.clientCw(instance);
|
|
||||||
|
|
||||||
if (!client) {
|
|
||||||
this.logger.warn('client not found');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const waInstance = this.waMonitor.waInstances[instance.instanceName];
|
const waInstance = this.waMonitor.waInstances[instance.instanceName];
|
||||||
|
|
||||||
if (!waInstance) {
|
if (!waInstance) {
|
||||||
@@ -1279,7 +1450,14 @@ export class ChatwootService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event === 'messages.upsert') {
|
const client = await this.clientCw(instance);
|
||||||
|
|
||||||
|
if (!client) {
|
||||||
|
this.logger.warn('client not found');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === 'messages.upsert' || event === 'send.message') {
|
||||||
this.logger.verbose('event messages.upsert');
|
this.logger.verbose('event messages.upsert');
|
||||||
|
|
||||||
if (body.key.remoteJid === 'status@broadcast') {
|
if (body.key.remoteJid === 'status@broadcast') {
|
||||||
@@ -1290,11 +1468,18 @@ export class ChatwootService {
|
|||||||
this.logger.verbose('get conversation message');
|
this.logger.verbose('get conversation message');
|
||||||
const bodyMessage = await this.getConversationMessage(body.message);
|
const bodyMessage = await this.getConversationMessage(body.message);
|
||||||
|
|
||||||
|
if (bodyMessage && bodyMessage.includes('Por favor, classifique esta conversa, http')) {
|
||||||
|
this.logger.verbose('conversation is closed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const isMedia = this.isMediaMessage(body.message);
|
const isMedia = this.isMediaMessage(body.message);
|
||||||
|
|
||||||
const adsMessage = this.getAdsMessage(body.message);
|
const adsMessage = this.getAdsMessage(body.message);
|
||||||
|
|
||||||
if (!bodyMessage && !isMedia) {
|
const reactionMessage = this.getReactionMessage(body.message);
|
||||||
|
|
||||||
|
if (!bodyMessage && !isMedia && !reactionMessage) {
|
||||||
this.logger.warn('no body message found');
|
this.logger.warn('no body message found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1353,7 +1538,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('send data to chatwoot');
|
this.logger.verbose('send data to chatwoot');
|
||||||
const send = await this.sendData(getConversation, fileName, messageType, content);
|
const send = await this.sendData(getConversation, fileName, messageType, content, instance, body);
|
||||||
|
|
||||||
if (!send) {
|
if (!send) {
|
||||||
this.logger.warn('message not sent');
|
this.logger.warn('message not sent');
|
||||||
@@ -1374,7 +1559,7 @@ export class ChatwootService {
|
|||||||
this.logger.verbose('message is not group');
|
this.logger.verbose('message is not group');
|
||||||
|
|
||||||
this.logger.verbose('send data to chatwoot');
|
this.logger.verbose('send data to chatwoot');
|
||||||
const send = await this.sendData(getConversation, fileName, messageType, bodyMessage);
|
const send = await this.sendData(getConversation, fileName, messageType, bodyMessage, instance, body);
|
||||||
|
|
||||||
if (!send) {
|
if (!send) {
|
||||||
this.logger.warn('message not sent');
|
this.logger.warn('message not sent');
|
||||||
@@ -1394,6 +1579,35 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('check if has ReactionMessage');
|
||||||
|
if (reactionMessage) {
|
||||||
|
this.logger.verbose('send data to chatwoot');
|
||||||
|
if (reactionMessage.text) {
|
||||||
|
const send = await this.createMessage(
|
||||||
|
instance,
|
||||||
|
getConversation,
|
||||||
|
reactionMessage.text,
|
||||||
|
messageType,
|
||||||
|
false,
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
message: { extendedTextMessage: { contextInfo: { stanzaId: reactionMessage.key.id } } },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!send) {
|
||||||
|
this.logger.warn('message not sent');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.messageCacheFile = path.join(ROOT_DIR, 'store', 'chatwoot', `${instance.instanceName}_cache.txt`);
|
||||||
|
this.messageCache = this.loadMessageCache();
|
||||||
|
this.messageCache.add(send.id.toString());
|
||||||
|
this.logger.verbose('save message cache');
|
||||||
|
this.saveMessageCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.verbose('check if has Ads Message');
|
this.logger.verbose('check if has Ads Message');
|
||||||
if (adsMessage) {
|
if (adsMessage) {
|
||||||
this.logger.verbose('message is from Ads');
|
this.logger.verbose('message is from Ads');
|
||||||
@@ -1436,6 +1650,8 @@ export class ChatwootService {
|
|||||||
fileName,
|
fileName,
|
||||||
messageType,
|
messageType,
|
||||||
`${bodyMessage}\n\n\n**${title}**\n${description}\n${adsMessage.sourceUrl}`,
|
`${bodyMessage}\n\n\n**${title}**\n${description}\n${adsMessage.sourceUrl}`,
|
||||||
|
instance,
|
||||||
|
body,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!send) {
|
if (!send) {
|
||||||
@@ -1471,7 +1687,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('send data to chatwoot');
|
this.logger.verbose('send data to chatwoot');
|
||||||
const send = await this.createMessage(instance, getConversation, content, messageType);
|
const send = await this.createMessage(instance, getConversation, content, messageType, false, [], body);
|
||||||
|
|
||||||
if (!send) {
|
if (!send) {
|
||||||
this.logger.warn('message not sent');
|
this.logger.warn('message not sent');
|
||||||
@@ -1492,7 +1708,7 @@ export class ChatwootService {
|
|||||||
this.logger.verbose('message is not group');
|
this.logger.verbose('message is not group');
|
||||||
|
|
||||||
this.logger.verbose('send data to chatwoot');
|
this.logger.verbose('send data to chatwoot');
|
||||||
const send = await this.createMessage(instance, getConversation, bodyMessage, messageType);
|
const send = await this.createMessage(instance, getConversation, bodyMessage, messageType, false, [], body);
|
||||||
|
|
||||||
if (!send) {
|
if (!send) {
|
||||||
this.logger.warn('message not sent');
|
this.logger.warn('message not sent');
|
||||||
@@ -1528,16 +1744,18 @@ export class ChatwootService {
|
|||||||
await this.createBotMessage(instance, msgStatus, 'incoming');
|
await this.createBotMessage(instance, msgStatus, 'incoming');
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (event === 'connection.update') {
|
if (event === 'connection.update') {
|
||||||
// this.logger.verbose('event connection.update');
|
this.logger.verbose('event connection.update');
|
||||||
|
|
||||||
// if (body.status === 'open') {
|
if (body.status === 'open') {
|
||||||
// const msgConnection = `🚀 Connection successfully established!`;
|
// if we have qrcode count then we understand that a new connection was established
|
||||||
|
if (this.waMonitor.waInstances[instance.instanceName].qrCode.count > 0) {
|
||||||
// this.logger.verbose('send message to chatwoot');
|
const msgConnection = `🚀 Connection successfully established!`;
|
||||||
// await this.createBotMessage(instance, msgConnection, 'incoming');
|
this.logger.verbose('send message to chatwoot');
|
||||||
// }
|
await this.createBotMessage(instance, msgConnection, 'incoming');
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (event === 'qrcode.updated') {
|
if (event === 'qrcode.updated') {
|
||||||
this.logger.verbose('event qrcode.updated');
|
this.logger.verbose('event qrcode.updated');
|
||||||
|
|||||||
@@ -7,19 +7,23 @@ import { join } from 'path';
|
|||||||
import { Auth, ConfigService, Database, DelInstance, HttpServer, Redis } from '../../config/env.config';
|
import { Auth, ConfigService, Database, DelInstance, HttpServer, Redis } from '../../config/env.config';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
|
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
|
||||||
// inserido por francis inicio
|
|
||||||
import { NotFoundException } from '../../exceptions';
|
import { NotFoundException } from '../../exceptions';
|
||||||
// inserido por francis fim
|
|
||||||
import { dbserver } from '../../libs/db.connect';
|
import { dbserver } from '../../libs/db.connect';
|
||||||
import { RedisCache } from '../../libs/redis.client';
|
import { RedisCache } from '../../libs/redis.client';
|
||||||
import {
|
import {
|
||||||
AuthModel,
|
AuthModel,
|
||||||
|
ChamaaiModel,
|
||||||
|
// ChatModel,
|
||||||
ChatwootModel,
|
ChatwootModel,
|
||||||
ContactModel,
|
// ContactModel,
|
||||||
MessageModel,
|
// MessageModel,
|
||||||
MessageUpModel,
|
// MessageUpModel,
|
||||||
|
ProxyModel,
|
||||||
|
RabbitmqModel,
|
||||||
SettingsModel,
|
SettingsModel,
|
||||||
|
TypebotModel,
|
||||||
WebhookModel,
|
WebhookModel,
|
||||||
|
WebsocketModel,
|
||||||
} from '../models';
|
} from '../models';
|
||||||
import { RepositoryBroker } from '../repository/repository.manager';
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
import { WAStartupService } from './whatsapp.service';
|
import { WAStartupService } from './whatsapp.service';
|
||||||
@@ -35,7 +39,7 @@ export class WAMonitoringService {
|
|||||||
|
|
||||||
this.removeInstance();
|
this.removeInstance();
|
||||||
this.noConnection();
|
this.noConnection();
|
||||||
this.delInstanceFiles();
|
// this.delInstanceFiles();
|
||||||
|
|
||||||
Object.assign(this.db, configService.get<Database>('DATABASE'));
|
Object.assign(this.db, configService.get<Database>('DATABASE'));
|
||||||
Object.assign(this.redis, configService.get<Redis>('REDIS'));
|
Object.assign(this.redis, configService.get<Redis>('REDIS'));
|
||||||
@@ -66,8 +70,10 @@ export class WAMonitoringService {
|
|||||||
await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance);
|
await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance);
|
||||||
this.waInstances[instance]?.client?.ws?.close();
|
this.waInstances[instance]?.client?.ws?.close();
|
||||||
this.waInstances[instance]?.client?.end(undefined);
|
this.waInstances[instance]?.client?.end(undefined);
|
||||||
|
this.waInstances[instance]?.removeRabbitmqQueues();
|
||||||
delete this.waInstances[instance];
|
delete this.waInstances[instance];
|
||||||
} else {
|
} else {
|
||||||
|
this.waInstances[instance]?.removeRabbitmqQueues();
|
||||||
delete this.waInstances[instance];
|
delete this.waInstances[instance];
|
||||||
this.eventEmitter.emit('remove.instance', instance, 'inner');
|
this.eventEmitter.emit('remove.instance', instance, 'inner');
|
||||||
}
|
}
|
||||||
@@ -75,68 +81,9 @@ export class WAMonitoringService {
|
|||||||
}, 1000 * 60 * time);
|
}, 1000 * 60 * time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* ocultado por francis inicio
|
|
||||||
public async instanceInfo(instanceName?: string) {
|
public async instanceInfo(instanceName?: string) {
|
||||||
this.logger.verbose('get instance info');
|
this.logger.verbose('get instance info');
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
|
||||||
|
|
||||||
const instances: any[] = await Promise.all(
|
|
||||||
Object.entries(this.waInstances).map(async ([key, value]) => {
|
|
||||||
const status = value?.connectionStatus?.state || 'unknown';
|
|
||||||
|
|
||||||
if (status === 'unknown') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status === 'open') {
|
|
||||||
this.logger.verbose('instance: ' + key + ' - connectionStatus: open');
|
|
||||||
}
|
|
||||||
|
|
||||||
const instanceData: any = {
|
|
||||||
instance: {
|
|
||||||
instanceName: key,
|
|
||||||
owner: value.wuid,
|
|
||||||
profileName: (await value.getProfileName()) || 'not loaded',
|
|
||||||
profilePictureUrl: value.profilePictureUrl,
|
|
||||||
profileStatus: (await value.getProfileStatus()) || '',
|
|
||||||
status: status,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
|
||||||
instanceData.instance.serverUrl = urlServer;
|
|
||||||
instanceData.instance.apikey = (await this.repository.auth.find(key))?.apikey;
|
|
||||||
|
|
||||||
const findChatwoot = await this.waInstances[key].findChatwoot();
|
|
||||||
if (findChatwoot && findChatwoot.enabled) {
|
|
||||||
instanceData.instance.chatwoot = {
|
|
||||||
...findChatwoot,
|
|
||||||
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(key)}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return instanceData;
|
|
||||||
}),
|
|
||||||
).then((results) => results.filter((instance) => instance !== null));
|
|
||||||
|
|
||||||
this.logger.verbose('return instance info: ' + instances.length);
|
|
||||||
|
|
||||||
if (instanceName) {
|
|
||||||
const instance = instances.find((i) => i.instance.instanceName === instanceName);
|
|
||||||
return instance || [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return instances;
|
|
||||||
}
|
|
||||||
|
|
||||||
ocultado por francis fim */
|
|
||||||
|
|
||||||
// inserido por francis inicio
|
|
||||||
|
|
||||||
public async instanceInfo(instanceName?: string) {
|
|
||||||
this.logger.verbose('get instance info');
|
|
||||||
if (instanceName && !this.waInstances[instanceName]) {
|
if (instanceName && !this.waInstances[instanceName]) {
|
||||||
throw new NotFoundException(`Instance "${instanceName}" not found`);
|
throw new NotFoundException(`Instance "${instanceName}" not found`);
|
||||||
}
|
}
|
||||||
@@ -176,7 +123,7 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||||
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
|
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey;
|
instanceData.instance['apikey'] = (await this.repository.auth.find(key))?.apikey;
|
||||||
|
|
||||||
instanceData.instance['chatwoot'] = chatwoot;
|
instanceData.instance['chatwoot'] = chatwoot;
|
||||||
}
|
}
|
||||||
@@ -195,7 +142,7 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||||
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
|
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey;
|
instanceData.instance['apikey'] = (await this.repository.auth.find(key))?.apikey;
|
||||||
|
|
||||||
instanceData.instance['chatwoot'] = chatwoot;
|
instanceData.instance['chatwoot'] = chatwoot;
|
||||||
}
|
}
|
||||||
@@ -210,17 +157,6 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
return instances.find((i) => i.instance.instanceName === instanceName) ?? instances;
|
return instances.find((i) => i.instance.instanceName === instanceName) ?? instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// inserido por francis fim
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private delInstanceFiles() {
|
private delInstanceFiles() {
|
||||||
this.logger.verbose('cron to delete instance files started');
|
this.logger.verbose('cron to delete instance files started');
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
@@ -257,6 +193,13 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
|
|
||||||
public async cleaningUp(instanceName: string) {
|
public async cleaningUp(instanceName: string) {
|
||||||
this.logger.verbose('cleaning up instance: ' + instanceName);
|
this.logger.verbose('cleaning up instance: ' + instanceName);
|
||||||
|
if (this.redis.ENABLED) {
|
||||||
|
this.logger.verbose('cleaning up instance in redis: ' + instanceName);
|
||||||
|
this.cache.reference = instanceName;
|
||||||
|
await this.cache.delAll();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.db.ENABLED && this.db.SAVE_DATA.INSTANCE) {
|
if (this.db.ENABLED && this.db.SAVE_DATA.INSTANCE) {
|
||||||
this.logger.verbose('cleaning up instance in database: ' + instanceName);
|
this.logger.verbose('cleaning up instance in database: ' + instanceName);
|
||||||
await this.repository.dbServer.connect();
|
await this.repository.dbServer.connect();
|
||||||
@@ -267,13 +210,6 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.redis.ENABLED) {
|
|
||||||
this.logger.verbose('cleaning up instance in redis: ' + instanceName);
|
|
||||||
this.cache.reference = instanceName;
|
|
||||||
await this.cache.delAll();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.verbose('cleaning up instance in files: ' + instanceName);
|
this.logger.verbose('cleaning up instance in files: ' + instanceName);
|
||||||
rmSync(join(INSTANCE_DIR, instanceName), { recursive: true, force: true });
|
rmSync(join(INSTANCE_DIR, instanceName), { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
@@ -303,13 +239,19 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
|
|
||||||
this.logger.verbose('cleaning store database instance: ' + instanceName);
|
this.logger.verbose('cleaning store database instance: ' + instanceName);
|
||||||
|
|
||||||
await AuthModel.deleteMany({ owner: instanceName });
|
// await ChatModel.deleteMany({ owner: instanceName });
|
||||||
await ContactModel.deleteMany({ owner: instanceName });
|
// await ContactModel.deleteMany({ owner: instanceName });
|
||||||
await MessageModel.deleteMany({ owner: instanceName });
|
// await MessageUpModel.deleteMany({ owner: instanceName });
|
||||||
await MessageUpModel.deleteMany({ owner: instanceName });
|
// await MessageModel.deleteMany({ owner: instanceName });
|
||||||
|
|
||||||
await AuthModel.deleteMany({ _id: instanceName });
|
await AuthModel.deleteMany({ _id: instanceName });
|
||||||
await WebhookModel.deleteMany({ _id: instanceName });
|
await WebhookModel.deleteMany({ _id: instanceName });
|
||||||
await ChatwootModel.deleteMany({ _id: instanceName });
|
await ChatwootModel.deleteMany({ _id: instanceName });
|
||||||
|
await ChamaaiModel.deleteMany({ _id: instanceName });
|
||||||
|
await ProxyModel.deleteMany({ _id: instanceName });
|
||||||
|
await RabbitmqModel.deleteMany({ _id: instanceName });
|
||||||
|
await TypebotModel.deleteMany({ _id: instanceName });
|
||||||
|
await WebsocketModel.deleteMany({ _id: instanceName });
|
||||||
await SettingsModel.deleteMany({ _id: instanceName });
|
await SettingsModel.deleteMany({ _id: instanceName });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -335,7 +277,6 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
const instance = new WAStartupService(this.configService, this.eventEmitter, this.repository, this.cache);
|
const instance = new WAStartupService(this.configService, this.eventEmitter, this.repository, this.cache);
|
||||||
instance.instanceName = name;
|
instance.instanceName = name;
|
||||||
this.logger.verbose('Instance loaded: ' + name);
|
this.logger.verbose('Instance loaded: ' + name);
|
||||||
|
|
||||||
await instance.connectToWhatsapp();
|
await instance.connectToWhatsapp();
|
||||||
this.logger.verbose('connectToWhatsapp: ' + name);
|
this.logger.verbose('connectToWhatsapp: ' + name);
|
||||||
|
|
||||||
@@ -416,8 +357,8 @@ public async instanceInfo(instanceName?: string) {
|
|||||||
this.eventEmitter.on('logout.instance', async (instanceName: string) => {
|
this.eventEmitter.on('logout.instance', async (instanceName: string) => {
|
||||||
this.logger.verbose('logout instance: ' + instanceName);
|
this.logger.verbose('logout instance: ' + instanceName);
|
||||||
try {
|
try {
|
||||||
this.logger.verbose('request cleaning up instance: ' + instanceName);
|
// this.logger.verbose('request cleaning up instance: ' + instanceName);
|
||||||
this.cleaningUp(instanceName);
|
// this.cleaningUp(instanceName);
|
||||||
} finally {
|
} finally {
|
||||||
this.logger.warn(`Instance "${instanceName}" - LOGOUT`);
|
this.logger.warn(`Instance "${instanceName}" - LOGOUT`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ export class ProxyService {
|
|||||||
|
|
||||||
private readonly logger = new Logger(ProxyService.name);
|
private readonly logger = new Logger(ProxyService.name);
|
||||||
|
|
||||||
public create(instance: InstanceDto, data: ProxyDto) {
|
public create(instance: InstanceDto, data: ProxyDto, reload = true) {
|
||||||
this.logger.verbose('create proxy: ' + instance.instanceName);
|
this.logger.verbose('create proxy: ' + instance.instanceName);
|
||||||
this.waMonitor.waInstances[instance.instanceName].setProxy(data);
|
this.waMonitor.waInstances[instance.instanceName].setProxy(data, reload);
|
||||||
|
|
||||||
return { proxy: { ...instance, proxy: data } };
|
return { proxy: { ...instance, proxy: data } };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class SettingsService {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { reject_call: false, msg_call: '', groups_ignore: false };
|
return { reject_call: false, msg_call: '', groups_ignore: true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/whatsapp/services/sqs.service.ts
Normal file
35
src/whatsapp/services/sqs.service.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
import { initQueues } from '../../libs/sqs.server';
|
||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { SqsDto } from '../dto/sqs.dto';
|
||||||
|
import { SqsRaw } from '../models';
|
||||||
|
import { WAMonitoringService } from './monitor.service';
|
||||||
|
|
||||||
|
export class SqsService {
|
||||||
|
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||||
|
|
||||||
|
private readonly logger = new Logger(SqsService.name);
|
||||||
|
|
||||||
|
public create(instance: InstanceDto, data: SqsDto) {
|
||||||
|
this.logger.verbose('create sqs: ' + instance.instanceName);
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].setSqs(data);
|
||||||
|
|
||||||
|
initQueues(instance.instanceName, data.events);
|
||||||
|
return { sqs: { ...instance, sqs: data } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public async find(instance: InstanceDto): Promise<SqsRaw> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('find sqs: ' + instance.instanceName);
|
||||||
|
const result = await this.waMonitor.waInstances[instance.instanceName].findSqs();
|
||||||
|
|
||||||
|
if (Object.keys(result).length === 0) {
|
||||||
|
throw new Error('Sqs not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
return { enabled: false, events: [] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import { ConfigService, Typebot } from '../../config/env.config';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { Session, TypebotDto } from '../dto/typebot.dto';
|
import { Session, TypebotDto } from '../dto/typebot.dto';
|
||||||
@@ -8,7 +9,7 @@ import { Events } from '../types/wa.types';
|
|||||||
import { WAMonitoringService } from './monitor.service';
|
import { WAMonitoringService } from './monitor.service';
|
||||||
|
|
||||||
export class TypebotService {
|
export class TypebotService {
|
||||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {}
|
||||||
|
|
||||||
private readonly logger = new Logger(TypebotService.name);
|
private readonly logger = new Logger(TypebotService.name);
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ export class TypebotService {
|
|||||||
findData.sessions.splice(findData.sessions.indexOf(session), 1);
|
findData.sessions.splice(findData.sessions.indexOf(session), 1);
|
||||||
|
|
||||||
const typebotData = {
|
const typebotData = {
|
||||||
enabled: true,
|
enabled: findData.enabled,
|
||||||
url: findData.url,
|
url: findData.url,
|
||||||
typebot: findData.typebot,
|
typebot: findData.typebot,
|
||||||
expire: findData.expire,
|
expire: findData.expire,
|
||||||
@@ -68,10 +69,24 @@ export class TypebotService {
|
|||||||
session.status = status;
|
session.status = status;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (status === 'paused') {
|
||||||
|
const session: Session = {
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
sessionId: Math.floor(Math.random() * 10000000000).toString(),
|
||||||
|
status: status,
|
||||||
|
createdAt: Date.now(),
|
||||||
|
updateAt: Date.now(),
|
||||||
|
prefilledVariables: {
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
pushName: '',
|
||||||
|
additionalData: {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
findData.sessions.push(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
const typebotData = {
|
const typebotData = {
|
||||||
enabled: true,
|
enabled: findData.enabled,
|
||||||
url: findData.url,
|
url: findData.url,
|
||||||
typebot: findData.typebot,
|
typebot: findData.typebot,
|
||||||
expire: findData.expire,
|
expire: findData.expire,
|
||||||
@@ -96,12 +111,14 @@ export class TypebotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async startTypebot(instance: InstanceDto, data: any) {
|
public async startTypebot(instance: InstanceDto, data: any) {
|
||||||
|
if (data.remoteJid === 'status@broadcast') return;
|
||||||
|
|
||||||
const remoteJid = data.remoteJid;
|
const remoteJid = data.remoteJid;
|
||||||
const url = data.url;
|
const url = data.url;
|
||||||
const typebot = data.typebot;
|
const typebot = data.typebot;
|
||||||
|
const startSession = data.startSession;
|
||||||
const variables = data.variables;
|
const variables = data.variables;
|
||||||
const findTypebot = await this.find(instance);
|
const findTypebot = await this.find(instance);
|
||||||
const sessions = (findTypebot.sessions as Session[]) ?? [];
|
|
||||||
const expire = findTypebot.expire;
|
const expire = findTypebot.expire;
|
||||||
const keyword_finish = findTypebot.keyword_finish;
|
const keyword_finish = findTypebot.keyword_finish;
|
||||||
const delay_message = findTypebot.delay_message;
|
const delay_message = findTypebot.delay_message;
|
||||||
@@ -110,43 +127,84 @@ export class TypebotService {
|
|||||||
|
|
||||||
const prefilledVariables = {
|
const prefilledVariables = {
|
||||||
remoteJid: remoteJid,
|
remoteJid: remoteJid,
|
||||||
|
instanceName: instance.instanceName,
|
||||||
};
|
};
|
||||||
|
|
||||||
variables.forEach((variable) => {
|
if (variables?.length) {
|
||||||
prefilledVariables[variable.name] = variable.value;
|
variables.forEach((variable: { name: string | number; value: string }) => {
|
||||||
});
|
prefilledVariables[variable.name] = variable.value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const response = await this.createNewSession(instance, {
|
if (startSession) {
|
||||||
url: url,
|
const newSessions = await this.clearSessions(instance, remoteJid);
|
||||||
typebot: typebot,
|
|
||||||
remoteJid: remoteJid,
|
|
||||||
expire: expire,
|
|
||||||
keyword_finish: keyword_finish,
|
|
||||||
delay_message: delay_message,
|
|
||||||
unknown_message: unknown_message,
|
|
||||||
listening_from_me: listening_from_me,
|
|
||||||
sessions: sessions,
|
|
||||||
prefilledVariables: prefilledVariables,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.sessionId) {
|
const response = await this.createNewSession(instance, {
|
||||||
await this.sendWAMessage(
|
enabled: findTypebot.enabled,
|
||||||
instance,
|
|
||||||
remoteJid,
|
|
||||||
response.messages,
|
|
||||||
response.input,
|
|
||||||
response.clientSideActions,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
|
|
||||||
remoteJid: remoteJid,
|
|
||||||
url: url,
|
url: url,
|
||||||
typebot: typebot,
|
typebot: typebot,
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
expire: expire,
|
||||||
|
keyword_finish: keyword_finish,
|
||||||
|
delay_message: delay_message,
|
||||||
|
unknown_message: unknown_message,
|
||||||
|
listening_from_me: listening_from_me,
|
||||||
|
sessions: newSessions,
|
||||||
prefilledVariables: prefilledVariables,
|
prefilledVariables: prefilledVariables,
|
||||||
sessionId: `${response.sessionId}`,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (response.sessionId) {
|
||||||
|
await this.sendWAMessage(instance, remoteJid, response.messages, response.input, response.clientSideActions);
|
||||||
|
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
url: url,
|
||||||
|
typebot: typebot,
|
||||||
|
prefilledVariables: prefilledVariables,
|
||||||
|
sessionId: `${response.sessionId}`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error('Session ID not found in response');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Session ID not found in response");
|
const id = Math.floor(Math.random() * 10000000000).toString();
|
||||||
|
|
||||||
|
const reqData = {
|
||||||
|
startParams: {
|
||||||
|
publicId: data.typebot,
|
||||||
|
prefilledVariables: prefilledVariables,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
|
let url: string;
|
||||||
|
if (version === 'latest') {
|
||||||
|
url = `${data.url}/api/v1/typebots/${data.typebot}/startChat`;
|
||||||
|
} else {
|
||||||
|
url = `${data.url}/api/v1/sendMessage`;
|
||||||
|
}
|
||||||
|
const request = await axios.post(url, reqData);
|
||||||
|
|
||||||
|
await this.sendWAMessage(
|
||||||
|
instance,
|
||||||
|
remoteJid,
|
||||||
|
request.data.messages,
|
||||||
|
request.data.input,
|
||||||
|
request.data.clientSideActions,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
url: url,
|
||||||
|
typebot: typebot,
|
||||||
|
variables: variables,
|
||||||
|
sessionId: id,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -199,53 +257,96 @@ export class TypebotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createNewSession(instance: InstanceDto, data: any) {
|
public async createNewSession(instance: InstanceDto, data: any) {
|
||||||
|
if (data.remoteJid === 'status@broadcast') return;
|
||||||
const id = Math.floor(Math.random() * 10000000000).toString();
|
const id = Math.floor(Math.random() * 10000000000).toString();
|
||||||
|
|
||||||
const reqData = {
|
const reqData = {
|
||||||
sessionId: id,
|
|
||||||
startParams: {
|
startParams: {
|
||||||
typebot: data.typebot,
|
publicId: data.typebot,
|
||||||
prefilledVariables: {
|
prefilledVariables: {
|
||||||
...data.prefilledVariables,
|
...data.prefilledVariables,
|
||||||
remoteJid: data.remoteJid,
|
remoteJid: data.remoteJid,
|
||||||
pushName: data.pushName || 'Default Name',
|
pushName: data.pushName || data.prefilledVariables?.pushName || '',
|
||||||
instanceName: instance.instanceName,
|
instanceName: instance.instanceName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const request = await axios.post(data.url + '/api/v1/sendMessage', reqData);
|
try {
|
||||||
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
|
let url: string;
|
||||||
|
if (version === 'latest') {
|
||||||
|
url = `${data.url}/api/v1/typebots/${data.typebot}/startChat`;
|
||||||
|
} else {
|
||||||
|
url = `${data.url}/api/v1/sendMessage`;
|
||||||
|
}
|
||||||
|
const request = await axios.post(url, reqData);
|
||||||
|
|
||||||
if (request.data.sessionId) {
|
if (request?.data?.sessionId) {
|
||||||
data.sessions.push({
|
data.sessions.push({
|
||||||
remoteJid: data.remoteJid,
|
|
||||||
sessionId: `${id}-${request.data.sessionId}`,
|
|
||||||
status: 'opened',
|
|
||||||
createdAt: Date.now(),
|
|
||||||
updateAt: Date.now(),
|
|
||||||
prefilledVariables: {
|
|
||||||
...data.prefilledVariables,
|
|
||||||
remoteJid: data.remoteJid,
|
remoteJid: data.remoteJid,
|
||||||
pushName: data.pushName || 'Default Name',
|
sessionId: `${id}-${request.data.sessionId}`,
|
||||||
instanceName: instance.instanceName,
|
status: 'opened',
|
||||||
}
|
createdAt: Date.now(),
|
||||||
|
updateAt: Date.now(),
|
||||||
|
prefilledVariables: {
|
||||||
|
...data.prefilledVariables,
|
||||||
|
remoteJid: data.remoteJid,
|
||||||
|
pushName: data.pushName || '',
|
||||||
|
instanceName: instance.instanceName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const typebotData = {
|
||||||
|
enabled: data.enabled,
|
||||||
|
url: data.url,
|
||||||
|
typebot: data.typebot,
|
||||||
|
expire: data.expire,
|
||||||
|
keyword_finish: data.keyword_finish,
|
||||||
|
delay_message: data.delay_message,
|
||||||
|
unknown_message: data.unknown_message,
|
||||||
|
listening_from_me: data.listening_from_me,
|
||||||
|
sessions: data.sessions,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.create(instance, typebotData);
|
||||||
|
}
|
||||||
|
return request.data;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async clearSessions(instance: InstanceDto, remoteJid: string) {
|
||||||
|
const findTypebot = await this.find(instance);
|
||||||
|
const sessions = (findTypebot.sessions as Session[]) ?? [];
|
||||||
|
|
||||||
|
const sessionWithRemoteJid = sessions.filter((session) => session.remoteJid === remoteJid);
|
||||||
|
|
||||||
|
if (sessionWithRemoteJid.length > 0) {
|
||||||
|
sessionWithRemoteJid.forEach((session) => {
|
||||||
|
sessions.splice(sessions.indexOf(session), 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
const typebotData = {
|
const typebotData = {
|
||||||
enabled: true,
|
enabled: findTypebot.enabled,
|
||||||
url: data.url,
|
url: findTypebot.url,
|
||||||
typebot: data.typebot,
|
typebot: findTypebot.typebot,
|
||||||
expire: data.expire,
|
expire: findTypebot.expire,
|
||||||
keyword_finish: data.keyword_finish,
|
keyword_finish: findTypebot.keyword_finish,
|
||||||
delay_message: data.delay_message,
|
delay_message: findTypebot.delay_message,
|
||||||
unknown_message: data.unknown_message,
|
unknown_message: findTypebot.unknown_message,
|
||||||
listening_from_me: data.listening_from_me,
|
listening_from_me: findTypebot.listening_from_me,
|
||||||
sessions: data.sessions,
|
sessions,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.create(instance, typebotData);
|
this.create(instance, typebotData);
|
||||||
|
|
||||||
|
return sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
return request.data;
|
return sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendWAMessage(
|
public async sendWAMessage(
|
||||||
@@ -297,7 +398,7 @@ export class TypebotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.underline) {
|
if (element.underline) {
|
||||||
text = `~${text}~`;
|
text = `*${text}*`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.url) {
|
if (element.url) {
|
||||||
@@ -410,17 +511,115 @@ export class TypebotService {
|
|||||||
|
|
||||||
const session = sessions.find((session) => session.remoteJid === remoteJid);
|
const session = sessions.find((session) => session.remoteJid === remoteJid);
|
||||||
|
|
||||||
if (session && expire && expire > 0) {
|
try {
|
||||||
const now = Date.now();
|
if (session && expire && expire > 0) {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
const diff = now - session.updateAt;
|
const diff = now - session.updateAt;
|
||||||
|
|
||||||
const diffInMinutes = Math.floor(diff / 1000 / 60);
|
const diffInMinutes = Math.floor(diff / 1000 / 60);
|
||||||
|
|
||||||
if (diffInMinutes > expire) {
|
if (diffInMinutes > expire) {
|
||||||
sessions.splice(sessions.indexOf(session), 1);
|
const newSessions = await this.clearSessions(instance, remoteJid);
|
||||||
|
|
||||||
|
const data = await this.createNewSession(instance, {
|
||||||
|
enabled: findTypebot.enabled,
|
||||||
|
url: url,
|
||||||
|
typebot: typebot,
|
||||||
|
expire: expire,
|
||||||
|
keyword_finish: keyword_finish,
|
||||||
|
delay_message: delay_message,
|
||||||
|
unknown_message: unknown_message,
|
||||||
|
listening_from_me: listening_from_me,
|
||||||
|
sessions: newSessions,
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
pushName: msg.pushName,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
|
||||||
|
|
||||||
|
if (data.messages.length === 0) {
|
||||||
|
const content = this.getConversationMessage(msg.message);
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
if (unknown_message) {
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].textMessage({
|
||||||
|
number: remoteJid.split('@')[0],
|
||||||
|
options: {
|
||||||
|
delay: delay_message || 1000,
|
||||||
|
presence: 'composing',
|
||||||
|
},
|
||||||
|
textMessage: {
|
||||||
|
text: unknown_message,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
|
||||||
|
const newSessions = await this.clearSessions(instance, remoteJid);
|
||||||
|
|
||||||
|
const typebotData = {
|
||||||
|
enabled: findTypebot.enabled,
|
||||||
|
url: url,
|
||||||
|
typebot: typebot,
|
||||||
|
expire: expire,
|
||||||
|
keyword_finish: keyword_finish,
|
||||||
|
delay_message: delay_message,
|
||||||
|
unknown_message: unknown_message,
|
||||||
|
listening_from_me: listening_from_me,
|
||||||
|
sessions: newSessions,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.create(instance, typebotData);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
|
let urlTypebot: string;
|
||||||
|
let reqData: {};
|
||||||
|
if (version === 'latest') {
|
||||||
|
urlTypebot = `${data.url}/api/v1/sessions/${data.sessionId}/continueChat`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
urlTypebot = `${data.url}/api/v1/sendMessage`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
sessionId: data.sessionId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = await axios.post(urlTypebot, reqData);
|
||||||
|
|
||||||
|
await this.sendWAMessage(
|
||||||
|
instance,
|
||||||
|
remoteJid,
|
||||||
|
request.data.messages,
|
||||||
|
request.data.input,
|
||||||
|
request.data.clientSideActions,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session && session.status !== 'opened') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!session) {
|
||||||
const data = await this.createNewSession(instance, {
|
const data = await this.createNewSession(instance, {
|
||||||
|
enabled: findTypebot.enabled,
|
||||||
url: url,
|
url: url,
|
||||||
typebot: typebot,
|
typebot: typebot,
|
||||||
expire: expire,
|
expire: expire,
|
||||||
@@ -435,76 +634,87 @@ export class TypebotService {
|
|||||||
|
|
||||||
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
|
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
|
||||||
|
|
||||||
|
if (data.messages.length === 0) {
|
||||||
|
const content = this.getConversationMessage(msg.message);
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
if (unknown_message) {
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].textMessage({
|
||||||
|
number: remoteJid.split('@')[0],
|
||||||
|
options: {
|
||||||
|
delay: delay_message || 1000,
|
||||||
|
presence: 'composing',
|
||||||
|
},
|
||||||
|
textMessage: {
|
||||||
|
text: unknown_message,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
|
||||||
|
sessions.splice(sessions.indexOf(session), 1);
|
||||||
|
|
||||||
|
const typebotData = {
|
||||||
|
enabled: findTypebot.enabled,
|
||||||
|
url: url,
|
||||||
|
typebot: typebot,
|
||||||
|
expire: expire,
|
||||||
|
keyword_finish: keyword_finish,
|
||||||
|
delay_message: delay_message,
|
||||||
|
unknown_message: unknown_message,
|
||||||
|
listening_from_me: listening_from_me,
|
||||||
|
sessions,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.create(instance, typebotData);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: any;
|
||||||
|
try {
|
||||||
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
|
let urlTypebot: string;
|
||||||
|
let reqData: {};
|
||||||
|
if (version === 'latest') {
|
||||||
|
urlTypebot = `${data.url}/api/v1/sessions/${data.sessionId}/continueChat`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
urlTypebot = `${data.url}/api/v1/sendMessage`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
sessionId: data.sessionId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
request = await axios.post(urlTypebot, reqData);
|
||||||
|
|
||||||
|
await this.sendWAMessage(
|
||||||
|
instance,
|
||||||
|
remoteJid,
|
||||||
|
request.data.messages,
|
||||||
|
request.data.input,
|
||||||
|
request.data.clientSideActions,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (session && session.status !== 'opened') {
|
sessions.map((session) => {
|
||||||
return;
|
if (session.remoteJid === remoteJid) {
|
||||||
}
|
session.updateAt = Date.now();
|
||||||
|
}
|
||||||
if (!session) {
|
|
||||||
const data = await this.createNewSession(instance, {
|
|
||||||
url: url,
|
|
||||||
typebot: typebot,
|
|
||||||
expire: expire,
|
|
||||||
keyword_finish: keyword_finish,
|
|
||||||
delay_message: delay_message,
|
|
||||||
unknown_message: unknown_message,
|
|
||||||
listening_from_me: listening_from_me,
|
|
||||||
sessions: sessions,
|
|
||||||
remoteJid: remoteJid,
|
|
||||||
pushName: msg.pushName,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sessions.map((session) => {
|
|
||||||
if (session.remoteJid === remoteJid) {
|
|
||||||
session.updateAt = Date.now();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const typebotData = {
|
|
||||||
enabled: true,
|
|
||||||
url: url,
|
|
||||||
typebot: typebot,
|
|
||||||
expire: expire,
|
|
||||||
keyword_finish: keyword_finish,
|
|
||||||
delay_message: delay_message,
|
|
||||||
unknown_message: unknown_message,
|
|
||||||
listening_from_me: listening_from_me,
|
|
||||||
sessions,
|
|
||||||
};
|
|
||||||
|
|
||||||
this.create(instance, typebotData);
|
|
||||||
|
|
||||||
const content = this.getConversationMessage(msg.message);
|
|
||||||
|
|
||||||
if (!content) {
|
|
||||||
if (unknown_message) {
|
|
||||||
this.waMonitor.waInstances[instance.instanceName].textMessage({
|
|
||||||
number: remoteJid.split('@')[0],
|
|
||||||
options: {
|
|
||||||
delay: delay_message || 1000,
|
|
||||||
presence: 'composing',
|
|
||||||
},
|
|
||||||
textMessage: {
|
|
||||||
text: unknown_message,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content.toLowerCase() === keyword_finish.toLowerCase()) {
|
|
||||||
sessions.splice(sessions.indexOf(session), 1);
|
|
||||||
|
|
||||||
const typebotData = {
|
const typebotData = {
|
||||||
enabled: true,
|
enabled: findTypebot.enabled,
|
||||||
url: url,
|
url: url,
|
||||||
typebot: typebot,
|
typebot: typebot,
|
||||||
expire: expire,
|
expire: expire,
|
||||||
@@ -517,24 +727,73 @@ export class TypebotService {
|
|||||||
|
|
||||||
this.create(instance, typebotData);
|
this.create(instance, typebotData);
|
||||||
|
|
||||||
|
const content = this.getConversationMessage(msg.message);
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
if (unknown_message) {
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].textMessage({
|
||||||
|
number: remoteJid.split('@')[0],
|
||||||
|
options: {
|
||||||
|
delay: delay_message || 1000,
|
||||||
|
presence: 'composing',
|
||||||
|
},
|
||||||
|
textMessage: {
|
||||||
|
text: unknown_message,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
|
||||||
|
sessions.splice(sessions.indexOf(session), 1);
|
||||||
|
|
||||||
|
const typebotData = {
|
||||||
|
enabled: findTypebot.enabled,
|
||||||
|
url: url,
|
||||||
|
typebot: typebot,
|
||||||
|
expire: expire,
|
||||||
|
keyword_finish: keyword_finish,
|
||||||
|
delay_message: delay_message,
|
||||||
|
unknown_message: unknown_message,
|
||||||
|
listening_from_me: listening_from_me,
|
||||||
|
sessions,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.create(instance, typebotData);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
|
let urlTypebot: string;
|
||||||
|
let reqData: {};
|
||||||
|
if (version === 'latest') {
|
||||||
|
urlTypebot = `${url}/api/v1/sessions/${session.sessionId.split('-')[1]}/continueChat`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
urlTypebot = `${url}/api/v1/sendMessage`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
sessionId: session.sessionId.split('-')[1],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const request = await axios.post(urlTypebot, reqData);
|
||||||
|
|
||||||
|
await this.sendWAMessage(
|
||||||
|
instance,
|
||||||
|
remoteJid,
|
||||||
|
request.data.messages,
|
||||||
|
request.data.input,
|
||||||
|
request.data.clientSideActions,
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const reqData = {
|
|
||||||
message: content,
|
|
||||||
sessionId: session.sessionId.split('-')[1],
|
|
||||||
};
|
|
||||||
|
|
||||||
const request = await axios.post(url + '/api/v1/sendMessage', reqData);
|
|
||||||
|
|
||||||
await this.sendWAMessage(
|
|
||||||
instance,
|
|
||||||
remoteJid,
|
|
||||||
request.data.messages,
|
|
||||||
request.data.input,
|
|
||||||
request.data.clientSideActions,
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class WebhookService {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { enabled: false, url: '', events: [], webhook_by_events: false };
|
return { enabled: false, url: '', events: [], webhook_by_events: false, webhook_base64: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,7 @@ export declare namespace wa {
|
|||||||
url?: string;
|
url?: string;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
webhook_by_events?: boolean;
|
webhook_by_events?: boolean;
|
||||||
|
webhook_base64?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LocalChatwoot = {
|
export type LocalChatwoot = {
|
||||||
@@ -83,6 +84,11 @@ export declare namespace wa {
|
|||||||
events?: string[];
|
events?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LocalSqs = {
|
||||||
|
enabled?: boolean;
|
||||||
|
events?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
type Session = {
|
type Session = {
|
||||||
remoteJid?: string;
|
remoteJid?: string;
|
||||||
sessionId?: string;
|
sessionId?: string;
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import { ProxyController } from './controllers/proxy.controller';
|
|||||||
import { RabbitmqController } from './controllers/rabbitmq.controller';
|
import { RabbitmqController } from './controllers/rabbitmq.controller';
|
||||||
import { SendMessageController } from './controllers/sendMessage.controller';
|
import { SendMessageController } from './controllers/sendMessage.controller';
|
||||||
import { SettingsController } from './controllers/settings.controller';
|
import { SettingsController } from './controllers/settings.controller';
|
||||||
|
import { SqsController } from './controllers/sqs.controller';
|
||||||
import { TypebotController } from './controllers/typebot.controller';
|
import { TypebotController } from './controllers/typebot.controller';
|
||||||
import { ViewsController } from './controllers/views.controller';
|
|
||||||
import { WebhookController } from './controllers/webhook.controller';
|
import { WebhookController } from './controllers/webhook.controller';
|
||||||
import { WebsocketController } from './controllers/websocket.controller';
|
import { WebsocketController } from './controllers/websocket.controller';
|
||||||
import {
|
import {
|
||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
ProxyModel,
|
ProxyModel,
|
||||||
RabbitmqModel,
|
RabbitmqModel,
|
||||||
SettingsModel,
|
SettingsModel,
|
||||||
|
SqsModel,
|
||||||
TypebotModel,
|
TypebotModel,
|
||||||
WebhookModel,
|
WebhookModel,
|
||||||
WebsocketModel,
|
WebsocketModel,
|
||||||
@@ -42,6 +43,7 @@ import { ProxyRepository } from './repository/proxy.repository';
|
|||||||
import { RabbitmqRepository } from './repository/rabbitmq.repository';
|
import { RabbitmqRepository } from './repository/rabbitmq.repository';
|
||||||
import { RepositoryBroker } from './repository/repository.manager';
|
import { RepositoryBroker } from './repository/repository.manager';
|
||||||
import { SettingsRepository } from './repository/settings.repository';
|
import { SettingsRepository } from './repository/settings.repository';
|
||||||
|
import { SqsRepository } from './repository/sqs.repository';
|
||||||
import { TypebotRepository } from './repository/typebot.repository';
|
import { TypebotRepository } from './repository/typebot.repository';
|
||||||
import { WebhookRepository } from './repository/webhook.repository';
|
import { WebhookRepository } from './repository/webhook.repository';
|
||||||
import { WebsocketRepository } from './repository/websocket.repository';
|
import { WebsocketRepository } from './repository/websocket.repository';
|
||||||
@@ -52,6 +54,7 @@ import { WAMonitoringService } from './services/monitor.service';
|
|||||||
import { ProxyService } from './services/proxy.service';
|
import { ProxyService } from './services/proxy.service';
|
||||||
import { RabbitmqService } from './services/rabbitmq.service';
|
import { RabbitmqService } from './services/rabbitmq.service';
|
||||||
import { SettingsService } from './services/settings.service';
|
import { SettingsService } from './services/settings.service';
|
||||||
|
import { SqsService } from './services/sqs.service';
|
||||||
import { TypebotService } from './services/typebot.service';
|
import { TypebotService } from './services/typebot.service';
|
||||||
import { WebhookService } from './services/webhook.service';
|
import { WebhookService } from './services/webhook.service';
|
||||||
import { WebsocketService } from './services/websocket.service';
|
import { WebsocketService } from './services/websocket.service';
|
||||||
@@ -68,6 +71,7 @@ const websocketRepository = new WebsocketRepository(WebsocketModel, configServic
|
|||||||
const proxyRepository = new ProxyRepository(ProxyModel, configService);
|
const proxyRepository = new ProxyRepository(ProxyModel, configService);
|
||||||
const chamaaiRepository = new ChamaaiRepository(ChamaaiModel, configService);
|
const chamaaiRepository = new ChamaaiRepository(ChamaaiModel, configService);
|
||||||
const rabbitmqRepository = new RabbitmqRepository(RabbitmqModel, configService);
|
const rabbitmqRepository = new RabbitmqRepository(RabbitmqModel, configService);
|
||||||
|
const sqsRepository = new SqsRepository(SqsModel, configService);
|
||||||
const chatwootRepository = new ChatwootRepository(ChatwootModel, configService);
|
const chatwootRepository = new ChatwootRepository(ChatwootModel, configService);
|
||||||
const settingsRepository = new SettingsRepository(SettingsModel, configService);
|
const settingsRepository = new SettingsRepository(SettingsModel, configService);
|
||||||
const authRepository = new AuthRepository(AuthModel, configService);
|
const authRepository = new AuthRepository(AuthModel, configService);
|
||||||
@@ -82,6 +86,7 @@ export const repository = new RepositoryBroker(
|
|||||||
settingsRepository,
|
settingsRepository,
|
||||||
websocketRepository,
|
websocketRepository,
|
||||||
rabbitmqRepository,
|
rabbitmqRepository,
|
||||||
|
sqsRepository,
|
||||||
typebotRepository,
|
typebotRepository,
|
||||||
proxyRepository,
|
proxyRepository,
|
||||||
chamaaiRepository,
|
chamaaiRepository,
|
||||||
@@ -96,7 +101,7 @@ export const waMonitor = new WAMonitoringService(eventEmitter, configService, re
|
|||||||
|
|
||||||
const authService = new AuthService(configService, waMonitor, repository);
|
const authService = new AuthService(configService, waMonitor, repository);
|
||||||
|
|
||||||
const typebotService = new TypebotService(waMonitor);
|
const typebotService = new TypebotService(waMonitor, configService);
|
||||||
|
|
||||||
export const typebotController = new TypebotController(typebotService);
|
export const typebotController = new TypebotController(typebotService);
|
||||||
|
|
||||||
@@ -120,9 +125,13 @@ const rabbitmqService = new RabbitmqService(waMonitor);
|
|||||||
|
|
||||||
export const rabbitmqController = new RabbitmqController(rabbitmqService);
|
export const rabbitmqController = new RabbitmqController(rabbitmqService);
|
||||||
|
|
||||||
const chatwootService = new ChatwootService(waMonitor, configService);
|
const sqsService = new SqsService(waMonitor);
|
||||||
|
|
||||||
export const chatwootController = new ChatwootController(chatwootService, configService);
|
export const sqsController = new SqsController(sqsService);
|
||||||
|
|
||||||
|
const chatwootService = new ChatwootService(waMonitor, configService, repository);
|
||||||
|
|
||||||
|
export const chatwootController = new ChatwootController(chatwootService, configService, repository);
|
||||||
|
|
||||||
const settingsService = new SettingsService(waMonitor);
|
const settingsService = new SettingsService(waMonitor);
|
||||||
|
|
||||||
@@ -139,10 +148,11 @@ export const instanceController = new InstanceController(
|
|||||||
settingsService,
|
settingsService,
|
||||||
websocketService,
|
websocketService,
|
||||||
rabbitmqService,
|
rabbitmqService,
|
||||||
|
proxyService,
|
||||||
|
sqsService,
|
||||||
typebotService,
|
typebotService,
|
||||||
cache,
|
cache,
|
||||||
);
|
);
|
||||||
export const viewsController = new ViewsController(waMonitor, configService);
|
|
||||||
export const sendMessageController = new SendMessageController(waMonitor);
|
export const sendMessageController = new SendMessageController(waMonitor);
|
||||||
export const chatController = new ChatController(waMonitor);
|
export const chatController = new ChatController(waMonitor);
|
||||||
export const groupController = new GroupController(waMonitor);
|
export const groupController = new GroupController(waMonitor);
|
||||||
|
|||||||
110
views/manager-wip.hbs
Normal file
110
views/manager-wip.hbs
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pt-br">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="shortcut icon" href="https://evolution-api.com/files/evolution-api-favicon.png" type="image/x-icon">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
|
||||||
|
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
|
||||||
|
<title>Instance Manager</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container mt-4">
|
||||||
|
<!-- Botão para abrir o modal de adicionar nova instância -->
|
||||||
|
<button class="btn btn-primary mb-3" data-toggle="modal" data-target="#actionModal" data-action="add">Nova
|
||||||
|
Instância</button>
|
||||||
|
|
||||||
|
<!-- Tabela de instâncias -->
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Nome da Instância</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>API Key</th>
|
||||||
|
<th>Ações</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<!-- Iterando sobre as instâncias e preenchendo a tabela -->
|
||||||
|
{{#each instances}}
|
||||||
|
<tr>
|
||||||
|
<td>{{this.instance.instanceName}}</td>
|
||||||
|
<td>{{this.instance.status}}</td>
|
||||||
|
<td>{{this.instance.apikey}}</td>
|
||||||
|
<td>
|
||||||
|
<!-- Dropdown de ações para cada instância -->
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="btn btn-secondary dropdown-toggle" type="button" id="actionDropdown"
|
||||||
|
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
Ações
|
||||||
|
</button>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="actionDropdown">
|
||||||
|
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
|
||||||
|
data-action="connect">Connect</a>
|
||||||
|
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
|
||||||
|
data-action="restart">Restart</a>
|
||||||
|
<!-- Adicione mais itens de ação aqui -->
|
||||||
|
<!-- ... -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/each}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal de ações -->
|
||||||
|
<div class="modal fade" id="actionModal" tabindex="-1" role="dialog" aria-labelledby="actionModalLabel"
|
||||||
|
aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="actionModalLabel">Ação</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
|
||||||
|
<button type="button" class="btn btn-primary">Salvar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
|
||||||
|
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
|
||||||
|
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js"
|
||||||
|
integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('#actionModal').on('show.bs.modal', function(event) {
|
||||||
|
var button = $(event.relatedTarget);
|
||||||
|
var action = button.data('action');
|
||||||
|
|
||||||
|
console.log(action);
|
||||||
|
|
||||||
|
if (action === 'connect') {
|
||||||
|
|
||||||
|
} else if (action === 'restart') {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<iframe src="https://app.smith.dgcode.com.br/app/evolutionapi-public/home-64ca60783615e270291978b4?embed=true" frameborder="0" style="width: 100%; height: 100vh;"></iframe>
|
<iframe src="https://manager.evolution-api.com" frameborder="0" style="width: 100%; height: 100vh;"></iframe>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user