mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 11:52:20 -06:00
Compare commits
258 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb6e58b3c4 | ||
|
|
67e98456bb | ||
|
|
3e47420534 | ||
|
|
1d3d557c43 | ||
|
|
3f41974a75 | ||
|
|
3e3c7397a5 | ||
|
|
dcb51702e7 | ||
|
|
de0c9a1eff | ||
|
|
dd0c1e20a7 | ||
|
|
4769d75dc3 | ||
|
|
6b926dc697 | ||
|
|
ecae077c6d | ||
|
|
78ab1bed35 | ||
|
|
2b6dbfde6b | ||
|
|
6bb1abd7f0 | ||
|
|
aef92240cc | ||
|
|
f0d8c2d095 | ||
|
|
14529f2c35 | ||
|
|
89f40d54d9 | ||
|
|
4c006970a2 | ||
|
|
de676041df | ||
|
|
82b1567ae5 | ||
|
|
1cd7291068 | ||
|
|
fdee1df5b3 | ||
|
|
c314d00ccd | ||
|
|
62e2a8a6e3 | ||
|
|
a12231a0aa | ||
|
|
183efd427a | ||
|
|
f95f3126c3 | ||
|
|
4d9ca4b451 | ||
|
|
c76334a68a | ||
|
|
f475391ba6 | ||
|
|
b77f22790b | ||
|
|
757a578c6e | ||
|
|
c5824767c8 | ||
|
|
84f3f07279 | ||
|
|
f8e1892eee | ||
|
|
036a8edca0 | ||
|
|
58ed6f395f | ||
|
|
ef4be6a612 | ||
|
|
3d8e6f4394 | ||
|
|
0cc1f18a7e | ||
|
|
8b6e577b8f | ||
|
|
cc91f2e5db | ||
|
|
8d1f2313ac | ||
|
|
f9abd90cc9 | ||
|
|
f7293255cf | ||
|
|
7d6a130cf9 | ||
|
|
be7bb2e39f | ||
|
|
1c30728880 | ||
|
|
8d91e7cb1d | ||
|
|
68d980795a | ||
|
|
45c11a5a8e | ||
|
|
4d00351db7 | ||
|
|
fff420b652 | ||
|
|
7103a95305 | ||
|
|
bcada5d553 | ||
|
|
c9b24ff612 | ||
|
|
854c7ed04d | ||
|
|
c0054959cd | ||
|
|
1aa837d220 | ||
|
|
95df402c4c | ||
|
|
2f3d6f7e63 | ||
|
|
ffe1523170 | ||
|
|
a73d5f4b4d | ||
|
|
f35b62ed12 | ||
|
|
20abdd2908 | ||
|
|
28c2c7285c | ||
|
|
3ca8ab12a4 | ||
|
|
fd82aa143c | ||
|
|
1fcbd4f9fd | ||
|
|
73d9cd62a5 | ||
|
|
be699d24a1 | ||
|
|
798eb90bed | ||
|
|
c252f5f8d9 | ||
|
|
76d77ad76f | ||
|
|
69f5cdd61a | ||
|
|
9f52f20660 | ||
|
|
90048afa9d | ||
|
|
1ec3ed32ee | ||
|
|
16ed5821e2 | ||
|
|
b681e33944 | ||
|
|
8f4d44a212 | ||
|
|
93a5d07f9a | ||
|
|
40c230c7db | ||
|
|
d0fa3b92f8 | ||
|
|
2a7727cf5f | ||
|
|
98722e7acf | ||
|
|
683fe4c3db | ||
|
|
e851696430 | ||
|
|
b2ccf965bb | ||
|
|
f847f38812 | ||
|
|
19039aa281 | ||
|
|
091b920a22 | ||
|
|
d7f264c1c2 | ||
|
|
897f8164b9 | ||
|
|
796287a776 | ||
|
|
763e30bd1d | ||
|
|
5121374d60 | ||
|
|
3e3a175bdc | ||
|
|
4a1aa9130b | ||
|
|
5a3f5f60b6 | ||
|
|
8c1600be55 | ||
|
|
7d3ae2347b | ||
|
|
27add47db4 | ||
|
|
836bcab036 | ||
|
|
2d20a07dfb | ||
|
|
24c5c70466 | ||
|
|
22ead22499 | ||
|
|
65e1620b43 | ||
|
|
acac09375e | ||
|
|
83cf859da3 | ||
|
|
956c391f13 | ||
|
|
7767a2607e | ||
|
|
429d1ac183 | ||
|
|
f42928f88f | ||
|
|
2d816ab92d | ||
|
|
aa75380662 | ||
|
|
3cf0ced62e | ||
|
|
41fa700fb3 | ||
|
|
a4ef9fb9b7 | ||
|
|
1db23b5277 | ||
|
|
584f0cbac0 | ||
|
|
dc432a19a3 | ||
|
|
6727b1cfca | ||
|
|
8c7b0698f3 | ||
|
|
69e1622e82 | ||
|
|
af7a5d3248 | ||
|
|
7b1a4554ad | ||
|
|
b3e213c133 | ||
|
|
a9fafec79d | ||
|
|
7cacf7bbaf | ||
|
|
44bf39f7b7 | ||
|
|
0db8f7295b | ||
|
|
c1226062b1 | ||
|
|
819ed168da | ||
|
|
19940953e2 | ||
|
|
f4af3eaf5d | ||
|
|
718563fe6a | ||
|
|
7e996ad6fa | ||
|
|
0b07fb6a49 | ||
|
|
0cb87e6ed9 | ||
|
|
71a3e75ae2 | ||
|
|
a2448ea4c1 | ||
|
|
8a14141021 | ||
|
|
69353892d9 | ||
|
|
7a2fcc3469 | ||
|
|
dfa6dd5011 | ||
|
|
654400c0cf | ||
|
|
3c15fc1b0d | ||
|
|
4b32485e3c | ||
|
|
b90736ed25 | ||
|
|
f28d5c7781 | ||
|
|
0654627478 | ||
|
|
2e91a2ecdb | ||
|
|
66a8ceb27a | ||
|
|
e6b0addb6c | ||
|
|
c00f132145 | ||
|
|
b9eb8d45b2 | ||
|
|
ec7ad70458 | ||
|
|
64e19699fb | ||
|
|
6d3e1b0cbe | ||
|
|
d3a53e1d3c | ||
|
|
23bbb3ee32 | ||
|
|
56bfcd52b7 | ||
|
|
1c19b6de1e | ||
|
|
85bed0bdf1 | ||
|
|
0102796769 | ||
|
|
50b2a72f1b | ||
|
|
04cc239756 | ||
|
|
0c20da2481 | ||
|
|
72d2a563f3 | ||
|
|
6f3f8c944d | ||
|
|
ed60fd2e82 | ||
|
|
636fef4693 | ||
|
|
77775e2f85 | ||
|
|
b260959a6e | ||
|
|
2a04f7b378 | ||
|
|
d4766f9c81 | ||
|
|
7f4c9b5b11 | ||
|
|
70f7c8ce89 | ||
|
|
f33a6aba39 | ||
|
|
236d717f10 | ||
|
|
0fc160f57c | ||
|
|
666023d89a | ||
|
|
8c4f2991c7 | ||
|
|
4453dff36d | ||
|
|
90b043561f | ||
|
|
43a8b34673 | ||
|
|
6005d33c94 | ||
|
|
cffb4736ce | ||
|
|
be54331d05 | ||
|
|
e19b8255d3 | ||
|
|
d680900f07 | ||
|
|
78bd4fd7de | ||
|
|
01d4a95d2d | ||
|
|
bb4490307d | ||
|
|
be492a3e3f | ||
|
|
a7b05f1e85 | ||
|
|
1c5ae4eb4d | ||
|
|
16d03d20ac | ||
|
|
8f062fab7d | ||
|
|
2565b934a5 | ||
|
|
7e88a9084d | ||
|
|
ef03292e35 | ||
|
|
d309ede623 | ||
|
|
834a80c35a | ||
|
|
99b0288d1b | ||
|
|
926f58f336 | ||
|
|
b7bfe99520 | ||
|
|
fa60b68425 | ||
|
|
8622e1e4ff | ||
|
|
3e13ae9740 | ||
|
|
e5cd577fbf | ||
|
|
86985231ff | ||
|
|
e64926a429 | ||
|
|
6232190cfe | ||
|
|
eb83d89307 | ||
|
|
b4a9941452 | ||
|
|
be782ba512 | ||
|
|
db54f247a2 | ||
|
|
0fc3b47c88 | ||
|
|
3eda2a1f2a | ||
|
|
c45b2adad6 | ||
|
|
702dbebfbe | ||
|
|
052303cc93 | ||
|
|
69380146e4 | ||
|
|
514fb56209 | ||
|
|
57b61070d9 | ||
|
|
86ce00365a | ||
|
|
a8bd32bef3 | ||
|
|
ae8801dd8a | ||
|
|
0a4e52e663 | ||
|
|
95045db74e | ||
|
|
19e7c0be0b | ||
|
|
3fcbf458b6 | ||
|
|
4580146cdb | ||
|
|
ea6a7c1c87 | ||
|
|
06cde721b3 | ||
|
|
31486e5963 | ||
|
|
1b52bdf425 | ||
|
|
9b59895ad2 | ||
|
|
c7600ff059 | ||
|
|
b1769edb65 | ||
|
|
14ad09e867 | ||
|
|
26a99d3696 | ||
|
|
c973730acc | ||
|
|
048bea376d | ||
|
|
eca4285ea8 | ||
|
|
437803da07 | ||
|
|
a7be7c3e19 | ||
|
|
5bd7dd3022 | ||
|
|
27aa0add4e | ||
|
|
24712c4c2d | ||
|
|
4bf4b4a045 | ||
|
|
9604f5c317 | ||
|
|
69c1059644 | ||
|
|
26b2903995 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -2,6 +2,8 @@
|
|||||||
/dist
|
/dist
|
||||||
/node_modules
|
/node_modules
|
||||||
|
|
||||||
|
/Docker/.env
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs/**.json
|
logs/**.json
|
||||||
*.log
|
*.log
|
||||||
@@ -12,6 +14,9 @@ yarn-error.log*
|
|||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
|
|
||||||
/docker-compose-data
|
/docker-compose-data
|
||||||
|
/docker-data
|
||||||
|
|
||||||
|
docker-compose.yaml
|
||||||
|
|
||||||
# Package
|
# Package
|
||||||
/yarn.lock
|
/yarn.lock
|
||||||
|
|||||||
195
CHANGELOG.md
195
CHANGELOG.md
@@ -1,3 +1,198 @@
|
|||||||
|
# 1.4.5 (2023-07-26 09:32)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed problems in localization template in chatwoot
|
||||||
|
* Fix mids going duplicated in chatwoot
|
||||||
|
|
||||||
|
# 1.4.4 (2023-07-25 15:24)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed chatwoot line wrap issue
|
||||||
|
* Solved receive location in chatwoot
|
||||||
|
* When requesting the pairing code, it also brings the qr code
|
||||||
|
* Option reopen_conversation in chatwoot endpoint
|
||||||
|
* Option conversation_pending in chatwoot endpoint
|
||||||
|
|
||||||
|
# 1.4.3 (2023-07-25 10:51)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Adjusts in settings with options always_online, read_messages and read_status
|
||||||
|
* Fixed send webhook for event CALL
|
||||||
|
* Create instance with settings
|
||||||
|
|
||||||
|
# 1.4.2 (2023-07-24 20:52)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed validation is set settings
|
||||||
|
* Adjusts in group validations
|
||||||
|
* Ajusts in sticker message to chatwoot
|
||||||
|
|
||||||
|
# 1.4.1 (2023-07-24 18:28)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed reconnect with pairing code or qrcode
|
||||||
|
* Fixed problem in createJid
|
||||||
|
|
||||||
|
# 1.4.0 (2023-07-24 17:03)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Added connection functionality via pairing code
|
||||||
|
* Added fetch profile endpoint in chat controller
|
||||||
|
* Created settings controller
|
||||||
|
* Added reject call and send text message when receiving a call
|
||||||
|
* Added setting to ignore group messages
|
||||||
|
* Added connection with pairing code in chatwoot with command /init:{NUMBER}
|
||||||
|
* Added encoding option in endpoint sendWhatsAppAudio
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Added link preview option in send text message
|
||||||
|
* Fixed problem with fileSha256 appearing when sending a sticker in chatwoot
|
||||||
|
* Fixed issue where it was not possible to open a conversation when sent at first by me on my cell phone in chatwoot
|
||||||
|
* Now it only updates the contact name if it is the same as the phone number in chatwoot
|
||||||
|
* Now accepts all chatwoot inbox templates
|
||||||
|
* Command to create new instances set to /new_instance:{NAME}:{NUMBER}
|
||||||
|
* Fix in chatwoot set, sign msg can now be disabled
|
||||||
|
|
||||||
|
### Integrations
|
||||||
|
|
||||||
|
- Chatwoot: v2.18.0 - v3.0.0 (Beta)
|
||||||
|
|
||||||
|
# 1.3.2 (2023-07-21 17:19)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fix in update settings that needed to restart after updated
|
||||||
|
* Correction in the use of the api with mongodb
|
||||||
|
* Adjustments to search endpoint for contacts, chats, messages and Status messages
|
||||||
|
* Now when deleting the instance, the data referring to it in mongodb is also deleted
|
||||||
|
* It is now validated if the instance name contains uppercase and special characters
|
||||||
|
* For compatibility reasons, container mode has been removed
|
||||||
|
* Added docker-compose files example
|
||||||
|
|
||||||
|
### Integrations
|
||||||
|
|
||||||
|
- Chatwoot: v2.18.0
|
||||||
|
|
||||||
|
# 1.3.1 (2023-07-20 07:48)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Adjust in create store files
|
||||||
|
|
||||||
|
### Integrations
|
||||||
|
|
||||||
|
- Chatwoot: v2.18.0
|
||||||
|
|
||||||
|
# 1.3.0 (2023-07-19 11:33)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Added messages.delete event
|
||||||
|
* Added restart instance endpoint
|
||||||
|
* Created automation for creating instances in the chatwoot bot with the command '#inbox_whatsapp:{INSTANCE_NAME}
|
||||||
|
* Change Baileys version to: 6.4.0
|
||||||
|
* Send contact in chatwoot
|
||||||
|
* Send contact array in chatwoot
|
||||||
|
* Added apiKey in webhook and serverUrl in fetchInstance if EXPOSE_IN_FETCH_INSTANCES: true
|
||||||
|
* Translation set to default (english) in chatwoot
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed error to send message in large groups
|
||||||
|
* Docker files adjusted
|
||||||
|
* Fixed in the postman collection the webhookByEvent parameter by webhook_by_events
|
||||||
|
* Added validations in create instance
|
||||||
|
* Removed link preview endpoint, now it's done automatically from sending conventional text
|
||||||
|
* Added group membership validation before sending message to groups
|
||||||
|
* Adjusts in docker files
|
||||||
|
* Adjusts in returns in endpoints chatwoot and webhook
|
||||||
|
* Fixed ghost mentions in send text message
|
||||||
|
* Fixed bug that saved contacts from groups came without number in chatwoot
|
||||||
|
* Fixed problem to receive csat in chatwoot
|
||||||
|
* Fixed require fileName for document only in base64 for send media message
|
||||||
|
* Bug fix when sending mobile message change contact name to number in chatwoot
|
||||||
|
* Bug fix when connecting whatsapp does not send confirmation message
|
||||||
|
* Fixed quoted message with id or message directly
|
||||||
|
* Adjust in validation for mexican and argentine numbers
|
||||||
|
* Adjust in create store files
|
||||||
|
|
||||||
|
### Integrations
|
||||||
|
|
||||||
|
- Chatwoot: v2.18.0
|
||||||
|
|
||||||
|
# 1.2.2 (2023-07-15 09:36)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Tweak in route "/" with version info
|
||||||
|
* Adjusts chatwoot version
|
||||||
|
|
||||||
|
### Integrations
|
||||||
|
|
||||||
|
- Chatwoot: v2.18.0
|
||||||
|
|
||||||
|
# 1.2.1 (2023-07-14 19:04)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Adjusts in docker files
|
||||||
|
* Save picture url groups in chatwoot
|
||||||
|
|
||||||
|
# 1.2.0 (2023-07-14 15:28)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Native integration with chatwoot
|
||||||
|
* Added returning or non-returning participants option in fetchAllGroups
|
||||||
|
* Added group integration to chatwoot
|
||||||
|
* Added automation on create instance to chatwoot
|
||||||
|
* Added verbose logs and format chatwoot service
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Adjusts in docker-compose files
|
||||||
|
* Adjusts in number validation for AR and MX numbers
|
||||||
|
* Adjusts in env files, removed save old_messages
|
||||||
|
* Fix when sending a message to a group I don't belong returns a bad request
|
||||||
|
* Fits the format on return from the fetchAllGroups endpoint
|
||||||
|
* Adjust in send document with caption from chatwoot
|
||||||
|
* Fixed message with undefind in chatwoot
|
||||||
|
* Changed message in path /
|
||||||
|
* Test duplicate message media in groups chatwoot
|
||||||
|
* Optimize send message from group with mentions
|
||||||
|
* Fixed name of the profile status in fetchInstances
|
||||||
|
* Fixed error 500 when logout in instance with status = close
|
||||||
|
|
||||||
|
# 1.1.5 (2023-07-12 07:17)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Adjusts in temp folder
|
||||||
|
* Return with event send_message
|
||||||
|
|
||||||
|
# 1.1.4 (2023-07-08 11:01)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Route to send status broadcast
|
||||||
|
* Added verbose logs
|
||||||
|
* Insert allContacts in payload of endpoint sendStatus
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Adjusted set in webhook to go empty when enabled false
|
||||||
|
* Adjust in store files
|
||||||
|
* Fixed the problem when do not save contacts when receive messages
|
||||||
|
* Changed owner of the jid for instanceName
|
||||||
|
* Create .env for installation in docker
|
||||||
|
|
||||||
# 1.1.3 (2023-07-06 11:43)
|
# 1.1.3 (2023-07-06 11:43)
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
100
Docker/.env.example
Normal file
100
Docker/.env.example
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
# Server URL - Set your application url
|
||||||
|
SERVER_URL=http://localhost:8080
|
||||||
|
|
||||||
|
# Cors - * for all or set separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
|
||||||
|
CORS_ORIGIN=*
|
||||||
|
CORS_METHODS=POST,GET,PUT,DELETE
|
||||||
|
CORS_CREDENTIALS=true
|
||||||
|
|
||||||
|
# Determine the logs to be displayed
|
||||||
|
LOG_LEVEL=ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS
|
||||||
|
LOG_COLOR=true
|
||||||
|
# Log Baileys - "fatal" | "error" | "warn" | "info" | "debug" | "trace"
|
||||||
|
LOG_BAILEYS=error
|
||||||
|
|
||||||
|
# Determine how long the instance should be deleted from memory in case of no connection.
|
||||||
|
# Default time: 5 minutes
|
||||||
|
# If you don't even want an expiration, enter the value false
|
||||||
|
DEL_INSTANCE=false
|
||||||
|
|
||||||
|
# Temporary data storage
|
||||||
|
STORE_MESSAGES=true
|
||||||
|
STORE_MESSAGE_UP=true
|
||||||
|
STORE_CONTACTS=true
|
||||||
|
STORE_CHATS=true
|
||||||
|
|
||||||
|
# Set Store Interval in Seconds (7200 = 2h)
|
||||||
|
CLEAN_STORE_CLEANING_INTERVAL=7200
|
||||||
|
CLEAN_STORE_MESSAGES=true
|
||||||
|
CLEAN_STORE_MESSAGE_UP=true
|
||||||
|
CLEAN_STORE_CONTACTS=true
|
||||||
|
CLEAN_STORE_CHATS=true
|
||||||
|
|
||||||
|
# Permanent data storage
|
||||||
|
DATABASE_ENABLED=true
|
||||||
|
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
|
||||||
|
DATABASE_CONNECTION_DB_PREFIX_NAME=evdocker
|
||||||
|
|
||||||
|
# Choose the data you want to save in the application's database or store
|
||||||
|
DATABASE_SAVE_DATA_INSTANCE=false
|
||||||
|
DATABASE_SAVE_DATA_NEW_MESSAGE=false
|
||||||
|
DATABASE_SAVE_MESSAGE_UPDATE=false
|
||||||
|
DATABASE_SAVE_DATA_CONTACTS=false
|
||||||
|
DATABASE_SAVE_DATA_CHATS=false
|
||||||
|
|
||||||
|
REDIS_ENABLED=true
|
||||||
|
REDIS_URI=redis://redis:6379
|
||||||
|
REDIS_PREFIX_KEY=evdocker
|
||||||
|
|
||||||
|
# Global Webhook Settings
|
||||||
|
# Each instance's Webhook URL and events will be requested at the time it is created
|
||||||
|
## Define a global webhook that will listen for enabled events from all instances
|
||||||
|
WEBHOOK_GLOBAL_URL=''
|
||||||
|
WEBHOOK_GLOBAL_ENABLED=false
|
||||||
|
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
|
||||||
|
WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
|
||||||
|
## Set the events you want to hear
|
||||||
|
WEBHOOK_EVENTS_APPLICATION_STARTUP=false
|
||||||
|
WEBHOOK_EVENTS_QRCODE_UPDATED=true
|
||||||
|
WEBHOOK_EVENTS_MESSAGES_SET=true
|
||||||
|
WEBHOOK_EVENTS_MESSAGES_UPSERT=true
|
||||||
|
WEBHOOK_EVENTS_MESSAGES_UPDATE=true
|
||||||
|
WEBHOOK_EVENTS_MESSAGES_DELETE=true
|
||||||
|
WEBHOOK_EVENTS_SEND_MESSAGE=true
|
||||||
|
WEBHOOK_EVENTS_CONTACTS_SET=true
|
||||||
|
WEBHOOK_EVENTS_CONTACTS_UPSERT=true
|
||||||
|
WEBHOOK_EVENTS_CONTACTS_UPDATE=true
|
||||||
|
WEBHOOK_EVENTS_PRESENCE_UPDATE=true
|
||||||
|
WEBHOOK_EVENTS_CHATS_SET=true
|
||||||
|
WEBHOOK_EVENTS_CHATS_UPSERT=true
|
||||||
|
WEBHOOK_EVENTS_CHATS_UPDATE=true
|
||||||
|
WEBHOOK_EVENTS_CHATS_DELETE=true
|
||||||
|
WEBHOOK_EVENTS_GROUPS_UPSERT=true
|
||||||
|
WEBHOOK_EVENTS_GROUPS_UPDATE=true
|
||||||
|
WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
||||||
|
WEBHOOK_EVENTS_CONNECTION_UPDATE=true
|
||||||
|
WEBHOOK_EVENTS_CALL=true
|
||||||
|
# This event fires every time a new token is requested via the refresh route
|
||||||
|
WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
|
||||||
|
|
||||||
|
# Name that will be displayed on smartphone connection
|
||||||
|
CONFIG_SESSION_PHONE_CLIENT=EvolutionAPI
|
||||||
|
# Browser Name = chrome | firefox | edge | opera | safari
|
||||||
|
CONFIG_SESSION_PHONE_NAME=chrome
|
||||||
|
|
||||||
|
# Set qrcode display limit
|
||||||
|
QRCODE_LIMIT=30
|
||||||
|
|
||||||
|
# Defines an authentication type for the api
|
||||||
|
# We recommend using the apikey because it will allow you to use a custom token,
|
||||||
|
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
|
||||||
|
# jwt or 'apikey'
|
||||||
|
AUTHENTICATION_TYPE=apikey
|
||||||
|
## Define a global apikey to access all instances.
|
||||||
|
### OBS: This key must be inserted in the request header to create an instance.
|
||||||
|
AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
|
||||||
|
AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
||||||
|
## Set the secret key to encrypt and decrypt your token and its expiration time
|
||||||
|
# seconds - 3600s ===1h | zero (0) - never expires
|
||||||
|
AUTHENTICATION_JWT_EXPIRIN_IN=0
|
||||||
|
AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
|
||||||
@@ -1,27 +1,41 @@
|
|||||||
version: '3.3'
|
version: '3.3'
|
||||||
|
|
||||||
networks:
|
|
||||||
evolution-net:
|
|
||||||
driver: bridge
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
mongodb:
|
mongodb:
|
||||||
container_name: mongodb
|
container_name: mongodb
|
||||||
image: mongo
|
image: mongo
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
|
||||||
- evolution_mongodb_data:/data/db
|
|
||||||
- evolution_mongodb_configdb:/data/configdb
|
|
||||||
ports:
|
ports:
|
||||||
- 27017:27017
|
- 27017:27017
|
||||||
environment:
|
environment:
|
||||||
MONGO_INITDB_ROOT_USERNAME: root
|
- MONGO_INITDB_ROOT_USERNAME=root
|
||||||
MONGO_INITDB_ROOT_PASSWORD: root
|
- MONGO_INITDB_ROOT_PASSWORD=root
|
||||||
networks:
|
- PUID=1000
|
||||||
- evolution-net
|
- PGID=1000
|
||||||
|
volumes:
|
||||||
|
- evolution_mongodb_data:/data/db
|
||||||
|
- evolution_mongodb_configdb:/data/configdb
|
||||||
expose:
|
expose:
|
||||||
- 27017
|
- 27017
|
||||||
|
|
||||||
|
mongo-express:
|
||||||
|
image: mongo-express
|
||||||
|
environment:
|
||||||
|
ME_CONFIG_BASICAUTH_USERNAME: root
|
||||||
|
ME_CONFIG_BASICAUTH_PASSWORD: root
|
||||||
|
ME_CONFIG_MONGODB_SERVER: mongodb
|
||||||
|
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
||||||
|
ME_CONFIG_MONGODB_ADMINPASSWORD: root
|
||||||
|
ports:
|
||||||
|
- 8081:8081
|
||||||
|
links:
|
||||||
|
- mongodb
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
evolution_mongodb_data:
|
evolution_mongodb_data:
|
||||||
evolution_mongodb_configdb:
|
evolution_mongodb_configdb:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
evolution-net:
|
||||||
|
external: true
|
||||||
|
|
||||||
@@ -1,27 +1,21 @@
|
|||||||
version: '3.3'
|
version: '3.3'
|
||||||
|
|
||||||
networks:
|
|
||||||
evolution-net:
|
|
||||||
driver: bridge
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
|
container_name: redis
|
||||||
command: >
|
command: >
|
||||||
redis-server
|
redis-server
|
||||||
--port 6379
|
--port 6379
|
||||||
--appendonly yes
|
--appendonly yes
|
||||||
--save 900 1
|
|
||||||
--save 300 10
|
|
||||||
--save 60 10000
|
|
||||||
--appendfsync everysec
|
|
||||||
volumes:
|
volumes:
|
||||||
- evolution_redis:/data
|
- evolution_redis:/data
|
||||||
container_name: redis
|
|
||||||
ports:
|
ports:
|
||||||
- 6379:6379
|
- 6379:6379
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
evolution_redis:
|
evolution_redis:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
evolution-net:
|
||||||
|
external: true
|
||||||
|
|||||||
124
Dockerfile
124
Dockerfile
@@ -13,81 +13,91 @@ COPY ./package.json .
|
|||||||
|
|
||||||
ENV DOCKER_ENV=true
|
ENV DOCKER_ENV=true
|
||||||
|
|
||||||
ENV SERVER_TYPE="http"
|
ENV SERVER_URL=http://localhost:8080
|
||||||
ENV SERVER_PORT=8080
|
|
||||||
|
|
||||||
ENV CORS_ORIGIN="*"
|
ENV CORS_ORIGIN=*
|
||||||
ENV CORS_METHODS="POST,GET,PUT,DELETE"
|
ENV CORS_METHODS=POST,GET,PUT,DELETE
|
||||||
ENV CORS_CREDENTIALS=true
|
ENV CORS_CREDENTIALS=true
|
||||||
|
|
||||||
ENV LOG_LEVEL=$LOG_LEVEL
|
ENV LOG_LEVEL=ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS
|
||||||
ENV LOG_COLOR=true
|
ENV LOG_COLOR=true
|
||||||
|
ENV LOG_BAILEYS=error
|
||||||
|
|
||||||
ENV DEL_INSTANCE=$DEL_INSTANCE
|
ENV DEL_INSTANCE=false
|
||||||
|
|
||||||
ENV STORE_MESSAGES=$STORE_MESSAGE
|
ENV STORE_MESSAGES=true
|
||||||
ENV STORE_MESSAGE_UP=$STORE_MESSAGE_UP
|
ENV STORE_MESSAGE_UP=true
|
||||||
ENV STORE_CONTACTS=$STORE_CONTACTS
|
ENV STORE_CONTACTS=true
|
||||||
ENV STORE_CHATS=$STORE_CHATS
|
ENV STORE_CHATS=true
|
||||||
|
|
||||||
ENV CLEAN_STORE_CLEANING_INTERVAL=$CLEAN_STORE_CLEANING_INTERVAL
|
ENV CLEAN_STORE_CLEANING_INTERVAL=7200
|
||||||
ENV CLEAN_STORE_MESSAGES=$CLEAN_STORE_MESSAGE
|
ENV CLEAN_STORE_MESSAGES=true
|
||||||
ENV CLEAN_STORE_MESSAGE_UP=$CLEAN_STORE_MESSAGE_UP
|
ENV CLEAN_STORE_MESSAGE_UP=true
|
||||||
ENV CLEAN_STORE_CONTACTS=$CLEAN_STORE_CONTACTS
|
ENV CLEAN_STORE_CONTACTS=true
|
||||||
ENV CLEAN_STORE_CHATS=$CLEAN_STORE_CHATS
|
ENV CLEAN_STORE_CHATS=true
|
||||||
|
|
||||||
ENV DATABASE_ENABLED=$DATABASE_ENABLED
|
ENV DATABASE_ENABLED=false
|
||||||
ENV DATABASE_CONNECTION_URI=$DATABASE_CONNECTION_URI
|
ENV DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
|
||||||
ENV DATABASE_CONNECTION_DB_PREFIX_NAME=$DATABASE_CONNECTION_DB_PREFIX_NAME
|
ENV DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
|
||||||
ENV DATABASE_SAVE_DATA_INSTANCE=$DATABASE_SAVE_DATA_INSTANCE
|
|
||||||
ENV DATABASE_SAVE_DATA_OLD_MESSAGE=$DATABASE_SAVE_DATA_OLD_MESSAGE
|
|
||||||
ENV DATABASE_SAVE_DATA_NEW_MESSAGE=$DATABASE_SAVE_DATA_NEW_MESSAGE
|
|
||||||
ENV DATABASE_SAVE_MESSAGE_UPDATE=$DATABASE_SAVE_MESSAGE_UPDATE
|
|
||||||
ENV DATABASE_SAVE_DATA_CONTACTS=$DATABASE_SAVE_DATA_CONTACTS
|
|
||||||
ENV DATABASE_SAVE_DATA_CHATS=$DATABASE_SAVE_DATA_CHATS
|
|
||||||
|
|
||||||
ENV REDIS_ENABLED=$REDIS_ENABLED
|
ENV DATABASE_SAVE_DATA_INSTANCE=false
|
||||||
ENV REDIS_URI=$REDIS_URI
|
ENV DATABASE_SAVE_DATA_NEW_MESSAGE=false
|
||||||
|
ENV DATABASE_SAVE_MESSAGE_UPDATE=false
|
||||||
|
ENV DATABASE_SAVE_DATA_CONTACTS=false
|
||||||
|
ENV DATABASE_SAVE_DATA_CHATS=false
|
||||||
|
|
||||||
ENV WEBHOOK_GLOBAL_URL=$WEBHOOK_GLOBAL_URL
|
ENV REDIS_ENABLED=false
|
||||||
ENV WEBHOOK_GLOBAL_ENABLED=$WEBHOOK_GLOBAL_ENABLED
|
ENV REDIS_URI=redis://redis:6379
|
||||||
ENV WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=$WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS
|
ENV REDIS_PREFIX_KEY=evolution
|
||||||
|
|
||||||
ENV WEBHOOK_EVENTS_APPLICATION_STARTUP=$WEBHOOK_EVENTS_APPLICATION_STARTUP
|
ENV WEBHOOK_GLOBAL_URL=<url>
|
||||||
ENV WEBHOOK_EVENTS_QRCODE_UPDATED=$WEBHOOK_EVENTS_QRCODE_UPDATED
|
ENV WEBHOOK_GLOBAL_ENABLED=false
|
||||||
ENV WEBHOOK_EVENTS_MESSAGES_SET=$WEBHOOK_EVENTS_MESSAGES_SET
|
|
||||||
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
|
|
||||||
ENV WEBHOOK_EVENTS_MESSAGES_UPSERT=$WEBHOOK_EVENTS_MESSAGES_UPSERT
|
|
||||||
ENV WEBHOOK_EVENTS_CONTACTS_SET=$WEBHOOK_EVENTS_CONTACTS_SET
|
|
||||||
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=$WEBHOOK_EVENTS_CONTACTS_UPSERT
|
|
||||||
ENV WEBHOOK_EVENTS_CONTACTS_UPDATE=$WEBHOOK_EVENTS_CONTACTS_UPDATE
|
|
||||||
ENV WEBHOOK_EVENTS_PRESENCE_UPDATE=$WEBHOOK_EVENTS_PRESENCE_UPDATE
|
|
||||||
ENV WEBHOOK_EVENTS_CHATS_SET=$WEBHOOK_EVENTS_CHATS_SET
|
|
||||||
ENV WEBHOOK_EVENTS_CHATS_UPSERT=$WEBHOOK_EVENTS_CHATS_UPSERT
|
|
||||||
ENV WEBHOOK_EVENTS_CHATS_UPDATE=$WEBHOOK_EVENTS_CHATS_UPDATE
|
|
||||||
ENV WEBHOOK_EVENTS_CONNECTION_UPDATE=$WEBHOOK_EVENTS_CONNECTION_UPDATE
|
|
||||||
ENV WEBHOOK_EVENTS_GROUPS_UPSERT=$WEBHOOK_EVENTS_GROUPS_UPSERT
|
|
||||||
ENV WEBHOOK_EVENTS_GROUPS_UPDATE=$WEBHOOK_EVENTS_GROUPS_UPDATE
|
|
||||||
ENV WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=$WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE
|
|
||||||
|
|
||||||
ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=$WEBHOOK_EVENTS_NEW_JWT_TOKEN
|
ENV WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
|
||||||
|
|
||||||
ENV CONFIG_SESSION_PHONE_CLIENT=$CONFIG_SESSION_PHONE_CLIENT
|
ENV WEBHOOK_EVENTS_APPLICATION_STARTUP=false
|
||||||
ENV CONFIG_SESSION_PHONE_NAME=$CONFIG_SESSION_PHONE_NAME
|
ENV WEBHOOK_EVENTS_QRCODE_UPDATED=true
|
||||||
|
ENV WEBHOOK_EVENTS_MESSAGES_SET=true
|
||||||
|
ENV WEBHOOK_EVENTS_MESSAGES_UPSERT=true
|
||||||
|
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=true
|
||||||
|
ENV WEBHOOK_EVENTS_MESSAGES_DELETE=true
|
||||||
|
ENV WEBHOOK_EVENTS_SEND_MESSAGE=true
|
||||||
|
ENV WEBHOOK_EVENTS_CONTACTS_SET=true
|
||||||
|
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=true
|
||||||
|
ENV WEBHOOK_EVENTS_CONTACTS_UPDATE=true
|
||||||
|
ENV WEBHOOK_EVENTS_PRESENCE_UPDATE=true
|
||||||
|
ENV WEBHOOK_EVENTS_CHATS_SET=true
|
||||||
|
ENV WEBHOOK_EVENTS_CHATS_UPSERT=true
|
||||||
|
ENV WEBHOOK_EVENTS_CHATS_UPDATE=true
|
||||||
|
ENV WEBHOOK_EVENTS_CHATS_DELETE=true
|
||||||
|
ENV WEBHOOK_EVENTS_GROUPS_UPSERT=true
|
||||||
|
ENV WEBHOOK_EVENTS_GROUPS_UPDATE=true
|
||||||
|
ENV WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
||||||
|
ENV WEBHOOK_EVENTS_CONNECTION_UPDATE=true
|
||||||
|
ENV WEBHOOK_EVENTS_CALL=true
|
||||||
|
|
||||||
ENV QRCODE_LIMIT=$QRCODE_LIMIT
|
ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
|
||||||
|
|
||||||
ENV AUTHENTICATION_TYPE=$AUTHENTICATION_TYPE
|
ENV CONFIG_SESSION_PHONE_CLIENT=EvolutionAPI
|
||||||
|
ENV CONFIG_SESSION_PHONE_NAME=chrome
|
||||||
|
|
||||||
ENV AUTHENTICATION_API_KEY=$AUTHENTICATION_API_KEY
|
ENV QRCODE_LIMIT=30
|
||||||
ENV AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=$AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES
|
|
||||||
|
|
||||||
ENV AUTHENTICATION_JWT_EXPIRIN_IN=$AUTHENTICATION_JWT_EXPIRIN_IN
|
ENV AUTHENTICATION_TYPE=apikey
|
||||||
ENV AUTHENTICATION_JWT_SECRET="L=0YWt]b2w[WF>#>:&E`"
|
|
||||||
|
|
||||||
ENV AUTHENTICATION_INSTANCE_NAME=$AUTHENTICATION_INSTANCE_NAME
|
ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
|
||||||
ENV AUTHENTICATION_INSTANCE_WEBHOOK_URL=$AUTHENTICATION_INSTANCE_WEBHOOK_URL
|
ENV AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
||||||
ENV AUTHENTICATION_INSTANCE_MODE=$AUTHENTICATION_INSTANCE_MODE
|
|
||||||
|
ENV AUTHENTICATION_JWT_EXPIRIN_IN=0
|
||||||
|
ENV AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
|
||||||
|
|
||||||
|
ENV AUTHENTICATION_INSTANCE_MODE=server
|
||||||
|
|
||||||
|
ENV AUTHENTICATION_INSTANCE_NAME=evolution
|
||||||
|
ENV AUTHENTICATION_INSTANCE_WEBHOOK_URL=<url>
|
||||||
|
ENV AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
|
||||||
|
ENV AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
|
||||||
|
ENV AUTHENTICATION_INSTANCE_CHATWOOT_URL=<url>
|
||||||
|
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
[](https://evolution-api.com/whatsapp)
|
[](https://evolution-api.com/whatsapp)
|
||||||
[](https://evolution-api.com/docs/evolution-documentation/getting-started/postman-collection/)
|
[](https://evolution-api.com/discord)
|
||||||
[](https://evolution-api.com)
|
[](https://evolution-api.com/postman)
|
||||||
|
[](https://doc.evolution-api.com)
|
||||||
[](./LICENSE)
|
[](./LICENSE)
|
||||||
[](https://app.picpay.com/user/davidsongomes1998)
|
[](https://app.picpay.com/user/davidsongomes1998)
|
||||||
|
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
version: '3.3'
|
|
||||||
|
|
||||||
networks:
|
|
||||||
evolution-net:
|
|
||||||
driver: bridge
|
|
||||||
|
|
||||||
services:
|
|
||||||
api:
|
|
||||||
container_name: evolution_api
|
|
||||||
image: evolution/api:local
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
volumes:
|
|
||||||
- evolution_instances:/evolution/instances
|
|
||||||
- evolution_store:/evolution/store
|
|
||||||
environment:
|
|
||||||
- LOG_LEVEL=ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS
|
|
||||||
- LOG_BAILEYS=error
|
|
||||||
# Determine how long the instance should be deleted from memory in case of no connection.
|
|
||||||
# Default time: 5 minutes
|
|
||||||
# If you don't even want an expiration, enter the value false
|
|
||||||
- DEL_INSTANCE=false # 5 or false
|
|
||||||
# Temporary data storage
|
|
||||||
- STORE_MESSAGES=true
|
|
||||||
- STORE_MESSAGE_UP=true
|
|
||||||
- STORE_CONTACTS=true
|
|
||||||
- STORE_CHATS=true
|
|
||||||
- CLEAN_STORE_CLEANING_INTERVAL=7200 # seconds === 2h
|
|
||||||
- CLEAN_STORE_MESSAGES=true
|
|
||||||
- CLEAN_STORE_MESSAGE_UP=true
|
|
||||||
- CLEAN_STORE_CONTACTS=true
|
|
||||||
- CLEAN_STORE_CHATS=true
|
|
||||||
# Permanent data storage
|
|
||||||
- DATABASE_ENABLED=false
|
|
||||||
- DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
|
|
||||||
- DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
|
|
||||||
# Choose the data you want to save in the application's database or store
|
|
||||||
- DATABASE_SAVE_DATA_INSTANCE=true
|
|
||||||
- DATABASE_SAVE_DATA_OLD_MESSAGE=false
|
|
||||||
- DATABASE_SAVE_DATA_NEW_MESSAGE=true
|
|
||||||
- DATABASE_SAVE_MESSAGE_UPDATE=true
|
|
||||||
- DATABASE_SAVE_DATA_CONTACTS=true
|
|
||||||
- DATABASE_SAVE_DATA_CHATS=true
|
|
||||||
- REDIS_ENABLED=true
|
|
||||||
- REDIS_URI=redis://redis:6379/1
|
|
||||||
- REDIS_PREFIX_KEY=evolution
|
|
||||||
# Webhook Settings
|
|
||||||
# Define a global webhook that will listen for enabled events from all instances
|
|
||||||
- WEBHOOK_GLOBAL_URL=<url>
|
|
||||||
- WEBHOOK_GLOBAL_ENABLED=false
|
|
||||||
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
|
|
||||||
- WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
|
|
||||||
# Automatically maps webhook paths
|
|
||||||
# Set the events you want to hear
|
|
||||||
- WEBHOOK_EVENTS_APPLICATION_STARTUP=false
|
|
||||||
- WEBHOOK_EVENTS_QRCODE_UPDATED=true
|
|
||||||
- WEBHOOK_EVENTS_MESSAGES_SET=true
|
|
||||||
- WEBHOOK_EVENTS_MESSAGES_UPSERT=true
|
|
||||||
- WEBHOOK_EVENTS_MESSAGES_UPDATE=true
|
|
||||||
- WEBHOOK_EVENTS_CONTACTS_SET=true
|
|
||||||
- WEBHOOK_EVENTS_CONTACTS_UPSERT=true
|
|
||||||
- WEBHOOK_EVENTS_CONTACTS_UPDATE=true
|
|
||||||
- WEBHOOK_EVENTS_PRESENCE_UPDATE=true
|
|
||||||
- WEBHOOK_EVENTS_CHATS_SET=true
|
|
||||||
- WEBHOOK_EVENTS_CHATS_UPSERT=true
|
|
||||||
- WEBHOOK_EVENTS_CHATS_UPDATE=true
|
|
||||||
- WEBHOOK_EVENTS_CHATS_DELETE=true
|
|
||||||
- WEBHOOK_EVENTS_GROUPS_UPSERT=true
|
|
||||||
- WEBHOOK_EVENTS_GROUPS_UPDATE=true
|
|
||||||
- WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
|
||||||
- WEBHOOK_EVENTS_CONNECTION_UPDATE=true
|
|
||||||
# This event fires every time a new token is requested via the refresh route
|
|
||||||
- WEBHOOK_EVENTS_NEW_JWT_TOKEN=true
|
|
||||||
# Name that will be displayed on smartphone connection
|
|
||||||
- CONFIG_SESSION_PHONE_CLIENT=Evolution API
|
|
||||||
- CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari
|
|
||||||
# Set qrcode display limit
|
|
||||||
- QRCODE_LIMIT=30
|
|
||||||
# Defines an authentication type for the api
|
|
||||||
- AUTHENTICATION_TYPE=apikey # jwt or apikey
|
|
||||||
# Define a global apikey to access all instances
|
|
||||||
# OBS: This key must be inserted in the request header to create an instance.
|
|
||||||
- AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
|
|
||||||
# Expose the api key on return from fetch instances
|
|
||||||
- AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
|
||||||
# Set the secret key to encrypt and decrypt your token and its expiration time.
|
|
||||||
- AUTHENTICATION_JWT_EXPIRIN_IN=0 # seconds - 3600s === 1h | zero (0) - never expires
|
|
||||||
# Set the instance name and webhook url to create an instance in init the application
|
|
||||||
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
|
|
||||||
- AUTHENTICATION_INSTANCE_MODE=server # container or server
|
|
||||||
# if you are using container mode, set the container name and the webhook url to default instance
|
|
||||||
- AUTHENTICATION_INSTANCE_NAME=evolution
|
|
||||||
- AUTHENTICATION_INSTANCE_WEBHOOK_URL=<url>
|
|
||||||
command: ['node', './dist/src/main.js']
|
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
expose:
|
|
||||||
- 8080
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
evolution_instances:
|
|
||||||
evolution_store:
|
|
||||||
28
docker-compose.yaml.example
Normal file
28
docker-compose.yaml.example
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
version: '3.3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
api:
|
||||||
|
container_name: evolution_api
|
||||||
|
image: evolution/api:local
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
volumes:
|
||||||
|
- evolution_instances:/evolution/instances
|
||||||
|
- evolution_store:/evolution/store
|
||||||
|
networks:
|
||||||
|
- evolution-net
|
||||||
|
env_file:
|
||||||
|
- ./Docker/.env
|
||||||
|
command: ['node', './dist/src/main.js']
|
||||||
|
expose:
|
||||||
|
- 8080
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
evolution_instances:
|
||||||
|
evolution_store:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
evolution-net:
|
||||||
|
external: true
|
||||||
|
|
||||||
79
docker-compose.yaml.example.complete
Normal file
79
docker-compose.yaml.example.complete
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
version: '3.3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
api:
|
||||||
|
container_name: evolution_api
|
||||||
|
image: evolution/api:local
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
volumes:
|
||||||
|
- evolution_instances:/evolution/instances
|
||||||
|
- evolution_store:/evolution/store
|
||||||
|
networks:
|
||||||
|
- evolution-net
|
||||||
|
env_file:
|
||||||
|
- ./Docker/.env
|
||||||
|
command: ['node', './dist/src/main.js']
|
||||||
|
expose:
|
||||||
|
- 8080
|
||||||
|
|
||||||
|
mongodb:
|
||||||
|
container_name: mongodb
|
||||||
|
image: mongo
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 27017:27017
|
||||||
|
environment:
|
||||||
|
- MONGO_INITDB_ROOT_USERNAME=root
|
||||||
|
- MONGO_INITDB_ROOT_PASSWORD=root
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
volumes:
|
||||||
|
- evolution_mongodb_data:/data/db
|
||||||
|
- evolution_mongodb_configdb:/data/configdb
|
||||||
|
networks:
|
||||||
|
- evolution-net
|
||||||
|
expose:
|
||||||
|
- 27017
|
||||||
|
|
||||||
|
mongo-express:
|
||||||
|
image: mongo-express
|
||||||
|
networks:
|
||||||
|
- evolution-net
|
||||||
|
environment:
|
||||||
|
ME_CONFIG_BASICAUTH_USERNAME: root
|
||||||
|
ME_CONFIG_BASICAUTH_PASSWORD: root
|
||||||
|
ME_CONFIG_MONGODB_SERVER: mongodb
|
||||||
|
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
||||||
|
ME_CONFIG_MONGODB_ADMINPASSWORD: root
|
||||||
|
ports:
|
||||||
|
- 8081:8081
|
||||||
|
links:
|
||||||
|
- mongodb
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:latest
|
||||||
|
container_name: redis
|
||||||
|
command: >
|
||||||
|
redis-server
|
||||||
|
--port 6379
|
||||||
|
--appendonly yes
|
||||||
|
volumes:
|
||||||
|
- evolution_redis:/data
|
||||||
|
networks:
|
||||||
|
- evolution-net
|
||||||
|
ports:
|
||||||
|
- 6379:6379
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
evolution_instances:
|
||||||
|
evolution_store:
|
||||||
|
evolution_mongodb_data:
|
||||||
|
evolution_mongodb_configdb:
|
||||||
|
evolution_redis:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
evolution-net:
|
||||||
|
external: true
|
||||||
|
|
||||||
@@ -8,13 +8,6 @@ then
|
|||||||
docker network create -d bridge ${NET}
|
docker network create -d bridge ${NET}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# sudo mkdir -p ./docker-data/instances
|
|
||||||
# sudo mkdir -p ./docker-data/mongodb
|
|
||||||
# sudo mkdir -p ./docker-data/mongodb/data
|
|
||||||
# sudo mkdir -p ./docker-data/mongodb/configdb
|
|
||||||
# sudo mkdir -p ./docker-data/redis
|
|
||||||
# sudo mkdir -p ./docker-data/redis/data
|
|
||||||
|
|
||||||
docker build -t ${IMAGE} .
|
docker build -t ${IMAGE} .
|
||||||
|
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.1.3",
|
"version": "1.4.5",
|
||||||
"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": {
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/DavidsonGomes/evolution-api.git"
|
"url": "git+https://github.com/EvolutionAPI/evolution-api.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"chat",
|
"chat",
|
||||||
@@ -36,14 +36,16 @@
|
|||||||
},
|
},
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/DavidsonGomes/evolution-api/issues"
|
"url": "https://github.com/EvolutionAPI/evolution-api/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/DavidsonGomes/evolution-api#readme",
|
"homepage": "https://github.com/EvolutionAPI/evolution-api#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@adiwajshing/keyed-db": "^0.2.4",
|
"@adiwajshing/keyed-db": "^0.2.4",
|
||||||
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
||||||
|
"@figuro/chatwoot-sdk": "^1.1.14",
|
||||||
"@hapi/boom": "^10.0.1",
|
"@hapi/boom": "^10.0.1",
|
||||||
"@whiskeysockets/baileys": "^6.3.0",
|
"@sentry/node": "^7.59.2",
|
||||||
|
"@whiskeysockets/baileys": "^6.4.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",
|
||||||
@@ -65,6 +67,7 @@
|
|||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"node-mime-types": "^1.1.0",
|
"node-mime-types": "^1.1.0",
|
||||||
"pino": "^8.11.0",
|
"pino": "^8.11.0",
|
||||||
|
"proxy-agent": "^6.2.1",
|
||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"redis": "^4.6.5",
|
"redis": "^4.6.5",
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { load } from 'js-yaml';
|
import { load } from 'js-yaml';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { SRC_DIR } from './path.config';
|
|
||||||
import { isBooleanString } from 'class-validator';
|
import { isBooleanString } from 'class-validator';
|
||||||
|
|
||||||
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number };
|
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
|
||||||
|
|
||||||
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
|
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
|
||||||
export type Cors = {
|
export type Cors = {
|
||||||
@@ -33,7 +32,6 @@ export type Log = {
|
|||||||
|
|
||||||
export type SaveData = {
|
export type SaveData = {
|
||||||
INSTANCE: boolean;
|
INSTANCE: boolean;
|
||||||
OLD_MESSAGE: boolean;
|
|
||||||
NEW_MESSAGE: boolean;
|
NEW_MESSAGE: boolean;
|
||||||
MESSAGE_UPDATE: boolean;
|
MESSAGE_UPDATE: boolean;
|
||||||
CONTACTS: boolean;
|
CONTACTS: boolean;
|
||||||
@@ -77,6 +75,8 @@ export type EventsWebhook = {
|
|||||||
MESSAGES_SET: boolean;
|
MESSAGES_SET: boolean;
|
||||||
MESSAGES_UPSERT: boolean;
|
MESSAGES_UPSERT: boolean;
|
||||||
MESSAGES_UPDATE: boolean;
|
MESSAGES_UPDATE: boolean;
|
||||||
|
MESSAGES_DELETE: boolean;
|
||||||
|
SEND_MESSAGE: boolean;
|
||||||
CONTACTS_SET: boolean;
|
CONTACTS_SET: boolean;
|
||||||
CONTACTS_UPDATE: boolean;
|
CONTACTS_UPDATE: boolean;
|
||||||
CONTACTS_UPSERT: boolean;
|
CONTACTS_UPSERT: boolean;
|
||||||
@@ -89,22 +89,18 @@ export type EventsWebhook = {
|
|||||||
GROUPS_UPSERT: boolean;
|
GROUPS_UPSERT: boolean;
|
||||||
GROUP_UPDATE: boolean;
|
GROUP_UPDATE: boolean;
|
||||||
GROUP_PARTICIPANTS_UPDATE: boolean;
|
GROUP_PARTICIPANTS_UPDATE: boolean;
|
||||||
|
CALL: boolean;
|
||||||
NEW_JWT_TOKEN: boolean;
|
NEW_JWT_TOKEN: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ApiKey = { KEY: string };
|
export type ApiKey = { KEY: string };
|
||||||
export type Jwt = { EXPIRIN_IN: number; SECRET: string };
|
export type Jwt = { EXPIRIN_IN: number; SECRET: string };
|
||||||
export type Instance = {
|
|
||||||
NAME: string;
|
|
||||||
WEBHOOK_URL: string;
|
|
||||||
MODE: string;
|
|
||||||
};
|
|
||||||
export type Auth = {
|
export type Auth = {
|
||||||
API_KEY: ApiKey;
|
API_KEY: ApiKey;
|
||||||
EXPOSE_IN_FETCH_INSTANCES: boolean;
|
EXPOSE_IN_FETCH_INSTANCES: boolean;
|
||||||
JWT: Jwt;
|
JWT: Jwt;
|
||||||
TYPE: 'jwt' | 'apikey';
|
TYPE: 'jwt' | 'apikey';
|
||||||
INSTANCE: Instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DelInstance = number | boolean;
|
export type DelInstance = number | boolean;
|
||||||
@@ -170,6 +166,7 @@ export class ConfigService {
|
|||||||
SERVER: {
|
SERVER: {
|
||||||
TYPE: process.env.SERVER_TYPE as 'http' | 'https',
|
TYPE: process.env.SERVER_TYPE as 'http' | 'https',
|
||||||
PORT: Number.parseInt(process.env.SERVER_PORT),
|
PORT: Number.parseInt(process.env.SERVER_PORT),
|
||||||
|
URL: process.env.SERVER_URL,
|
||||||
},
|
},
|
||||||
CORS: {
|
CORS: {
|
||||||
ORIGIN: process.env.CORS_ORIGIN.split(','),
|
ORIGIN: process.env.CORS_ORIGIN.split(','),
|
||||||
@@ -189,7 +186,7 @@ export class ConfigService {
|
|||||||
CLEAN_STORE: {
|
CLEAN_STORE: {
|
||||||
CLEANING_INTERVAL: Number.isInteger(process.env?.CLEAN_STORE_CLEANING_TERMINAL)
|
CLEANING_INTERVAL: Number.isInteger(process.env?.CLEAN_STORE_CLEANING_TERMINAL)
|
||||||
? Number.parseInt(process.env.CLEAN_STORE_CLEANING_TERMINAL)
|
? Number.parseInt(process.env.CLEAN_STORE_CLEANING_TERMINAL)
|
||||||
: undefined,
|
: 7200,
|
||||||
MESSAGES: process.env?.CLEAN_STORE_MESSAGES === 'true',
|
MESSAGES: process.env?.CLEAN_STORE_MESSAGES === 'true',
|
||||||
MESSAGE_UP: process.env?.CLEAN_STORE_MESSAGE_UP === 'true',
|
MESSAGE_UP: process.env?.CLEAN_STORE_MESSAGE_UP === 'true',
|
||||||
CONTACTS: process.env?.CLEAN_STORE_CONTACTS === 'true',
|
CONTACTS: process.env?.CLEAN_STORE_CONTACTS === 'true',
|
||||||
@@ -203,7 +200,6 @@ export class ConfigService {
|
|||||||
ENABLED: process.env?.DATABASE_ENABLED === 'true',
|
ENABLED: process.env?.DATABASE_ENABLED === 'true',
|
||||||
SAVE_DATA: {
|
SAVE_DATA: {
|
||||||
INSTANCE: process.env?.DATABASE_SAVE_DATA_INSTANCE === 'true',
|
INSTANCE: process.env?.DATABASE_SAVE_DATA_INSTANCE === 'true',
|
||||||
OLD_MESSAGE: process.env?.DATABASE_SAVE_DATA_OLD_MESSAGE === 'true',
|
|
||||||
NEW_MESSAGE: process.env?.DATABASE_SAVE_DATA_NEW_MESSAGE === 'true',
|
NEW_MESSAGE: process.env?.DATABASE_SAVE_DATA_NEW_MESSAGE === 'true',
|
||||||
MESSAGE_UPDATE: process.env?.DATABASE_SAVE_MESSAGE_UPDATE === 'true',
|
MESSAGE_UPDATE: process.env?.DATABASE_SAVE_MESSAGE_UPDATE === 'true',
|
||||||
CONTACTS: process.env?.DATABASE_SAVE_DATA_CONTACTS === 'true',
|
CONTACTS: process.env?.DATABASE_SAVE_DATA_CONTACTS === 'true',
|
||||||
@@ -222,7 +218,7 @@ export class ConfigService {
|
|||||||
},
|
},
|
||||||
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
|
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
|
||||||
? process.env.DEL_INSTANCE === 'true'
|
? process.env.DEL_INSTANCE === 'true'
|
||||||
: Number.parseInt(process.env.DEL_INSTANCE),
|
: Number.parseInt(process.env.DEL_INSTANCE) || false,
|
||||||
WEBHOOK: {
|
WEBHOOK: {
|
||||||
GLOBAL: {
|
GLOBAL: {
|
||||||
URL: process.env?.WEBHOOK_GLOBAL_URL,
|
URL: process.env?.WEBHOOK_GLOBAL_URL,
|
||||||
@@ -235,6 +231,8 @@ export class ConfigService {
|
|||||||
MESSAGES_SET: process.env?.WEBHOOK_EVENTS_MESSAGES_SET === 'true',
|
MESSAGES_SET: process.env?.WEBHOOK_EVENTS_MESSAGES_SET === 'true',
|
||||||
MESSAGES_UPSERT: process.env?.WEBHOOK_EVENTS_MESSAGES_UPSERT === 'true',
|
MESSAGES_UPSERT: process.env?.WEBHOOK_EVENTS_MESSAGES_UPSERT === 'true',
|
||||||
MESSAGES_UPDATE: process.env?.WEBHOOK_EVENTS_MESSAGES_UPDATE === 'true',
|
MESSAGES_UPDATE: process.env?.WEBHOOK_EVENTS_MESSAGES_UPDATE === 'true',
|
||||||
|
MESSAGES_DELETE: process.env?.WEBHOOK_EVENTS_MESSAGES_DELETE === 'true',
|
||||||
|
SEND_MESSAGE: process.env?.WEBHOOK_EVENTS_SEND_MESSAGE === 'true',
|
||||||
CONTACTS_SET: process.env?.WEBHOOK_EVENTS_CONTACTS_SET === 'true',
|
CONTACTS_SET: process.env?.WEBHOOK_EVENTS_CONTACTS_SET === 'true',
|
||||||
CONTACTS_UPDATE: process.env?.WEBHOOK_EVENTS_CONTACTS_UPDATE === 'true',
|
CONTACTS_UPDATE: process.env?.WEBHOOK_EVENTS_CONTACTS_UPDATE === 'true',
|
||||||
CONTACTS_UPSERT: process.env?.WEBHOOK_EVENTS_CONTACTS_UPSERT === 'true',
|
CONTACTS_UPSERT: process.env?.WEBHOOK_EVENTS_CONTACTS_UPSERT === 'true',
|
||||||
@@ -248,15 +246,16 @@ export class ConfigService {
|
|||||||
GROUP_UPDATE: process.env?.WEBHOOK_EVENTS_GROUPS_UPDATE === 'true',
|
GROUP_UPDATE: process.env?.WEBHOOK_EVENTS_GROUPS_UPDATE === 'true',
|
||||||
GROUP_PARTICIPANTS_UPDATE:
|
GROUP_PARTICIPANTS_UPDATE:
|
||||||
process.env?.WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE === 'true',
|
process.env?.WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE === 'true',
|
||||||
|
CALL: process.env?.WEBHOOK_EVENTS_CALL === 'true',
|
||||||
NEW_JWT_TOKEN: process.env?.WEBHOOK_EVENTS_NEW_JWT_TOKEN === 'true',
|
NEW_JWT_TOKEN: process.env?.WEBHOOK_EVENTS_NEW_JWT_TOKEN === 'true',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CONFIG_SESSION_PHONE: {
|
CONFIG_SESSION_PHONE: {
|
||||||
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT,
|
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API',
|
||||||
NAME: process.env?.CONFIG_SESSION_PHONE_NAME,
|
NAME: process.env?.CONFIG_SESSION_PHONE_NAME || 'chrome',
|
||||||
},
|
},
|
||||||
QRCODE: {
|
QRCODE: {
|
||||||
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT),
|
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,
|
||||||
},
|
},
|
||||||
AUTHENTICATION: {
|
AUTHENTICATION: {
|
||||||
TYPE: process.env.AUTHENTICATION_TYPE as 'jwt',
|
TYPE: process.env.AUTHENTICATION_TYPE as 'jwt',
|
||||||
@@ -271,11 +270,6 @@ export class ConfigService {
|
|||||||
: 3600,
|
: 3600,
|
||||||
SECRET: process.env.AUTHENTICATION_JWT_SECRET,
|
SECRET: process.env.AUTHENTICATION_JWT_SECRET,
|
||||||
},
|
},
|
||||||
INSTANCE: {
|
|
||||||
NAME: process.env.AUTHENTICATION_INSTANCE_NAME,
|
|
||||||
WEBHOOK_URL: process.env.AUTHENTICATION_INSTANCE_WEBHOOK_URL,
|
|
||||||
MODE: process.env.AUTHENTICATION_INSTANCE_MODE,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ export const ROOT_DIR = process.cwd();
|
|||||||
export const INSTANCE_DIR = join(ROOT_DIR, 'instances');
|
export const INSTANCE_DIR = join(ROOT_DIR, 'instances');
|
||||||
export const SRC_DIR = join(ROOT_DIR, 'src');
|
export const SRC_DIR = join(ROOT_DIR, 'src');
|
||||||
export const AUTH_DIR = join(ROOT_DIR, 'store', 'auth');
|
export const AUTH_DIR = join(ROOT_DIR, 'store', 'auth');
|
||||||
|
export const STORE_DIR = join(ROOT_DIR, 'store');
|
||||||
|
|||||||
@@ -104,9 +104,11 @@ export class RedisCache {
|
|||||||
public async delAll(hash?: string) {
|
public async delAll(hash?: string) {
|
||||||
try {
|
try {
|
||||||
this.logger.verbose('instance delAll: ' + hash);
|
this.logger.verbose('instance delAll: ' + hash);
|
||||||
return await this.client.del(
|
const result = await this.client.del(
|
||||||
hash || this.redisEnv.PREFIX_KEY + ':' + this.instanceName,
|
hash || this.redisEnv.PREFIX_KEY + ':' + this.instanceName,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,11 @@
|
|||||||
SERVER:
|
SERVER:
|
||||||
TYPE: http # https
|
TYPE: http # https
|
||||||
PORT: 8080 # 443
|
PORT: 8080 # 443
|
||||||
|
URL: localhost
|
||||||
|
|
||||||
CORS:
|
CORS:
|
||||||
ORIGIN:
|
ORIGIN:
|
||||||
- '*'
|
- "*"
|
||||||
# - yourdomain.com
|
# - yourdomain.com
|
||||||
METHODS:
|
METHODS:
|
||||||
- POST
|
- POST
|
||||||
@@ -38,7 +39,7 @@ LOG:
|
|||||||
- DARK
|
- DARK
|
||||||
- WEBHOOKS
|
- WEBHOOKS
|
||||||
COLOR: true
|
COLOR: true
|
||||||
BAILEYS: error # "fatal" | "error" | "warn" | "info" | "debug" | "trace"
|
BAILEYS: error # fatal | error | warn | info | debug | trace
|
||||||
|
|
||||||
# Determine how long the instance should be deleted from memory in case of no connection.
|
# Determine how long the instance should be deleted from memory in case of no connection.
|
||||||
# Default time: 5 minutes
|
# Default time: 5 minutes
|
||||||
@@ -61,40 +62,42 @@ CLEAN_STORE:
|
|||||||
|
|
||||||
# Permanent data storage
|
# Permanent data storage
|
||||||
DATABASE:
|
DATABASE:
|
||||||
ENABLED: true
|
ENABLED: false
|
||||||
CONNECTION:
|
CONNECTION:
|
||||||
URI: 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true'
|
URI: "mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true"
|
||||||
DB_PREFIX_NAME: evolution
|
DB_PREFIX_NAME: evolution
|
||||||
# Choose the data you want to save in the application's database or store
|
# Choose the data you want to save in the application's database or store
|
||||||
SAVE_DATA:
|
SAVE_DATA:
|
||||||
INSTANCE: false
|
INSTANCE: false
|
||||||
OLD_MESSAGE: false
|
NEW_MESSAGE: false
|
||||||
NEW_MESSAGE: true
|
MESSAGE_UPDATE: false
|
||||||
MESSAGE_UPDATE: true
|
CONTACTS: false
|
||||||
CONTACTS: true
|
CHATS: false
|
||||||
CHATS: true
|
|
||||||
|
|
||||||
REDIS:
|
REDIS:
|
||||||
ENABLED: true
|
ENABLED: false
|
||||||
URI: 'redis://localhost:6379/1'
|
URI: "redis://localhost:6379"
|
||||||
PREFIX_KEY: 'evolution'
|
PREFIX_KEY: "evolution"
|
||||||
|
|
||||||
# Webhook Settings
|
# Global Webhook Settings
|
||||||
|
# Each instance's Webhook URL and events will be requested at the time it is created
|
||||||
WEBHOOK:
|
WEBHOOK:
|
||||||
# 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
|
||||||
GLOBAL:
|
GLOBAL:
|
||||||
URL: <url>
|
URL: <url>
|
||||||
ENABLED: true
|
ENABLED: false
|
||||||
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
|
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
|
||||||
WEBHOOK_BY_EVENTS: false
|
WEBHOOK_BY_EVENTS: false
|
||||||
# Automatically maps webhook paths
|
# Automatically maps webhook paths
|
||||||
# Set the events you want to hear
|
# Set the events you want to hear
|
||||||
EVENTS:
|
EVENTS:
|
||||||
APPLICATION_STARTUP: true
|
APPLICATION_STARTUP: false
|
||||||
QRCODE_UPDATED: true
|
QRCODE_UPDATED: true
|
||||||
MESSAGES_SET: true
|
MESSAGES_SET: true
|
||||||
MESSAGES_UPSERT: true
|
MESSAGES_UPSERT: true
|
||||||
MESSAGES_UPDATE: true
|
MESSAGES_UPDATE: true
|
||||||
|
MESSAGES_DELETE: true
|
||||||
|
SEND_MESSAGE: true
|
||||||
CONTACTS_SET: true
|
CONTACTS_SET: true
|
||||||
CONTACTS_UPSERT: true
|
CONTACTS_UPSERT: true
|
||||||
CONTACTS_UPDATE: true
|
CONTACTS_UPDATE: true
|
||||||
@@ -107,12 +110,13 @@ WEBHOOK:
|
|||||||
GROUP_UPDATE: true
|
GROUP_UPDATE: true
|
||||||
GROUP_PARTICIPANTS_UPDATE: true
|
GROUP_PARTICIPANTS_UPDATE: true
|
||||||
CONNECTION_UPDATE: true
|
CONNECTION_UPDATE: true
|
||||||
|
CALL: true
|
||||||
# This event fires every time a new token is requested via the refresh route
|
# This event fires every time a new token is requested via the refresh route
|
||||||
NEW_JWT_TOKEN: true
|
NEW_JWT_TOKEN: false
|
||||||
|
|
||||||
CONFIG_SESSION_PHONE:
|
CONFIG_SESSION_PHONE:
|
||||||
# Name that will be displayed on smartphone connection
|
# Name that will be displayed on smartphone connection
|
||||||
CLIENT: 'Evolution API'
|
CLIENT: "Evolution API"
|
||||||
NAME: chrome # chrome | firefox | edge | opera | safari
|
NAME: chrome # chrome | firefox | edge | opera | safari
|
||||||
|
|
||||||
# Set qrcode display limit
|
# Set qrcode display limit
|
||||||
@@ -120,6 +124,8 @@ QRCODE:
|
|||||||
LIMIT: 30
|
LIMIT: 30
|
||||||
|
|
||||||
# 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,
|
||||||
|
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
|
||||||
AUTHENTICATION:
|
AUTHENTICATION:
|
||||||
TYPE: apikey # jwt or apikey
|
TYPE: apikey # jwt or apikey
|
||||||
# Define a global apikey to access all instances
|
# Define a global apikey to access all instances
|
||||||
@@ -132,10 +138,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`
|
||||||
# Set the instance name and webhook url to create an instance in init the application
|
|
||||||
INSTANCE:
|
|
||||||
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
|
|
||||||
MODE: server # container or server
|
|
||||||
# if you are using container mode, set the container name and the webhook url to default instance
|
|
||||||
NAME: evolution
|
|
||||||
WEBHOOK_URL: <url>
|
|
||||||
|
|||||||
29
src/main.ts
29
src/main.ts
@@ -10,6 +10,7 @@ import { waMonitor } from './whatsapp/whatsapp.module';
|
|||||||
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
||||||
import 'express-async-errors';
|
import 'express-async-errors';
|
||||||
import { ServerUP } from './utils/server-up';
|
import { ServerUP } from './utils/server-up';
|
||||||
|
import * as Sentry from '@sentry/node';
|
||||||
|
|
||||||
function initWA() {
|
function initWA() {
|
||||||
waMonitor.loadInstance();
|
waMonitor.loadInstance();
|
||||||
@@ -19,6 +20,27 @@ function bootstrap() {
|
|||||||
const logger = new Logger('SERVER');
|
const logger = new Logger('SERVER');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// Sentry.init({
|
||||||
|
// dsn: '',
|
||||||
|
// integrations: [
|
||||||
|
// // enable HTTP calls tracing
|
||||||
|
// new Sentry.Integrations.Http({ tracing: true }),
|
||||||
|
// // enable Express.js middleware tracing
|
||||||
|
// new Sentry.Integrations.Express({ app }),
|
||||||
|
// // Automatically instrument Node.js libraries and frameworks
|
||||||
|
// ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
|
||||||
|
// ],
|
||||||
|
|
||||||
|
// // Set tracesSampleRate to 1.0 to capture 100%
|
||||||
|
// // of transactions for performance monitoring.
|
||||||
|
// // We recommend adjusting this value in production
|
||||||
|
// tracesSampleRate: 1.0,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// app.use(Sentry.Handlers.requestHandler());
|
||||||
|
|
||||||
|
// app.use(Sentry.Handlers.tracingHandler());
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin(requestOrigin, callback) {
|
origin(requestOrigin, callback) {
|
||||||
@@ -43,6 +65,13 @@ function bootstrap() {
|
|||||||
|
|
||||||
app.use('/', router);
|
app.use('/', router);
|
||||||
|
|
||||||
|
// app.use(Sentry.Handlers.errorHandler());
|
||||||
|
|
||||||
|
// app.use(function onError(err, req, res, next) {
|
||||||
|
// res.statusCode = 500;
|
||||||
|
// res.end(res.sentry + '\n');
|
||||||
|
// });
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export const instanceNameSchema: JSONSchema7 = {
|
|||||||
webhook_by_events: { type: 'boolean' },
|
webhook_by_events: { type: 'boolean' },
|
||||||
events: {
|
events: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
minItems: 1,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: [
|
enum: [
|
||||||
@@ -39,6 +39,8 @@ export const instanceNameSchema: JSONSchema7 = {
|
|||||||
'MESSAGES_SET',
|
'MESSAGES_SET',
|
||||||
'MESSAGES_UPSERT',
|
'MESSAGES_UPSERT',
|
||||||
'MESSAGES_UPDATE',
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
'CONTACTS_SET',
|
'CONTACTS_SET',
|
||||||
'CONTACTS_UPSERT',
|
'CONTACTS_UPSERT',
|
||||||
'CONTACTS_UPDATE',
|
'CONTACTS_UPDATE',
|
||||||
@@ -51,11 +53,13 @@ export const instanceNameSchema: JSONSchema7 = {
|
|||||||
'GROUP_UPDATE',
|
'GROUP_UPDATE',
|
||||||
'GROUP_PARTICIPANTS_UPDATE',
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
'CONNECTION_UPDATE',
|
'CONNECTION_UPDATE',
|
||||||
|
'CALL',
|
||||||
'NEW_JWT_TOKEN',
|
'NEW_JWT_TOKEN',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
qrcode: { type: 'boolean', enum: [true, false] },
|
qrcode: { type: 'boolean', enum: [true, false] },
|
||||||
|
number: { type: 'string', pattern: '^\\d+[\\.@\\w-]+' },
|
||||||
token: { type: 'string' },
|
token: { type: 'string' },
|
||||||
},
|
},
|
||||||
...isNotEmpty('instanceName'),
|
...isNotEmpty('instanceName'),
|
||||||
@@ -80,8 +84,8 @@ const quotedOptionsSchema: JSONSchema7 = {
|
|||||||
remoteJid: { type: 'string' },
|
remoteJid: { type: 'string' },
|
||||||
fromMe: { type: 'boolean', enum: [true, false] },
|
fromMe: { type: 'boolean', enum: [true, false] },
|
||||||
},
|
},
|
||||||
required: ['id', 'remoteJid', 'fromMe'],
|
required: ['id'],
|
||||||
...isNotEmpty('id', 'remoteJid'),
|
...isNotEmpty('id'),
|
||||||
},
|
},
|
||||||
message: { type: 'object' },
|
message: { type: 'object' },
|
||||||
},
|
},
|
||||||
@@ -121,7 +125,6 @@ const optionsSchema: JSONSchema7 = {
|
|||||||
|
|
||||||
const numberDefinition: JSONSchema7Definition = {
|
const numberDefinition: JSONSchema7Definition = {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
pattern: '^\\d+[\\.@\\w-]+',
|
|
||||||
description: 'Invalid format',
|
description: 'Invalid format',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -143,24 +146,6 @@ export const textMessageSchema: JSONSchema7 = {
|
|||||||
required: ['textMessage', 'number'],
|
required: ['textMessage', 'number'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const linkPreviewSchema: JSONSchema7 = {
|
|
||||||
$id: v4(),
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
number: { ...numberDefinition },
|
|
||||||
options: { ...optionsSchema },
|
|
||||||
linkPreview: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
text: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['text'],
|
|
||||||
...isNotEmpty('text'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
required: ['linkPreview', 'number'],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const pollMessageSchema: JSONSchema7 = {
|
export const pollMessageSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@@ -189,6 +174,37 @@ export const pollMessageSchema: JSONSchema7 = {
|
|||||||
required: ['pollMessage', 'number'],
|
required: ['pollMessage', 'number'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const statusMessageSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
statusMessage: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
type: { type: 'string', enum: ['text', 'image', 'audio', 'video'] },
|
||||||
|
content: { type: 'string' },
|
||||||
|
caption: { type: 'string' },
|
||||||
|
backgroundColor: { type: 'string' },
|
||||||
|
font: { type: 'integer', minimum: 0, maximum: 5 },
|
||||||
|
statusJidList: {
|
||||||
|
type: 'array',
|
||||||
|
minItems: 1,
|
||||||
|
uniqueItems: true,
|
||||||
|
items: {
|
||||||
|
type: 'string',
|
||||||
|
pattern: '^\\d+',
|
||||||
|
description: '"statusJidList" must be an array of numeric strings',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
allContacts: { type: 'boolean', enum: [true, false] },
|
||||||
|
},
|
||||||
|
required: ['type', 'content'],
|
||||||
|
...isNotEmpty('type', 'content'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['statusMessage'],
|
||||||
|
};
|
||||||
|
|
||||||
export const mediaMessageSchema: JSONSchema7 = {
|
export const mediaMessageSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@@ -383,7 +399,7 @@ export const contactMessageSchema: JSONSchema7 = {
|
|||||||
email: { type: 'string' },
|
email: { type: 'string' },
|
||||||
url: { type: 'string' },
|
url: { type: 'string' },
|
||||||
},
|
},
|
||||||
required: ['fullName', 'wuid', 'phoneNumber'],
|
required: ['fullName', 'phoneNumber'],
|
||||||
...isNotEmpty('fullName'),
|
...isNotEmpty('fullName'),
|
||||||
},
|
},
|
||||||
minItems: 1,
|
minItems: 1,
|
||||||
@@ -430,7 +446,6 @@ export const whatsappNumberSchema: JSONSchema7 = {
|
|||||||
uniqueItems: true,
|
uniqueItems: true,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
pattern: '^\\d+',
|
|
||||||
description: '"numbers" must be an array of numeric strings',
|
description: '"numbers" must be an array of numeric strings',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -441,7 +456,7 @@ export const readMessageSchema: JSONSchema7 = {
|
|||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
readMessages: {
|
read_messages: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
minItems: 1,
|
minItems: 1,
|
||||||
uniqueItems: true,
|
uniqueItems: true,
|
||||||
@@ -456,7 +471,7 @@ export const readMessageSchema: JSONSchema7 = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: ['readMessages'],
|
required: ['read_messages'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const privacySettingsSchema: JSONSchema7 = {
|
export const privacySettingsSchema: JSONSchema7 = {
|
||||||
@@ -572,6 +587,17 @@ export const profilePictureSchema: JSONSchema7 = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const profileSchema: JSONSchema7 = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
wuid: { type: 'string' },
|
||||||
|
name: { type: 'string' },
|
||||||
|
picture: { type: 'string' },
|
||||||
|
status: { type: 'string' },
|
||||||
|
isBusiness: { type: 'boolean' },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const messageValidateSchema: JSONSchema7 = {
|
export const messageValidateSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@@ -642,6 +668,7 @@ export const createGroupSchema: JSONSchema7 = {
|
|||||||
subject: { type: 'string' },
|
subject: { type: 'string' },
|
||||||
description: { type: 'string' },
|
description: { type: 'string' },
|
||||||
profilePicture: { type: 'string' },
|
profilePicture: { type: 'string' },
|
||||||
|
promoteParticipants: { type: 'boolean', enum: [true, false] },
|
||||||
participants: {
|
participants: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
minItems: 1,
|
minItems: 1,
|
||||||
@@ -668,6 +695,16 @@ export const groupJidSchema: JSONSchema7 = {
|
|||||||
...isNotEmpty('groupJid'),
|
...isNotEmpty('groupJid'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getParticipantsSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
getParticipants: { type: 'string', enum: ['true', 'false'] },
|
||||||
|
},
|
||||||
|
required: ['getParticipants'],
|
||||||
|
...isNotEmpty('getParticipants'),
|
||||||
|
};
|
||||||
|
|
||||||
export const groupSendInviteSchema: JSONSchema7 = {
|
export const groupSendInviteSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@@ -795,7 +832,7 @@ export const webhookSchema: JSONSchema7 = {
|
|||||||
enabled: { type: 'boolean', enum: [true, false] },
|
enabled: { type: 'boolean', enum: [true, false] },
|
||||||
events: {
|
events: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
minItems: 1,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: [
|
enum: [
|
||||||
@@ -804,6 +841,8 @@ export const webhookSchema: JSONSchema7 = {
|
|||||||
'MESSAGES_SET',
|
'MESSAGES_SET',
|
||||||
'MESSAGES_UPSERT',
|
'MESSAGES_UPSERT',
|
||||||
'MESSAGES_UPDATE',
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
'CONTACTS_SET',
|
'CONTACTS_SET',
|
||||||
'CONTACTS_UPSERT',
|
'CONTACTS_UPSERT',
|
||||||
'CONTACTS_UPDATE',
|
'CONTACTS_UPDATE',
|
||||||
@@ -816,6 +855,7 @@ export const webhookSchema: JSONSchema7 = {
|
|||||||
'GROUP_UPDATE',
|
'GROUP_UPDATE',
|
||||||
'GROUP_PARTICIPANTS_UPDATE',
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
'CONNECTION_UPDATE',
|
'CONNECTION_UPDATE',
|
||||||
|
'CALL',
|
||||||
'NEW_JWT_TOKEN',
|
'NEW_JWT_TOKEN',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -824,3 +864,61 @@ export const webhookSchema: JSONSchema7 = {
|
|||||||
required: ['url', 'enabled'],
|
required: ['url', 'enabled'],
|
||||||
...isNotEmpty('url'),
|
...isNotEmpty('url'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const chatwootSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
enabled: { type: 'boolean', enum: [true, false] },
|
||||||
|
account_id: { type: 'string' },
|
||||||
|
token: { type: 'string' },
|
||||||
|
url: { type: 'string' },
|
||||||
|
sign_msg: { type: 'boolean', enum: [true, false] },
|
||||||
|
reopen_conversation: { type: 'boolean', enum: [true, false] },
|
||||||
|
conversation_pending: { type: 'boolean', enum: [true, false] },
|
||||||
|
},
|
||||||
|
required: [
|
||||||
|
'enabled',
|
||||||
|
'account_id',
|
||||||
|
'token',
|
||||||
|
'url',
|
||||||
|
'sign_msg',
|
||||||
|
'reopen_conversation',
|
||||||
|
'conversation_pending',
|
||||||
|
],
|
||||||
|
...isNotEmpty(
|
||||||
|
'account_id',
|
||||||
|
'token',
|
||||||
|
'url',
|
||||||
|
'sign_msg',
|
||||||
|
'reopen_conversation',
|
||||||
|
'conversation_pending',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const settingsSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
reject_call: { type: 'boolean', enum: [true, false] },
|
||||||
|
msg_call: { type: 'string' },
|
||||||
|
groups_ignore: { type: 'boolean', enum: [true, false] },
|
||||||
|
always_online: { type: 'boolean', enum: [true, false] },
|
||||||
|
read_messages: { type: 'boolean', enum: [true, false] },
|
||||||
|
read_status: { type: 'boolean', enum: [true, false] },
|
||||||
|
},
|
||||||
|
required: [
|
||||||
|
'reject_call',
|
||||||
|
'groups_ignore',
|
||||||
|
'always_online',
|
||||||
|
'read_messages',
|
||||||
|
'read_status',
|
||||||
|
],
|
||||||
|
...isNotEmpty(
|
||||||
|
'reject_call',
|
||||||
|
'groups_ignore',
|
||||||
|
'always_online',
|
||||||
|
'read_messages',
|
||||||
|
'read_status',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import { ROOT_DIR } from '../../config/path.config';
|
|||||||
export type IInsert = { insertCount: number };
|
export type IInsert = { insertCount: number };
|
||||||
|
|
||||||
export interface IRepository {
|
export interface IRepository {
|
||||||
insert(data: any, saveDb?: boolean): Promise<IInsert>;
|
insert(data: any, instanceName: string, saveDb?: boolean): Promise<IInsert>;
|
||||||
|
update(data: any, instanceName: string, saveDb?: boolean): Promise<IInsert>;
|
||||||
find(query: any): Promise<any>;
|
find(query: any): Promise<any>;
|
||||||
delete(query: any, force?: boolean): Promise<any>;
|
delete(query: any, force?: boolean): Promise<any>;
|
||||||
|
|
||||||
@@ -45,9 +46,14 @@ export abstract class Repository implements IRepository {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public insert(data: any, saveDb = false): Promise<IInsert> {
|
public insert(data: any, instanceName: string, saveDb = false): Promise<IInsert> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public update(data: any, instanceName: string, saveDb = false): Promise<IInsert> {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
|
|
||||||
public find(query: any): Promise<any> {
|
public find(query: any): Promise<any> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { validate } from 'jsonschema';
|
|||||||
import { BadRequestException } from '../../exceptions';
|
import { BadRequestException } from '../../exceptions';
|
||||||
import 'express-async-errors';
|
import 'express-async-errors';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { GroupInvite, GroupJid } from '../dto/group.dto';
|
import { GetParticipant, GroupInvite, GroupJid } from '../dto/group.dto';
|
||||||
|
|
||||||
type DataValidate<T> = {
|
type DataValidate<T> = {
|
||||||
request: Request;
|
request: Request;
|
||||||
@@ -160,7 +160,46 @@ export abstract class RouterBroker {
|
|||||||
|
|
||||||
const v = validate(ref, schema);
|
const v = validate(ref, schema);
|
||||||
|
|
||||||
console.log(v, '@checkei aqui');
|
if (!v.valid) {
|
||||||
|
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||||
|
let message: string;
|
||||||
|
if (schema['description']) {
|
||||||
|
message = schema['description'];
|
||||||
|
} else {
|
||||||
|
message = stack.replace('instance.', '');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
property: property.replace('instance.', ''),
|
||||||
|
message,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
logger.error([...message]);
|
||||||
|
throw new BadRequestException(...message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await execute(instance, ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getParticipantsValidate<T>(args: DataValidate<T>) {
|
||||||
|
const { request, ClassRef, schema, execute } = args;
|
||||||
|
|
||||||
|
const getParticipants = request.query as unknown as GetParticipant;
|
||||||
|
|
||||||
|
if (!getParticipants?.getParticipants) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'The getParticipants needs to be informed in the query',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = request.params as unknown as InstanceDto;
|
||||||
|
const body = request.body;
|
||||||
|
|
||||||
|
const ref = new ClassRef();
|
||||||
|
|
||||||
|
Object.assign(body, getParticipants);
|
||||||
|
Object.assign(ref, body);
|
||||||
|
|
||||||
|
const v = validate(ref, schema);
|
||||||
|
|
||||||
if (!v.valid) {
|
if (!v.valid) {
|
||||||
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||||
|
|||||||
@@ -16,31 +16,48 @@ import { ContactQuery } from '../repository/contact.repository';
|
|||||||
import { MessageQuery } from '../repository/message.repository';
|
import { MessageQuery } from '../repository/message.repository';
|
||||||
import { MessageUpQuery } from '../repository/messageUp.repository';
|
import { MessageUpQuery } from '../repository/messageUp.repository';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('ChatController');
|
||||||
|
|
||||||
export class ChatController {
|
export class ChatController {
|
||||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||||
|
|
||||||
public async whatsappNumber({ instanceName }: InstanceDto, data: WhatsAppNumberDto) {
|
public async whatsappNumber({ instanceName }: InstanceDto, data: WhatsAppNumberDto) {
|
||||||
|
logger.verbose('requested whatsappNumber from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].whatsappNumber(data);
|
return await this.waMonitor.waInstances[instanceName].whatsappNumber(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async readMessage({ instanceName }: InstanceDto, data: ReadMessageDto) {
|
public async readMessage({ instanceName }: InstanceDto, data: ReadMessageDto) {
|
||||||
|
logger.verbose('requested readMessage from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].markMessageAsRead(data);
|
return await this.waMonitor.waInstances[instanceName].markMessageAsRead(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async archiveChat({ instanceName }: InstanceDto, data: ArchiveChatDto) {
|
public async archiveChat({ instanceName }: InstanceDto, data: ArchiveChatDto) {
|
||||||
|
logger.verbose('requested archiveChat from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].archiveChat(data);
|
return await this.waMonitor.waInstances[instanceName].archiveChat(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) {
|
public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) {
|
||||||
|
logger.verbose('requested deleteMessage from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].deleteMessage(data);
|
return await this.waMonitor.waInstances[instanceName].deleteMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchProfilePicture({ instanceName }: InstanceDto, data: NumberDto) {
|
public async fetchProfilePicture({ instanceName }: InstanceDto, data: NumberDto) {
|
||||||
|
logger.verbose('requested fetchProfilePicture from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].profilePicture(data.number);
|
return await this.waMonitor.waInstances[instanceName].profilePicture(data.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async fetchProfile({ instanceName }: InstanceDto, data: NumberDto) {
|
||||||
|
logger.verbose('requested fetchProfile from ' + instanceName + ' instance');
|
||||||
|
return await this.waMonitor.waInstances[instanceName].fetchProfile(
|
||||||
|
instanceName,
|
||||||
|
data.number,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public async fetchContacts({ instanceName }: InstanceDto, query: ContactQuery) {
|
public async fetchContacts({ instanceName }: InstanceDto, query: ContactQuery) {
|
||||||
|
logger.verbose('requested fetchContacts from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchContacts(query);
|
return await this.waMonitor.waInstances[instanceName].fetchContacts(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,22 +65,29 @@ export class ChatController {
|
|||||||
{ instanceName }: InstanceDto,
|
{ instanceName }: InstanceDto,
|
||||||
data: getBase64FromMediaMessageDto,
|
data: getBase64FromMediaMessageDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested getBase64FromMediaMessage from ' + instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instanceName].getBase64FromMediaMessage(data);
|
return await this.waMonitor.waInstances[instanceName].getBase64FromMediaMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchMessages({ instanceName }: InstanceDto, query: MessageQuery) {
|
public async fetchMessages({ instanceName }: InstanceDto, query: MessageQuery) {
|
||||||
|
logger.verbose('requested fetchMessages from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchMessages(query);
|
return await this.waMonitor.waInstances[instanceName].fetchMessages(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchStatusMessage({ instanceName }: InstanceDto, query: MessageUpQuery) {
|
public async fetchStatusMessage({ instanceName }: InstanceDto, query: MessageUpQuery) {
|
||||||
|
logger.verbose('requested fetchStatusMessage from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchStatusMessage(query);
|
return await this.waMonitor.waInstances[instanceName].fetchStatusMessage(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchChats({ instanceName }: InstanceDto) {
|
public async fetchChats({ instanceName }: InstanceDto) {
|
||||||
|
logger.verbose('requested fetchChats from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchChats();
|
return await this.waMonitor.waInstances[instanceName].fetchChats();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchPrivacySettings({ instanceName }: InstanceDto) {
|
public async fetchPrivacySettings({ instanceName }: InstanceDto) {
|
||||||
|
logger.verbose('requested fetchPrivacySettings from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +95,7 @@ export class ChatController {
|
|||||||
{ instanceName }: InstanceDto,
|
{ instanceName }: InstanceDto,
|
||||||
data: PrivacySettingDto,
|
data: PrivacySettingDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose('requested updatePrivacySettings from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].updatePrivacySettings(data);
|
return await this.waMonitor.waInstances[instanceName].updatePrivacySettings(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +103,14 @@ export class ChatController {
|
|||||||
{ instanceName }: InstanceDto,
|
{ instanceName }: InstanceDto,
|
||||||
data: ProfilePictureDto,
|
data: ProfilePictureDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose('requested fetchBusinessProfile from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchBusinessProfile(
|
return await this.waMonitor.waInstances[instanceName].fetchBusinessProfile(
|
||||||
data.number,
|
data.number,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateProfileName({ instanceName }: InstanceDto, data: ProfileNameDto) {
|
public async updateProfileName({ instanceName }: InstanceDto, data: ProfileNameDto) {
|
||||||
|
logger.verbose('requested updateProfileName from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].updateProfileName(data.name);
|
return await this.waMonitor.waInstances[instanceName].updateProfileName(data.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +118,7 @@ export class ChatController {
|
|||||||
{ instanceName }: InstanceDto,
|
{ instanceName }: InstanceDto,
|
||||||
data: ProfileStatusDto,
|
data: ProfileStatusDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose('requested updateProfileStatus from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].updateProfileStatus(
|
return await this.waMonitor.waInstances[instanceName].updateProfileStatus(
|
||||||
data.status,
|
data.status,
|
||||||
);
|
);
|
||||||
@@ -100,6 +128,7 @@ export class ChatController {
|
|||||||
{ instanceName }: InstanceDto,
|
{ instanceName }: InstanceDto,
|
||||||
data: ProfilePictureDto,
|
data: ProfilePictureDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose('requested updateProfilePicture from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].updateProfilePicture(
|
return await this.waMonitor.waInstances[instanceName].updateProfilePicture(
|
||||||
data.picture,
|
data.picture,
|
||||||
);
|
);
|
||||||
@@ -109,6 +138,7 @@ export class ChatController {
|
|||||||
{ instanceName }: InstanceDto,
|
{ instanceName }: InstanceDto,
|
||||||
data: ProfilePictureDto,
|
data: ProfilePictureDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose('requested removeProfilePicture from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].removeProfilePicture();
|
return await this.waMonitor.waInstances[instanceName].removeProfilePicture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
105
src/whatsapp/controllers/chatwoot.controller.ts
Normal file
105
src/whatsapp/controllers/chatwoot.controller.ts
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import { isURL } from 'class-validator';
|
||||||
|
import { BadRequestException } from '../../exceptions';
|
||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||||
|
import { ChatwootService } from '../services/chatwoot.service';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
import { waMonitor } from '../whatsapp.module';
|
||||||
|
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||||
|
|
||||||
|
const logger = new Logger('ChatwootController');
|
||||||
|
|
||||||
|
export class ChatwootController {
|
||||||
|
constructor(
|
||||||
|
private readonly chatwootService: ChatwootService,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public async createChatwoot(instance: InstanceDto, data: ChatwootDto) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested createChatwoot from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (data.enabled) {
|
||||||
|
if (!isURL(data.url, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('url is not valid');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.account_id) {
|
||||||
|
throw new BadRequestException('account_id is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.token) {
|
||||||
|
throw new BadRequestException('token is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.sign_msg !== true && data.sign_msg !== false) {
|
||||||
|
throw new BadRequestException('sign_msg is required');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.enabled) {
|
||||||
|
logger.verbose('chatwoot disabled');
|
||||||
|
data.account_id = '';
|
||||||
|
data.token = '';
|
||||||
|
data.url = '';
|
||||||
|
data.sign_msg = false;
|
||||||
|
data.reopen_conversation = false;
|
||||||
|
data.conversation_pending = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.name_inbox = instance.instanceName;
|
||||||
|
|
||||||
|
const result = this.chatwootService.create(instance, data);
|
||||||
|
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
...result,
|
||||||
|
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async findChatwoot(instance: InstanceDto) {
|
||||||
|
logger.verbose('requested findChatwoot from ' + instance.instanceName + ' instance');
|
||||||
|
const result = await this.chatwootService.find(instance);
|
||||||
|
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
if (Object.keys(result).length === 0) {
|
||||||
|
return {
|
||||||
|
enabled: false,
|
||||||
|
url: '',
|
||||||
|
account_id: '',
|
||||||
|
token: '',
|
||||||
|
sign_msg: false,
|
||||||
|
name_inbox: '',
|
||||||
|
webhook_url: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
...result,
|
||||||
|
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async receiveWebhook(instance: InstanceDto, data: any) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested receiveWebhook from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
|
const chatwootService = new ChatwootService(waMonitor, this.configService);
|
||||||
|
|
||||||
|
return chatwootService.receiveWebhook(instance, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async newInstance(data: any) {
|
||||||
|
const chatwootService = new ChatwootService(waMonitor, this.configService);
|
||||||
|
|
||||||
|
return chatwootService.newInstance(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
CreateGroupDto,
|
CreateGroupDto,
|
||||||
|
GetParticipant,
|
||||||
GroupDescriptionDto,
|
GroupDescriptionDto,
|
||||||
GroupInvite,
|
GroupInvite,
|
||||||
GroupJid,
|
GroupJid,
|
||||||
@@ -12,21 +13,31 @@ import {
|
|||||||
} from '../dto/group.dto';
|
} from '../dto/group.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('ChatController');
|
||||||
|
|
||||||
export class GroupController {
|
export class GroupController {
|
||||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||||
|
|
||||||
public async createGroup(instance: InstanceDto, create: CreateGroupDto) {
|
public async createGroup(instance: InstanceDto, create: CreateGroupDto) {
|
||||||
|
logger.verbose('requested createGroup from ' + instance.instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].createGroup(create);
|
return await this.waMonitor.waInstances[instance.instanceName].createGroup(create);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateGroupPicture(instance: InstanceDto, update: GroupPictureDto) {
|
public async updateGroupPicture(instance: InstanceDto, update: GroupPictureDto) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested updateGroupPicture from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].updateGroupPicture(
|
return await this.waMonitor.waInstances[instance.instanceName].updateGroupPicture(
|
||||||
update,
|
update,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateGroupSubject(instance: InstanceDto, update: GroupSubjectDto) {
|
public async updateGroupSubject(instance: InstanceDto, update: GroupSubjectDto) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested updateGroupSubject from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].updateGroupSubject(
|
return await this.waMonitor.waInstances[instance.instanceName].updateGroupSubject(
|
||||||
update,
|
update,
|
||||||
);
|
);
|
||||||
@@ -36,38 +47,56 @@ export class GroupController {
|
|||||||
instance: InstanceDto,
|
instance: InstanceDto,
|
||||||
update: GroupDescriptionDto,
|
update: GroupDescriptionDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested updateGroupDescription from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].updateGroupDescription(
|
return await this.waMonitor.waInstances[instance.instanceName].updateGroupDescription(
|
||||||
update,
|
update,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findGroupInfo(instance: InstanceDto, groupJid: GroupJid) {
|
public async findGroupInfo(instance: InstanceDto, groupJid: GroupJid) {
|
||||||
|
logger.verbose('requested findGroupInfo from ' + instance.instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
|
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAllGroups(instance: InstanceDto) {
|
public async fetchAllGroups(instance: InstanceDto, getPaticipants: GetParticipant) {
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].fetchAllGroups();
|
logger.verbose(
|
||||||
|
'requested fetchAllGroups from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
|
return await this.waMonitor.waInstances[instance.instanceName].fetchAllGroups(
|
||||||
|
getPaticipants,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async inviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
public async inviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
||||||
|
logger.verbose('requested inviteCode from ' + instance.instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].inviteCode(groupJid);
|
return await this.waMonitor.waInstances[instance.instanceName].inviteCode(groupJid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async inviteInfo(instance: InstanceDto, inviteCode: GroupInvite) {
|
public async inviteInfo(instance: InstanceDto, inviteCode: GroupInvite) {
|
||||||
|
logger.verbose('requested inviteInfo from ' + instance.instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].inviteInfo(inviteCode);
|
return await this.waMonitor.waInstances[instance.instanceName].inviteInfo(inviteCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendInvite(instance: InstanceDto, data: GroupSendInvite) {
|
public async sendInvite(instance: InstanceDto, data: GroupSendInvite) {
|
||||||
|
logger.verbose('requested sendInvite from ' + instance.instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].sendInvite(data);
|
return await this.waMonitor.waInstances[instance.instanceName].sendInvite(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async revokeInviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
public async revokeInviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested revokeInviteCode from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].revokeInviteCode(
|
return await this.waMonitor.waInstances[instance.instanceName].revokeInviteCode(
|
||||||
groupJid,
|
groupJid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findParticipants(instance: InstanceDto, groupJid: GroupJid) {
|
public async findParticipants(instance: InstanceDto, groupJid: GroupJid) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested findParticipants from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].findParticipants(
|
return await this.waMonitor.waInstances[instance.instanceName].findParticipants(
|
||||||
groupJid,
|
groupJid,
|
||||||
);
|
);
|
||||||
@@ -77,22 +106,32 @@ export class GroupController {
|
|||||||
instance: InstanceDto,
|
instance: InstanceDto,
|
||||||
update: GroupUpdateParticipantDto,
|
update: GroupUpdateParticipantDto,
|
||||||
) {
|
) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested updateGParticipate from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].updateGParticipant(
|
return await this.waMonitor.waInstances[instance.instanceName].updateGParticipant(
|
||||||
update,
|
update,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateGSetting(instance: InstanceDto, update: GroupUpdateSettingDto) {
|
public async updateGSetting(instance: InstanceDto, update: GroupUpdateSettingDto) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested updateGSetting from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].updateGSetting(update);
|
return await this.waMonitor.waInstances[instance.instanceName].updateGSetting(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async toggleEphemeral(instance: InstanceDto, update: GroupToggleEphemeralDto) {
|
public async toggleEphemeral(instance: InstanceDto, update: GroupToggleEphemeralDto) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested toggleEphemeral from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].toggleEphemeral(
|
return await this.waMonitor.waInstances[instance.instanceName].toggleEphemeral(
|
||||||
update,
|
update,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async leaveGroup(instance: InstanceDto, groupJid: GroupJid) {
|
public async leaveGroup(instance: InstanceDto, groupJid: GroupJid) {
|
||||||
|
logger.verbose('requested leaveGroup from ' + instance.instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].leaveGroup(groupJid);
|
return await this.waMonitor.waInstances[instance.instanceName].leaveGroup(groupJid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { delay } from '@whiskeysockets/baileys';
|
import { delay } from '@whiskeysockets/baileys';
|
||||||
import EventEmitter2 from 'eventemitter2';
|
import EventEmitter2 from 'eventemitter2';
|
||||||
import { Auth, ConfigService } from '../../config/env.config';
|
import { Auth, ConfigService, HttpServer } from '../../config/env.config';
|
||||||
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
|
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { RepositoryBroker } from '../repository/repository.manager';
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
@@ -8,9 +8,12 @@ import { AuthService, OldToken } from '../services/auth.service';
|
|||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
import { WAStartupService } from '../services/whatsapp.service';
|
import { WAStartupService } from '../services/whatsapp.service';
|
||||||
import { WebhookService } from '../services/webhook.service';
|
import { WebhookService } from '../services/webhook.service';
|
||||||
|
import { ChatwootService } from '../services/chatwoot.service';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { wa } from '../types/wa.types';
|
import { wa } from '../types/wa.types';
|
||||||
import { RedisCache } from '../../db/redis.client';
|
import { RedisCache } from '../../db/redis.client';
|
||||||
|
import { isURL } from 'class-validator';
|
||||||
|
import { SettingsService } from '../services/settings.service';
|
||||||
|
|
||||||
export class InstanceController {
|
export class InstanceController {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -20,6 +23,8 @@ export class InstanceController {
|
|||||||
private readonly eventEmitter: EventEmitter2,
|
private readonly eventEmitter: EventEmitter2,
|
||||||
private readonly authService: AuthService,
|
private readonly authService: AuthService,
|
||||||
private readonly webhookService: WebhookService,
|
private readonly webhookService: WebhookService,
|
||||||
|
private readonly chatwootService: ChatwootService,
|
||||||
|
private readonly settingsService: SettingsService,
|
||||||
private readonly cache: RedisCache,
|
private readonly cache: RedisCache,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -31,30 +36,51 @@ export class InstanceController {
|
|||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
events,
|
events,
|
||||||
qrcode,
|
qrcode,
|
||||||
|
number,
|
||||||
token,
|
token,
|
||||||
|
chatwoot_account_id,
|
||||||
|
chatwoot_token,
|
||||||
|
chatwoot_url,
|
||||||
|
chatwoot_sign_msg,
|
||||||
|
chatwoot_reopen_conversation,
|
||||||
|
chatwoot_conversation_pending,
|
||||||
|
reject_call,
|
||||||
|
msg_call,
|
||||||
|
groups_ignore,
|
||||||
|
always_online,
|
||||||
|
read_messages,
|
||||||
|
read_status,
|
||||||
}: InstanceDto) {
|
}: InstanceDto) {
|
||||||
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
try {
|
||||||
|
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
|
||||||
|
|
||||||
if (mode === 'container') {
|
if (instanceName !== instanceName.toLowerCase().replace(/[^a-z0-9]/g, '')) {
|
||||||
if (Object.keys(this.waMonitor.waInstances).length > 0) {
|
throw new BadRequestException(
|
||||||
throw new BadRequestException([
|
'The instance name must be lowercase and without special characters',
|
||||||
'Instance already created',
|
);
|
||||||
'Only one instance can be created',
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('checking duplicate token');
|
||||||
await this.authService.checkDuplicateToken(token);
|
await this.authService.checkDuplicateToken(token);
|
||||||
|
|
||||||
|
this.logger.verbose('creating instance');
|
||||||
const instance = new WAStartupService(
|
const instance = new WAStartupService(
|
||||||
this.configService,
|
this.configService,
|
||||||
this.eventEmitter,
|
this.eventEmitter,
|
||||||
this.repository,
|
this.repository,
|
||||||
this.cache,
|
this.cache,
|
||||||
);
|
);
|
||||||
instance.instanceName = instanceName;
|
instance.instanceName = instanceName
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]/g, '')
|
||||||
|
.replace(' ', '');
|
||||||
|
|
||||||
|
this.logger.verbose('instance: ' + instance.instanceName + ' created');
|
||||||
|
|
||||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
this.waMonitor.waInstances[instance.instanceName] = instance;
|
||||||
this.waMonitor.delInstanceTime(instance.instanceName);
|
this.waMonitor.delInstanceTime(instance.instanceName);
|
||||||
|
|
||||||
|
this.logger.verbose('generating hash');
|
||||||
const hash = await this.authService.generateHash(
|
const hash = await this.authService.generateHash(
|
||||||
{
|
{
|
||||||
instanceName: instance.instanceName,
|
instanceName: instance.instanceName,
|
||||||
@@ -62,9 +88,16 @@ export class InstanceController {
|
|||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('hash: ' + hash + ' generated');
|
||||||
|
|
||||||
let getEvents: string[];
|
let getEvents: string[];
|
||||||
|
|
||||||
if (webhook) {
|
if (webhook) {
|
||||||
|
if (!isURL(webhook, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in webhook');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('creating webhook');
|
||||||
try {
|
try {
|
||||||
this.webhookService.create(instance, {
|
this.webhookService.create(instance, {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@@ -79,60 +112,109 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
this.logger.verbose('creating settings');
|
||||||
instance: {
|
const settings: wa.LocalSettings = {
|
||||||
instanceName: instance.instanceName,
|
reject_call: reject_call || false,
|
||||||
status: 'created',
|
msg_call: msg_call || '',
|
||||||
},
|
groups_ignore: groups_ignore || false,
|
||||||
hash,
|
always_online: always_online || false,
|
||||||
webhook,
|
read_messages: read_messages || false,
|
||||||
events: getEvents,
|
read_status: read_status || false,
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
await this.authService.checkDuplicateToken(token);
|
|
||||||
|
|
||||||
const instance = new WAStartupService(
|
this.logger.verbose('settings: ' + JSON.stringify(settings));
|
||||||
this.configService,
|
|
||||||
this.eventEmitter,
|
|
||||||
this.repository,
|
|
||||||
this.cache,
|
|
||||||
);
|
|
||||||
instance.instanceName = instanceName;
|
|
||||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
|
||||||
this.waMonitor.delInstanceTime(instance.instanceName);
|
|
||||||
|
|
||||||
const hash = await this.authService.generateHash(
|
this.settingsService.create(instance, settings);
|
||||||
{
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
},
|
|
||||||
token,
|
|
||||||
);
|
|
||||||
|
|
||||||
let getEvents: string[];
|
|
||||||
|
|
||||||
if (webhook) {
|
|
||||||
try {
|
|
||||||
this.webhookService.create(instance, {
|
|
||||||
enabled: true,
|
|
||||||
url: webhook,
|
|
||||||
events,
|
|
||||||
webhook_by_events,
|
|
||||||
});
|
|
||||||
|
|
||||||
getEvents = (await this.webhookService.find(instance)).events;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
||||||
let getQrcode: wa.QrCode;
|
let getQrcode: wa.QrCode;
|
||||||
|
|
||||||
if (qrcode) {
|
if (qrcode) {
|
||||||
await instance.connectToWhatsapp();
|
this.logger.verbose('creating qrcode');
|
||||||
await delay(2000);
|
await instance.connectToWhatsapp(number);
|
||||||
|
await delay(5000);
|
||||||
getQrcode = instance.qrCode;
|
getQrcode = instance.qrCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
instance: {
|
||||||
|
instanceName: instance.instanceName,
|
||||||
|
status: 'created',
|
||||||
|
},
|
||||||
|
hash,
|
||||||
|
webhook,
|
||||||
|
webhook_by_events,
|
||||||
|
events: getEvents,
|
||||||
|
settings,
|
||||||
|
qrcode: getQrcode,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.logger.verbose('instance created');
|
||||||
|
this.logger.verbose(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chatwoot_account_id) {
|
||||||
|
throw new BadRequestException('account_id is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chatwoot_token) {
|
||||||
|
throw new BadRequestException('token is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chatwoot_url) {
|
||||||
|
throw new BadRequestException('url is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isURL(chatwoot_url, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in chatwoot');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chatwoot_sign_msg !== true && chatwoot_sign_msg !== false) {
|
||||||
|
throw new BadRequestException('sign_msg is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
chatwoot_reopen_conversation !== true &&
|
||||||
|
chatwoot_reopen_conversation !== false
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('reopen_conversation is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
chatwoot_conversation_pending !== true &&
|
||||||
|
chatwoot_conversation_pending !== false
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('conversation_pending is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.chatwootService.create(instance, {
|
||||||
|
enabled: true,
|
||||||
|
account_id: chatwoot_account_id,
|
||||||
|
token: chatwoot_token,
|
||||||
|
url: chatwoot_url,
|
||||||
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
|
name_inbox: instance.instanceName,
|
||||||
|
number,
|
||||||
|
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||||
|
conversation_pending: chatwoot_conversation_pending || false,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.chatwootService.initInstanceChatwoot(
|
||||||
|
instance,
|
||||||
|
instance.instanceName,
|
||||||
|
`${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||||
|
qrcode,
|
||||||
|
number,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.log(error);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
instance: {
|
instance: {
|
||||||
instanceName: instance.instanceName,
|
instanceName: instance.instanceName,
|
||||||
@@ -142,26 +224,60 @@ export class InstanceController {
|
|||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
events: getEvents,
|
events: getEvents,
|
||||||
qrcode: getQrcode,
|
settings,
|
||||||
|
chatwoot: {
|
||||||
|
enabled: true,
|
||||||
|
account_id: chatwoot_account_id,
|
||||||
|
token: chatwoot_token,
|
||||||
|
url: chatwoot_url,
|
||||||
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
|
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||||
|
conversation_pending: chatwoot_conversation_pending || false,
|
||||||
|
number,
|
||||||
|
name_inbox: instance.instanceName,
|
||||||
|
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return { error: true, message: error.toString() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async connectToWhatsapp({ instanceName }: InstanceDto) {
|
public async connectToWhatsapp({ instanceName, number = null }: InstanceDto) {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose(
|
||||||
|
'requested connectToWhatsapp from ' + instanceName + ' instance',
|
||||||
|
);
|
||||||
|
|
||||||
const instance = this.waMonitor.waInstances[instanceName];
|
const instance = this.waMonitor.waInstances[instanceName];
|
||||||
const state = instance?.connectionStatus?.state;
|
const state = instance?.connectionStatus?.state;
|
||||||
|
|
||||||
switch (state) {
|
this.logger.verbose('state: ' + state);
|
||||||
case 'close':
|
|
||||||
await instance.connectToWhatsapp();
|
if (state == 'open') {
|
||||||
await delay(2000);
|
|
||||||
return instance.qrCode;
|
|
||||||
case 'connecting':
|
|
||||||
return instance.qrCode;
|
|
||||||
default:
|
|
||||||
return await this.connectionState({ instanceName });
|
return await this.connectionState({ instanceName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state == 'connecting') {
|
||||||
|
return instance.qrCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == 'close') {
|
||||||
|
this.logger.verbose('connecting');
|
||||||
|
await instance.connectToWhatsapp(number);
|
||||||
|
|
||||||
|
await delay(5000);
|
||||||
|
return instance.qrCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
instance: {
|
||||||
|
instanceName: instanceName,
|
||||||
|
status: state,
|
||||||
|
},
|
||||||
|
qrcode: instance?.qrCode,
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
@@ -169,18 +285,10 @@ export class InstanceController {
|
|||||||
|
|
||||||
public async restartInstance({ instanceName }: InstanceDto) {
|
public async restartInstance({ instanceName }: InstanceDto) {
|
||||||
try {
|
try {
|
||||||
delete this.waMonitor.waInstances[instanceName];
|
this.logger.verbose('requested restartInstance from ' + instanceName + ' instance');
|
||||||
console.log(this.waMonitor.waInstances[instanceName]);
|
|
||||||
const instance = new WAStartupService(
|
|
||||||
this.configService,
|
|
||||||
this.eventEmitter,
|
|
||||||
this.repository,
|
|
||||||
this.cache,
|
|
||||||
);
|
|
||||||
|
|
||||||
instance.instanceName = instanceName;
|
this.logger.verbose('logging out instance: ' + instanceName);
|
||||||
await instance.connectToWhatsapp();
|
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
||||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
|
||||||
|
|
||||||
return { error: false, message: 'Instance restarted' };
|
return { error: false, message: 'Instance restarted' };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -189,11 +297,19 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async connectionState({ instanceName }: InstanceDto) {
|
public async connectionState({ instanceName }: InstanceDto) {
|
||||||
return this.waMonitor.waInstances[instanceName]?.connectionStatus;
|
this.logger.verbose('requested connectionState from ' + instanceName + ' instance');
|
||||||
|
return {
|
||||||
|
instance: {
|
||||||
|
instanceName: instanceName,
|
||||||
|
state: this.waMonitor.waInstances[instanceName]?.connectionStatus?.state,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchInstances({ instanceName }: InstanceDto) {
|
public async fetchInstances({ instanceName }: InstanceDto) {
|
||||||
|
this.logger.verbose('requested fetchInstances from ' + instanceName + ' instance');
|
||||||
if (instanceName) {
|
if (instanceName) {
|
||||||
|
this.logger.verbose('instanceName: ' + instanceName);
|
||||||
return this.waMonitor.instanceInfo(instanceName);
|
return this.waMonitor.instanceInfo(instanceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,11 +317,22 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async logout({ instanceName }: InstanceDto) {
|
public async logout({ instanceName }: InstanceDto) {
|
||||||
|
this.logger.verbose('requested logout from ' + instanceName + ' instance');
|
||||||
|
const { instance } = await this.connectionState({ instanceName });
|
||||||
|
|
||||||
|
if (instance.state === 'close') {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'The "' + instanceName + '" instance is not connected',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('logging out instance: ' + instanceName);
|
||||||
await this.waMonitor.waInstances[instanceName]?.client?.logout(
|
await this.waMonitor.waInstances[instanceName]?.client?.logout(
|
||||||
'Log out instance: ' + instanceName,
|
'Log out instance: ' + instanceName,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('close connection instance: ' + instanceName);
|
||||||
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
||||||
|
|
||||||
return { error: false, message: 'Instance logged out' };
|
return { error: false, message: 'Instance logged out' };
|
||||||
@@ -215,19 +342,24 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async deleteInstance({ instanceName }: InstanceDto) {
|
public async deleteInstance({ instanceName }: InstanceDto) {
|
||||||
const stateConn = await this.connectionState({ instanceName });
|
this.logger.verbose('requested deleteInstance from ' + instanceName + ' instance');
|
||||||
if (stateConn.state === 'open') {
|
const { instance } = await this.connectionState({ instanceName });
|
||||||
throw new BadRequestException([
|
|
||||||
'Deletion failed',
|
if (instance.state === 'open') {
|
||||||
'The instance needs to be disconnected',
|
throw new BadRequestException(
|
||||||
]);
|
'The "' + instanceName + '" instance needs to be disconnected',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (stateConn.state === 'connecting') {
|
if (instance.state === 'connecting') {
|
||||||
|
this.logger.verbose('logging out instance: ' + instanceName);
|
||||||
|
|
||||||
await this.logout({ instanceName });
|
await this.logout({ instanceName });
|
||||||
delete this.waMonitor.waInstances[instanceName];
|
delete this.waMonitor.waInstances[instanceName];
|
||||||
return { error: false, message: 'Instance deleted' };
|
return { error: false, message: 'Instance deleted' };
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.verbose('deleting instance: ' + instanceName);
|
||||||
|
|
||||||
delete this.waMonitor.waInstances[instanceName];
|
delete this.waMonitor.waInstances[instanceName];
|
||||||
this.eventEmitter.emit('remove.instance', instanceName, 'inner');
|
this.eventEmitter.emit('remove.instance', instanceName, 'inner');
|
||||||
return { error: false, message: 'Instance deleted' };
|
return { error: false, message: 'Instance deleted' };
|
||||||
@@ -238,6 +370,7 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async refreshToken(_: InstanceDto, oldToken: OldToken) {
|
public async refreshToken(_: InstanceDto, oldToken: OldToken) {
|
||||||
|
this.logger.verbose('requested refreshToken');
|
||||||
return await this.authService.refreshToken(oldToken);
|
return await this.authService.refreshToken(oldToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,28 +5,46 @@ import {
|
|||||||
SendAudioDto,
|
SendAudioDto,
|
||||||
SendButtonDto,
|
SendButtonDto,
|
||||||
SendContactDto,
|
SendContactDto,
|
||||||
SendLinkPreviewDto,
|
|
||||||
SendListDto,
|
SendListDto,
|
||||||
SendLocationDto,
|
SendLocationDto,
|
||||||
SendMediaDto,
|
SendMediaDto,
|
||||||
SendPollDto,
|
SendPollDto,
|
||||||
SendReactionDto,
|
SendReactionDto,
|
||||||
|
SendStatusDto,
|
||||||
SendStickerDto,
|
SendStickerDto,
|
||||||
SendTextDto,
|
SendTextDto,
|
||||||
} from '../dto/sendMessage.dto';
|
} from '../dto/sendMessage.dto';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
|
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('MessageRouter');
|
||||||
|
|
||||||
export class SendMessageController {
|
export class SendMessageController {
|
||||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||||
|
|
||||||
public async sendText({ instanceName }: InstanceDto, data: SendTextDto) {
|
public async sendText({ instanceName }: InstanceDto, data: SendTextDto) {
|
||||||
|
logger.verbose('requested sendText from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].textMessage(data);
|
return await this.waMonitor.waInstances[instanceName].textMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendMedia({ instanceName }: InstanceDto, data: SendMediaDto) {
|
public async sendMedia({ instanceName }: InstanceDto, data: SendMediaDto) {
|
||||||
if (isBase64(data?.mediaMessage?.media) && !data?.mediaMessage?.fileName) {
|
logger.verbose('requested sendMedia from ' + instanceName + ' instance');
|
||||||
throw new BadRequestException('For bse64 the file name must be informed.');
|
|
||||||
|
if (
|
||||||
|
isBase64(data?.mediaMessage?.media) &&
|
||||||
|
!data?.mediaMessage?.fileName &&
|
||||||
|
data?.mediaMessage?.mediatype === 'document'
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('For base64 the file name must be informed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.verbose(
|
||||||
|
'isURL: ' +
|
||||||
|
isURL(data?.mediaMessage?.media) +
|
||||||
|
', isBase64: ' +
|
||||||
|
isBase64(data?.mediaMessage?.media),
|
||||||
|
);
|
||||||
if (isURL(data?.mediaMessage?.media) || isBase64(data?.mediaMessage?.media)) {
|
if (isURL(data?.mediaMessage?.media) || isBase64(data?.mediaMessage?.media)) {
|
||||||
return await this.waMonitor.waInstances[instanceName].mediaMessage(data);
|
return await this.waMonitor.waInstances[instanceName].mediaMessage(data);
|
||||||
}
|
}
|
||||||
@@ -34,6 +52,14 @@ export class SendMessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async sendSticker({ instanceName }: InstanceDto, data: SendStickerDto) {
|
public async sendSticker({ instanceName }: InstanceDto, data: SendStickerDto) {
|
||||||
|
logger.verbose('requested sendSticker from ' + instanceName + ' instance');
|
||||||
|
|
||||||
|
logger.verbose(
|
||||||
|
'isURL: ' +
|
||||||
|
isURL(data?.stickerMessage?.image) +
|
||||||
|
', isBase64: ' +
|
||||||
|
isBase64(data?.stickerMessage?.image),
|
||||||
|
);
|
||||||
if (isURL(data.stickerMessage.image) || isBase64(data.stickerMessage.image)) {
|
if (isURL(data.stickerMessage.image) || isBase64(data.stickerMessage.image)) {
|
||||||
return await this.waMonitor.waInstances[instanceName].mediaSticker(data);
|
return await this.waMonitor.waInstances[instanceName].mediaSticker(data);
|
||||||
}
|
}
|
||||||
@@ -41,6 +67,14 @@ export class SendMessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async sendWhatsAppAudio({ instanceName }: InstanceDto, data: SendAudioDto) {
|
public async sendWhatsAppAudio({ instanceName }: InstanceDto, data: SendAudioDto) {
|
||||||
|
logger.verbose('requested sendWhatsAppAudio from ' + instanceName + ' instance');
|
||||||
|
|
||||||
|
logger.verbose(
|
||||||
|
'isURL: ' +
|
||||||
|
isURL(data?.audioMessage?.audio) +
|
||||||
|
', isBase64: ' +
|
||||||
|
isBase64(data?.audioMessage?.audio),
|
||||||
|
);
|
||||||
if (isURL(data.audioMessage.audio) || isBase64(data.audioMessage.audio)) {
|
if (isURL(data.audioMessage.audio) || isBase64(data.audioMessage.audio)) {
|
||||||
return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data);
|
return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data);
|
||||||
}
|
}
|
||||||
@@ -48,6 +82,7 @@ export class SendMessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async sendButtons({ instanceName }: InstanceDto, data: SendButtonDto) {
|
public async sendButtons({ instanceName }: InstanceDto, data: SendButtonDto) {
|
||||||
|
logger.verbose('requested sendButtons from ' + instanceName + ' instance');
|
||||||
if (
|
if (
|
||||||
isBase64(data.buttonMessage.mediaMessage?.media) &&
|
isBase64(data.buttonMessage.mediaMessage?.media) &&
|
||||||
!data.buttonMessage.mediaMessage?.fileName
|
!data.buttonMessage.mediaMessage?.fileName
|
||||||
@@ -58,18 +93,22 @@ export class SendMessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async sendLocation({ instanceName }: InstanceDto, data: SendLocationDto) {
|
public async sendLocation({ instanceName }: InstanceDto, data: SendLocationDto) {
|
||||||
|
logger.verbose('requested sendLocation from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].locationMessage(data);
|
return await this.waMonitor.waInstances[instanceName].locationMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendList({ instanceName }: InstanceDto, data: SendListDto) {
|
public async sendList({ instanceName }: InstanceDto, data: SendListDto) {
|
||||||
|
logger.verbose('requested sendList from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].listMessage(data);
|
return await this.waMonitor.waInstances[instanceName].listMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendContact({ instanceName }: InstanceDto, data: SendContactDto) {
|
public async sendContact({ instanceName }: InstanceDto, data: SendContactDto) {
|
||||||
|
logger.verbose('requested sendContact from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].contactMessage(data);
|
return await this.waMonitor.waInstances[instanceName].contactMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendReaction({ instanceName }: InstanceDto, data: SendReactionDto) {
|
public async sendReaction({ instanceName }: InstanceDto, data: SendReactionDto) {
|
||||||
|
logger.verbose('requested sendReaction from ' + instanceName + ' instance');
|
||||||
if (!data.reactionMessage.reaction.match(/[^\(\)\w\sà-ú"-\+]+/)) {
|
if (!data.reactionMessage.reaction.match(/[^\(\)\w\sà-ú"-\+]+/)) {
|
||||||
throw new BadRequestException('"reaction" must be an emoji');
|
throw new BadRequestException('"reaction" must be an emoji');
|
||||||
}
|
}
|
||||||
@@ -77,10 +116,12 @@ export class SendMessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async sendPoll({ instanceName }: InstanceDto, data: SendPollDto) {
|
public async sendPoll({ instanceName }: InstanceDto, data: SendPollDto) {
|
||||||
|
logger.verbose('requested sendPoll from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].pollMessage(data);
|
return await this.waMonitor.waInstances[instanceName].pollMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendLinkPreview({ instanceName }: InstanceDto, data: SendLinkPreviewDto) {
|
public async sendStatus({ instanceName }: InstanceDto, data: SendStatusDto) {
|
||||||
return await this.waMonitor.waInstances[instanceName].linkPreview(data);
|
logger.verbose('requested sendStatus from ' + instanceName + ' instance');
|
||||||
|
return await this.waMonitor.waInstances[instanceName].statusMessage(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/whatsapp/controllers/settings.controller.ts
Normal file
25
src/whatsapp/controllers/settings.controller.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { isURL } from 'class-validator';
|
||||||
|
import { BadRequestException } from '../../exceptions';
|
||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { SettingsDto } from '../dto/settings.dto';
|
||||||
|
import { SettingsService } from '../services/settings.service';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('SettingsController');
|
||||||
|
|
||||||
|
export class SettingsController {
|
||||||
|
constructor(private readonly settingsService: SettingsService) {}
|
||||||
|
|
||||||
|
public async createSettings(instance: InstanceDto, data: SettingsDto) {
|
||||||
|
logger.verbose(
|
||||||
|
'requested createSettings from ' + instance.instanceName + ' instance',
|
||||||
|
);
|
||||||
|
|
||||||
|
return this.settingsService.create(instance, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async findSettings(instance: InstanceDto) {
|
||||||
|
logger.verbose('requested findSettings from ' + instance.instanceName + ' instance');
|
||||||
|
return this.settingsService.find(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,18 +3,31 @@ import { BadRequestException } from '../../exceptions';
|
|||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { WebhookDto } from '../dto/webhook.dto';
|
import { WebhookDto } from '../dto/webhook.dto';
|
||||||
import { WebhookService } from '../services/webhook.service';
|
import { WebhookService } from '../services/webhook.service';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('WebhookController');
|
||||||
|
|
||||||
export class WebhookController {
|
export class WebhookController {
|
||||||
constructor(private readonly webhookService: WebhookService) {}
|
constructor(private readonly webhookService: WebhookService) {}
|
||||||
|
|
||||||
public async createWebhook(instance: InstanceDto, data: WebhookDto) {
|
public async createWebhook(instance: InstanceDto, data: WebhookDto) {
|
||||||
if (!isURL(data.url, { require_tld: false })) {
|
logger.verbose('requested createWebhook from ' + instance.instanceName + ' instance');
|
||||||
|
|
||||||
|
if (data.enabled && !isURL(data.url, { require_tld: false })) {
|
||||||
throw new BadRequestException('Invalid "url" property');
|
throw new BadRequestException('Invalid "url" property');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!data.enabled) {
|
||||||
|
logger.verbose('webhook disabled');
|
||||||
|
data.url = '';
|
||||||
|
data.events = [];
|
||||||
|
}
|
||||||
|
|
||||||
return this.webhookService.create(instance, data);
|
return this.webhookService.create(instance, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findWebhook(instance: InstanceDto) {
|
public async findWebhook(instance: InstanceDto) {
|
||||||
|
logger.verbose('requested findWebhook from ' + instance.instanceName + ' instance');
|
||||||
return this.webhookService.find(instance);
|
return this.webhookService.find(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,19 @@ export class NumberDto {
|
|||||||
number: string;
|
number: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class NumberBusiness {
|
||||||
|
wid?: string;
|
||||||
|
jid?: string;
|
||||||
|
exists?: boolean;
|
||||||
|
isBusiness: boolean;
|
||||||
|
name?: string;
|
||||||
|
message?: string;
|
||||||
|
description?: string;
|
||||||
|
email?: string;
|
||||||
|
website?: string[];
|
||||||
|
address?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class ProfileNameDto {
|
export class ProfileNameDto {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
@@ -46,7 +59,7 @@ class Key {
|
|||||||
remoteJid: string;
|
remoteJid: string;
|
||||||
}
|
}
|
||||||
export class ReadMessageDto {
|
export class ReadMessageDto {
|
||||||
readMessages: Key[];
|
read_messages: Key[];
|
||||||
}
|
}
|
||||||
|
|
||||||
class LastMessage {
|
class LastMessage {
|
||||||
|
|||||||
11
src/whatsapp/dto/chatwoot.dto.ts
Normal file
11
src/whatsapp/dto/chatwoot.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export class ChatwootDto {
|
||||||
|
enabled?: boolean;
|
||||||
|
account_id?: string;
|
||||||
|
token?: string;
|
||||||
|
url?: string;
|
||||||
|
name_inbox?: string;
|
||||||
|
sign_msg?: boolean;
|
||||||
|
number?: string;
|
||||||
|
reopen_conversation?: boolean;
|
||||||
|
conversation_pending?: boolean;
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
export class CreateGroupDto {
|
export class CreateGroupDto {
|
||||||
subject: string;
|
subject: string;
|
||||||
description?: string;
|
|
||||||
participants: string[];
|
participants: string[];
|
||||||
|
description?: string;
|
||||||
|
promoteParticipants?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GroupPictureDto {
|
export class GroupPictureDto {
|
||||||
@@ -23,6 +24,10 @@ export class GroupJid {
|
|||||||
groupJid: string;
|
groupJid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class GetParticipant {
|
||||||
|
getParticipants: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class GroupInvite {
|
export class GroupInvite {
|
||||||
inviteCode: string;
|
inviteCode: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,21 @@
|
|||||||
export class InstanceDto {
|
export class InstanceDto {
|
||||||
instanceName: string;
|
instanceName: string;
|
||||||
|
qrcode?: boolean;
|
||||||
|
number?: string;
|
||||||
|
token?: string;
|
||||||
webhook?: string;
|
webhook?: string;
|
||||||
webhook_by_events?: boolean;
|
webhook_by_events?: boolean;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
qrcode?: boolean;
|
reject_call?: boolean;
|
||||||
token?: string;
|
msg_call?: string;
|
||||||
|
groups_ignore?: boolean;
|
||||||
|
always_online?: boolean;
|
||||||
|
read_messages?: boolean;
|
||||||
|
read_status?: boolean;
|
||||||
|
chatwoot_account_id?: string;
|
||||||
|
chatwoot_token?: string;
|
||||||
|
chatwoot_url?: string;
|
||||||
|
chatwoot_sign_msg?: boolean;
|
||||||
|
chatwoot_reopen_conversation?: boolean;
|
||||||
|
chatwoot_conversation_pending?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ export class Options {
|
|||||||
presence?: WAPresence;
|
presence?: WAPresence;
|
||||||
quoted?: Quoted;
|
quoted?: Quoted;
|
||||||
mentions?: Mentions;
|
mentions?: Mentions;
|
||||||
|
linkPreview?: boolean;
|
||||||
|
encoding?: boolean;
|
||||||
}
|
}
|
||||||
class OptionsMessage {
|
class OptionsMessage {
|
||||||
options: Options;
|
options: Options;
|
||||||
@@ -28,8 +30,14 @@ class TextMessage {
|
|||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class linkPreviewMessage {
|
export class StatusMessage {
|
||||||
text: string;
|
type: string;
|
||||||
|
content: string;
|
||||||
|
statusJidList?: string[];
|
||||||
|
allContacts?: boolean;
|
||||||
|
caption?: string;
|
||||||
|
backgroundColor?: string;
|
||||||
|
font?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PollMessage {
|
class PollMessage {
|
||||||
@@ -42,8 +50,8 @@ export class SendTextDto extends Metadata {
|
|||||||
textMessage: TextMessage;
|
textMessage: TextMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SendLinkPreviewDto extends Metadata {
|
export class SendStatusDto extends Metadata {
|
||||||
linkPreview: linkPreviewMessage;
|
statusMessage: StatusMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SendPollDto extends Metadata {
|
export class SendPollDto extends Metadata {
|
||||||
|
|||||||
8
src/whatsapp/dto/settings.dto.ts
Normal file
8
src/whatsapp/dto/settings.dto.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export class SettingsDto {
|
||||||
|
reject_call?: boolean;
|
||||||
|
msg_call?: string;
|
||||||
|
groups_ignore?: boolean;
|
||||||
|
always_online?: boolean;
|
||||||
|
read_messages?: boolean;
|
||||||
|
read_status?: boolean;
|
||||||
|
}
|
||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { cache, waMonitor } from '../whatsapp.module';
|
import { cache, waMonitor } from '../whatsapp.module';
|
||||||
import { Database, Redis, configService } from '../../config/env.config';
|
import { Database, Redis, configService } from '../../config/env.config';
|
||||||
import { RedisCache } from '../../db/redis.client';
|
|
||||||
|
|
||||||
async function getInstance(instanceName: string) {
|
async function getInstance(instanceName: string) {
|
||||||
const db = configService.get<Database>('DATABASE');
|
const db = configService.get<Database>('DATABASE');
|
||||||
|
|||||||
33
src/whatsapp/models/chatwoot.model.ts
Normal file
33
src/whatsapp/models/chatwoot.model.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { Schema } from 'mongoose';
|
||||||
|
import { dbserver } from '../../db/db.connect';
|
||||||
|
|
||||||
|
export class ChatwootRaw {
|
||||||
|
_id?: string;
|
||||||
|
enabled?: boolean;
|
||||||
|
account_id?: string;
|
||||||
|
token?: string;
|
||||||
|
url?: string;
|
||||||
|
name_inbox?: string;
|
||||||
|
sign_msg?: boolean;
|
||||||
|
number?: string;
|
||||||
|
reopen_conversation?: boolean;
|
||||||
|
conversation_pending?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const chatwootSchema = new Schema<ChatwootRaw>({
|
||||||
|
_id: { type: String, _id: true },
|
||||||
|
enabled: { type: Boolean, required: true },
|
||||||
|
account_id: { type: String, required: true },
|
||||||
|
token: { type: String, required: true },
|
||||||
|
url: { type: String, required: true },
|
||||||
|
name_inbox: { type: String, required: true },
|
||||||
|
sign_msg: { type: Boolean, required: true },
|
||||||
|
number: { type: String, required: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
export const ChatwootModel = dbserver?.model(
|
||||||
|
ChatwootRaw.name,
|
||||||
|
chatwootSchema,
|
||||||
|
'chatwoot',
|
||||||
|
);
|
||||||
|
export type IChatwootModel = typeof ChatwootModel;
|
||||||
@@ -3,3 +3,5 @@ export * from './contact.model';
|
|||||||
export * from './message.model';
|
export * from './message.model';
|
||||||
export * from './auth.model';
|
export * from './auth.model';
|
||||||
export * from './webhook.model';
|
export * from './webhook.model';
|
||||||
|
export * from './chatwoot.model';
|
||||||
|
export * from './settings.model';
|
||||||
|
|||||||
29
src/whatsapp/models/settings.model.ts
Normal file
29
src/whatsapp/models/settings.model.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { Schema } from 'mongoose';
|
||||||
|
import { dbserver } from '../../db/db.connect';
|
||||||
|
|
||||||
|
export class SettingsRaw {
|
||||||
|
_id?: string;
|
||||||
|
reject_call?: boolean;
|
||||||
|
msg_call?: string;
|
||||||
|
groups_ignore?: boolean;
|
||||||
|
always_online?: boolean;
|
||||||
|
read_messages?: boolean;
|
||||||
|
read_status?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settingsSchema = new Schema<SettingsRaw>({
|
||||||
|
_id: { type: String, _id: true },
|
||||||
|
reject_call: { type: Boolean, required: true },
|
||||||
|
msg_call: { type: String, required: true },
|
||||||
|
groups_ignore: { type: Boolean, required: true },
|
||||||
|
always_online: { type: Boolean, required: true },
|
||||||
|
read_messages: { type: Boolean, required: true },
|
||||||
|
read_status: { type: Boolean, required: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
export const SettingsModel = dbserver?.model(
|
||||||
|
SettingsRaw.name,
|
||||||
|
settingsSchema,
|
||||||
|
'settings',
|
||||||
|
);
|
||||||
|
export type ISettingsModel = typeof SettingsModel;
|
||||||
@@ -14,6 +14,7 @@ const webhookSchema = new Schema<WebhookRaw>({
|
|||||||
url: { type: String, required: true },
|
url: { type: String, required: true },
|
||||||
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 },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const WebhookModel = dbserver?.model(WebhookRaw.name, webhookSchema, 'webhook');
|
export const WebhookModel = dbserver?.model(WebhookRaw.name, webhookSchema, 'webhook');
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Auth, ConfigService } from '../../config/env.config';
|
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
import { IAuthModel, AuthRaw } from '../models';
|
import { IAuthModel, AuthRaw } from '../models';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { AUTH_DIR } from '../../config/path.config';
|
import { AUTH_DIR } from '../../config/path.config';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
export class AuthRepository extends Repository {
|
export class AuthRepository extends Repository {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -16,24 +16,35 @@ export class AuthRepository extends Repository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly auth: Auth;
|
private readonly auth: Auth;
|
||||||
|
private readonly logger = new Logger('AuthRepository');
|
||||||
|
|
||||||
public async create(data: AuthRaw, instance: string): Promise<IInsert> {
|
public async create(data: AuthRaw, instance: string): Promise<IInsert> {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('creating auth');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('saving auth to db');
|
||||||
const insert = await this.authModel.replaceOne(
|
const insert = await this.authModel.replaceOne(
|
||||||
{ _id: instance },
|
{ _id: instance },
|
||||||
{ ...data },
|
{ ...data },
|
||||||
{ upsert: true },
|
{ upsert: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('auth saved to db: ' + insert.modifiedCount + ' auth');
|
||||||
return { insertCount: insert.modifiedCount };
|
return { insertCount: insert.modifiedCount };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving auth to store');
|
||||||
|
|
||||||
this.writeStore<AuthRaw>({
|
this.writeStore<AuthRaw>({
|
||||||
path: join(AUTH_DIR, this.auth.TYPE),
|
path: join(AUTH_DIR, this.auth.TYPE),
|
||||||
fileName: instance,
|
fileName: instance,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
this.logger.verbose(
|
||||||
|
'auth saved to store in path: ' + join(AUTH_DIR, this.auth.TYPE) + '/' + instance,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('auth created');
|
||||||
return { insertCount: 1 };
|
return { insertCount: 1 };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { error } as any;
|
return { error } as any;
|
||||||
@@ -42,10 +53,14 @@ export class AuthRepository extends Repository {
|
|||||||
|
|
||||||
public async find(instance: string): Promise<AuthRaw> {
|
public async find(instance: string): Promise<AuthRaw> {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('finding auth');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding auth in db');
|
||||||
return await this.authModel.findOne({ _id: instance });
|
return await this.authModel.findOne({ _id: instance });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding auth in store');
|
||||||
|
|
||||||
return JSON.parse(
|
return JSON.parse(
|
||||||
readFileSync(join(AUTH_DIR, this.auth.TYPE, instance + '.json'), {
|
readFileSync(join(AUTH_DIR, this.auth.TYPE, instance + '.json'), {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { ConfigService, StoreConf } from '../../config/env.config';
|
|||||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
import { opendirSync, readFileSync, rmSync } from 'fs';
|
import { opendirSync, readFileSync, rmSync } from 'fs';
|
||||||
import { ChatRaw, IChatModel } from '../models';
|
import { ChatRaw, IChatModel } from '../models';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
export class ChatQuery {
|
export class ChatQuery {
|
||||||
where: ChatRaw;
|
where: ChatRaw;
|
||||||
@@ -16,31 +17,54 @@ export class ChatRepository extends Repository {
|
|||||||
super(configService);
|
super(configService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async insert(data: ChatRaw[], saveDb = false): Promise<IInsert> {
|
private readonly logger = new Logger('ChatRepository');
|
||||||
|
|
||||||
|
public async insert(
|
||||||
|
data: ChatRaw[],
|
||||||
|
instanceName: string,
|
||||||
|
saveDb = false,
|
||||||
|
): Promise<IInsert> {
|
||||||
|
this.logger.verbose('inserting chats');
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
this.logger.verbose('no chats to insert');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('saving chats to store');
|
||||||
if (this.dbSettings.ENABLED && saveDb) {
|
if (this.dbSettings.ENABLED && saveDb) {
|
||||||
|
this.logger.verbose('saving chats to db');
|
||||||
const insert = await this.chatModel.insertMany([...data]);
|
const insert = await this.chatModel.insertMany([...data]);
|
||||||
|
|
||||||
|
this.logger.verbose('chats saved to db: ' + insert.length + ' chats');
|
||||||
return { insertCount: insert.length };
|
return { insertCount: insert.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving chats to store');
|
||||||
|
|
||||||
const store = this.configService.get<StoreConf>('STORE');
|
const store = this.configService.get<StoreConf>('STORE');
|
||||||
|
|
||||||
if (store.CHATS) {
|
if (store.CHATS) {
|
||||||
|
this.logger.verbose('saving chats to store');
|
||||||
data.forEach((chat) => {
|
data.forEach((chat) => {
|
||||||
this.writeStore<ChatRaw>({
|
this.writeStore<ChatRaw>({
|
||||||
path: join(this.storePath, 'chats', chat.owner),
|
path: join(this.storePath, 'chats', instanceName),
|
||||||
fileName: chat.id,
|
fileName: chat.id,
|
||||||
data: chat,
|
data: chat,
|
||||||
});
|
});
|
||||||
|
this.logger.verbose(
|
||||||
|
'chats saved to store in path: ' +
|
||||||
|
join(this.storePath, 'chats', instanceName) +
|
||||||
|
'/' +
|
||||||
|
chat.id,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logger.verbose('chats saved to store');
|
||||||
return { insertCount: data.length };
|
return { insertCount: data.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('chats not saved to store');
|
||||||
return { insertCount: 0 };
|
return { insertCount: 0 };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
@@ -51,10 +75,14 @@ export class ChatRepository extends Repository {
|
|||||||
|
|
||||||
public async find(query: ChatQuery): Promise<ChatRaw[]> {
|
public async find(query: ChatQuery): Promise<ChatRaw[]> {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('finding chats');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding chats in db');
|
||||||
return await this.chatModel.find({ owner: query.where.owner });
|
return await this.chatModel.find({ owner: query.where.owner });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding chats in store');
|
||||||
|
|
||||||
const chats: ChatRaw[] = [];
|
const chats: ChatRaw[] = [];
|
||||||
const openDir = opendirSync(join(this.storePath, 'chats', query.where.owner));
|
const openDir = opendirSync(join(this.storePath, 'chats', query.where.owner));
|
||||||
for await (const dirent of openDir) {
|
for await (const dirent of openDir) {
|
||||||
@@ -70,6 +98,7 @@ export class ChatRepository extends Repository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('chats found in store: ' + chats.length + ' chats');
|
||||||
return chats;
|
return chats;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return [];
|
return [];
|
||||||
@@ -78,10 +107,13 @@ export class ChatRepository extends Repository {
|
|||||||
|
|
||||||
public async delete(query: ChatQuery) {
|
public async delete(query: ChatQuery) {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('deleting chats');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('deleting chats in db');
|
||||||
return await this.chatModel.deleteOne({ ...query.where });
|
return await this.chatModel.deleteOne({ ...query.where });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('deleting chats in store');
|
||||||
rmSync(join(this.storePath, 'chats', query.where.owner, query.where.id + '.josn'), {
|
rmSync(join(this.storePath, 'chats', query.where.owner, query.where.id + '.josn'), {
|
||||||
force: true,
|
force: true,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
|
|||||||
75
src/whatsapp/repository/chatwoot.repository.ts
Normal file
75
src/whatsapp/repository/chatwoot.repository.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
|
import { ConfigService } from '../../config/env.config';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { IChatwootModel, ChatwootRaw } from '../models';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
export class ChatwootRepository extends Repository {
|
||||||
|
constructor(
|
||||||
|
private readonly chatwootModel: IChatwootModel,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
) {
|
||||||
|
super(configService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly logger = new Logger('ChatwootRepository');
|
||||||
|
|
||||||
|
public async create(data: ChatwootRaw, instance: string): Promise<IInsert> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('creating chatwoot');
|
||||||
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('saving chatwoot to db');
|
||||||
|
const insert = await this.chatwootModel.replaceOne(
|
||||||
|
{ _id: instance },
|
||||||
|
{ ...data },
|
||||||
|
{ upsert: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.verbose(
|
||||||
|
'chatwoot saved to db: ' + insert.modifiedCount + ' chatwoot',
|
||||||
|
);
|
||||||
|
return { insertCount: insert.modifiedCount };
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving chatwoot to store');
|
||||||
|
|
||||||
|
this.writeStore<ChatwootRaw>({
|
||||||
|
path: join(this.storePath, 'chatwoot'),
|
||||||
|
fileName: instance,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.verbose(
|
||||||
|
'chatwoot saved to store in path: ' +
|
||||||
|
join(this.storePath, 'chatwoot') +
|
||||||
|
'/' +
|
||||||
|
instance,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('chatwoot created');
|
||||||
|
return { insertCount: 1 };
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async find(instance: string): Promise<ChatwootRaw> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('finding chatwoot');
|
||||||
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding chatwoot in db');
|
||||||
|
return await this.chatwootModel.findOne({ _id: instance });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding chatwoot in store');
|
||||||
|
return JSON.parse(
|
||||||
|
readFileSync(join(this.storePath, 'chatwoot', instance + '.json'), {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
}),
|
||||||
|
) as ChatwootRaw;
|
||||||
|
} catch (error) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { join } from 'path';
|
|||||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||||
import { ContactRaw, IContactModel } from '../models';
|
import { ContactRaw, IContactModel } from '../models';
|
||||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
export class ContactQuery {
|
export class ContactQuery {
|
||||||
where: ContactRaw;
|
where: ContactRaw;
|
||||||
@@ -16,31 +17,121 @@ export class ContactRepository extends Repository {
|
|||||||
super(configService);
|
super(configService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async insert(data: ContactRaw[], saveDb = false): Promise<IInsert> {
|
private readonly logger = new Logger('ContactRepository');
|
||||||
|
|
||||||
|
public async insert(
|
||||||
|
data: ContactRaw[],
|
||||||
|
instanceName: string,
|
||||||
|
saveDb = false,
|
||||||
|
): Promise<IInsert> {
|
||||||
|
this.logger.verbose('inserting contacts');
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
this.logger.verbose('no contacts to insert');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.dbSettings.ENABLED && saveDb) {
|
if (this.dbSettings.ENABLED && saveDb) {
|
||||||
|
this.logger.verbose('saving contacts to db');
|
||||||
|
|
||||||
const insert = await this.contactModel.insertMany([...data]);
|
const insert = await this.contactModel.insertMany([...data]);
|
||||||
|
|
||||||
|
this.logger.verbose('contacts saved to db: ' + insert.length + ' contacts');
|
||||||
return { insertCount: insert.length };
|
return { insertCount: insert.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving contacts to store');
|
||||||
|
|
||||||
const store = this.configService.get<StoreConf>('STORE');
|
const store = this.configService.get<StoreConf>('STORE');
|
||||||
|
|
||||||
if (store.CONTACTS) {
|
if (store.CONTACTS) {
|
||||||
|
this.logger.verbose('saving contacts to store');
|
||||||
data.forEach((contact) => {
|
data.forEach((contact) => {
|
||||||
this.writeStore({
|
this.writeStore({
|
||||||
path: join(this.storePath, 'contacts', contact.owner),
|
path: join(this.storePath, 'contacts', instanceName),
|
||||||
fileName: contact.id,
|
fileName: contact.id,
|
||||||
data: contact,
|
data: contact,
|
||||||
});
|
});
|
||||||
|
this.logger.verbose(
|
||||||
|
'contacts saved to store in path: ' +
|
||||||
|
join(this.storePath, 'contacts', instanceName) +
|
||||||
|
'/' +
|
||||||
|
contact.id,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logger.verbose('contacts saved to store: ' + data.length + ' contacts');
|
||||||
|
return { insertCount: data.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('contacts not saved');
|
||||||
|
return { insertCount: 0 };
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
} finally {
|
||||||
|
data = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update(
|
||||||
|
data: ContactRaw[],
|
||||||
|
instanceName: string,
|
||||||
|
saveDb = false,
|
||||||
|
): Promise<IInsert> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('updating contacts');
|
||||||
|
|
||||||
|
if (data.length === 0) {
|
||||||
|
this.logger.verbose('no contacts to update');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.dbSettings.ENABLED && saveDb) {
|
||||||
|
this.logger.verbose('updating contacts in db');
|
||||||
|
|
||||||
|
const contacts = data.map((contact) => {
|
||||||
|
return {
|
||||||
|
updateOne: {
|
||||||
|
filter: { id: contact.id },
|
||||||
|
update: { ...contact },
|
||||||
|
upsert: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const { nModified } = await this.contactModel.bulkWrite(contacts);
|
||||||
|
|
||||||
|
this.logger.verbose('contacts updated in db: ' + nModified + ' contacts');
|
||||||
|
return { insertCount: nModified };
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('updating contacts in store');
|
||||||
|
|
||||||
|
const store = this.configService.get<StoreConf>('STORE');
|
||||||
|
|
||||||
|
if (store.CONTACTS) {
|
||||||
|
this.logger.verbose('updating contacts in store');
|
||||||
|
data.forEach((contact) => {
|
||||||
|
this.writeStore({
|
||||||
|
path: join(this.storePath, 'contacts', instanceName),
|
||||||
|
fileName: contact.id,
|
||||||
|
data: contact,
|
||||||
|
});
|
||||||
|
this.logger.verbose(
|
||||||
|
'contacts updated in store in path: ' +
|
||||||
|
join(this.storePath, 'contacts', instanceName) +
|
||||||
|
'/' +
|
||||||
|
contact.id,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.verbose('contacts updated in store: ' + data.length + ' contacts');
|
||||||
|
|
||||||
return { insertCount: data.length };
|
return { insertCount: data.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('contacts not updated');
|
||||||
return { insertCount: 0 };
|
return { insertCount: 0 };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
@@ -51,11 +142,16 @@ export class ContactRepository extends Repository {
|
|||||||
|
|
||||||
public async find(query: ContactQuery): Promise<ContactRaw[]> {
|
public async find(query: ContactQuery): Promise<ContactRaw[]> {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('finding contacts');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding contacts in db');
|
||||||
return await this.contactModel.find({ ...query.where });
|
return await this.contactModel.find({ ...query.where });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding contacts in store');
|
||||||
const contacts: ContactRaw[] = [];
|
const contacts: ContactRaw[] = [];
|
||||||
if (query?.where?.id) {
|
if (query?.where?.id) {
|
||||||
|
this.logger.verbose('finding contacts in store by id');
|
||||||
contacts.push(
|
contacts.push(
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
readFileSync(
|
readFileSync(
|
||||||
@@ -70,6 +166,8 @@ export class ContactRepository extends Repository {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.verbose('finding contacts in store by owner');
|
||||||
|
|
||||||
const openDir = opendirSync(join(this.storePath, 'contacts', query.where.owner), {
|
const openDir = opendirSync(join(this.storePath, 'contacts', query.where.owner), {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
});
|
});
|
||||||
@@ -86,6 +184,8 @@ export class ContactRepository extends Repository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('contacts found in store: ' + contacts.length + ' contacts');
|
||||||
return contacts;
|
return contacts;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { join } from 'path';
|
|||||||
import { IMessageModel, MessageRaw } from '../models';
|
import { IMessageModel, MessageRaw } from '../models';
|
||||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
import { opendirSync, readFileSync } from 'fs';
|
import { opendirSync, readFileSync } from 'fs';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
export class MessageQuery {
|
export class MessageQuery {
|
||||||
where: MessageRaw;
|
where: MessageRaw;
|
||||||
@@ -17,13 +18,23 @@ export class MessageRepository extends Repository {
|
|||||||
super(configService);
|
super(configService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async insert(data: MessageRaw[], saveDb = false): Promise<IInsert> {
|
private readonly logger = new Logger('MessageRepository');
|
||||||
|
|
||||||
|
public async insert(
|
||||||
|
data: MessageRaw[],
|
||||||
|
instanceName: string,
|
||||||
|
saveDb = false,
|
||||||
|
): Promise<IInsert> {
|
||||||
|
this.logger.verbose('inserting messages');
|
||||||
|
|
||||||
if (!Array.isArray(data) || data.length === 0) {
|
if (!Array.isArray(data) || data.length === 0) {
|
||||||
|
this.logger.verbose('no messages to insert');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.dbSettings.ENABLED && saveDb) {
|
if (this.dbSettings.ENABLED && saveDb) {
|
||||||
|
this.logger.verbose('saving messages to db');
|
||||||
const cleanedData = data.map((obj) => {
|
const cleanedData = data.map((obj) => {
|
||||||
const cleanedObj = { ...obj };
|
const cleanedObj = { ...obj };
|
||||||
if ('extendedTextMessage' in obj.message) {
|
if ('extendedTextMessage' in obj.message) {
|
||||||
@@ -44,23 +55,37 @@ export class MessageRepository extends Repository {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const insert = await this.messageModel.insertMany([...cleanedData]);
|
const insert = await this.messageModel.insertMany([...cleanedData]);
|
||||||
|
|
||||||
|
this.logger.verbose('messages saved to db: ' + insert.length + ' messages');
|
||||||
return { insertCount: insert.length };
|
return { insertCount: insert.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving messages to store');
|
||||||
|
|
||||||
const store = this.configService.get<StoreConf>('STORE');
|
const store = this.configService.get<StoreConf>('STORE');
|
||||||
|
|
||||||
if (store.MESSAGES) {
|
if (store.MESSAGES) {
|
||||||
data.forEach((msg) =>
|
this.logger.verbose('saving messages to store');
|
||||||
this.writeStore<MessageRaw>({
|
|
||||||
path: join(this.storePath, 'messages', msg.owner),
|
|
||||||
fileName: msg.key.id,
|
|
||||||
data: msg,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
data.forEach((message) => {
|
||||||
|
this.writeStore({
|
||||||
|
path: join(this.storePath, 'messages', instanceName),
|
||||||
|
fileName: message.key.id,
|
||||||
|
data: message,
|
||||||
|
});
|
||||||
|
this.logger.verbose(
|
||||||
|
'messages saved to store in path: ' +
|
||||||
|
join(this.storePath, 'messages', instanceName) +
|
||||||
|
'/' +
|
||||||
|
message.key.id,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.verbose('messages saved to store: ' + data.length + ' messages');
|
||||||
return { insertCount: data.length };
|
return { insertCount: data.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('messages not saved to store');
|
||||||
return { insertCount: 0 };
|
return { insertCount: 0 };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('ERROR: ', error);
|
console.log('ERROR: ', error);
|
||||||
@@ -72,21 +97,26 @@ export class MessageRepository extends Repository {
|
|||||||
|
|
||||||
public async find(query: MessageQuery) {
|
public async find(query: MessageQuery) {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('finding messages');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding messages in db');
|
||||||
if (query?.where?.key) {
|
if (query?.where?.key) {
|
||||||
for (const [k, v] of Object.entries(query.where.key)) {
|
for (const [k, v] of Object.entries(query.where.key)) {
|
||||||
query.where['key.' + k] = v;
|
query.where['key.' + k] = v;
|
||||||
}
|
}
|
||||||
delete query?.where?.key;
|
delete query?.where?.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.messageModel
|
return await this.messageModel
|
||||||
.find({ ...query.where })
|
.find({ ...query.where })
|
||||||
.sort({ messageTimestamp: -1 })
|
.sort({ messageTimestamp: -1 })
|
||||||
.limit(query?.limit ?? 0);
|
.limit(query?.limit ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding messages in store');
|
||||||
const messages: MessageRaw[] = [];
|
const messages: MessageRaw[] = [];
|
||||||
if (query?.where?.key?.id) {
|
if (query?.where?.key?.id) {
|
||||||
|
this.logger.verbose('finding messages in store by id');
|
||||||
messages.push(
|
messages.push(
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
readFileSync(
|
readFileSync(
|
||||||
@@ -101,6 +131,7 @@ export class MessageRepository extends Repository {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.verbose('finding messages in store by owner');
|
||||||
const openDir = opendirSync(join(this.storePath, 'messages', query.where.owner), {
|
const openDir = opendirSync(join(this.storePath, 'messages', query.where.owner), {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
});
|
});
|
||||||
@@ -119,6 +150,7 @@ export class MessageRepository extends Repository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('messages found in store: ' + messages.length + ' messages');
|
||||||
return messages
|
return messages
|
||||||
.sort((x, y) => {
|
.sort((x, y) => {
|
||||||
return (y.messageTimestamp as number) - (x.messageTimestamp as number);
|
return (y.messageTimestamp as number) - (x.messageTimestamp as number);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { IMessageUpModel, MessageUpdateRaw } from '../models';
|
|||||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { opendirSync, readFileSync } from 'fs';
|
import { opendirSync, readFileSync } from 'fs';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
export class MessageUpQuery {
|
export class MessageUpQuery {
|
||||||
where: MessageUpdateRaw;
|
where: MessageUpdateRaw;
|
||||||
@@ -17,31 +18,54 @@ export class MessageUpRepository extends Repository {
|
|||||||
super(configService);
|
super(configService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async insert(data: MessageUpdateRaw[], saveDb?: boolean): Promise<IInsert> {
|
private readonly logger = new Logger('MessageUpRepository');
|
||||||
|
|
||||||
|
public async insert(
|
||||||
|
data: MessageUpdateRaw[],
|
||||||
|
instanceName: string,
|
||||||
|
saveDb?: boolean,
|
||||||
|
): Promise<IInsert> {
|
||||||
|
this.logger.verbose('inserting message up');
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
this.logger.verbose('no message up to insert');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.dbSettings.ENABLED && saveDb) {
|
if (this.dbSettings.ENABLED && saveDb) {
|
||||||
|
this.logger.verbose('saving message up to db');
|
||||||
const insert = await this.messageUpModel.insertMany([...data]);
|
const insert = await this.messageUpModel.insertMany([...data]);
|
||||||
|
|
||||||
|
this.logger.verbose('message up saved to db: ' + insert.length + ' message up');
|
||||||
return { insertCount: insert.length };
|
return { insertCount: insert.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving message up to store');
|
||||||
|
|
||||||
const store = this.configService.get<StoreConf>('STORE');
|
const store = this.configService.get<StoreConf>('STORE');
|
||||||
|
|
||||||
if (store.MESSAGE_UP) {
|
if (store.MESSAGE_UP) {
|
||||||
|
this.logger.verbose('saving message up to store');
|
||||||
data.forEach((update) => {
|
data.forEach((update) => {
|
||||||
this.writeStore<MessageUpdateRaw>({
|
this.writeStore<MessageUpdateRaw>({
|
||||||
path: join(this.storePath, 'message-up', update.owner),
|
path: join(this.storePath, 'message-up', instanceName),
|
||||||
fileName: update.id,
|
fileName: update.id,
|
||||||
data: update,
|
data: update,
|
||||||
});
|
});
|
||||||
|
this.logger.verbose(
|
||||||
|
'message up saved to store in path: ' +
|
||||||
|
join(this.storePath, 'message-up', instanceName) +
|
||||||
|
'/' +
|
||||||
|
update.id,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logger.verbose('message up saved to store: ' + data.length + ' message up');
|
||||||
return { insertCount: data.length };
|
return { insertCount: data.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('message up not saved to store');
|
||||||
return { insertCount: 0 };
|
return { insertCount: 0 };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
@@ -50,15 +74,21 @@ export class MessageUpRepository extends Repository {
|
|||||||
|
|
||||||
public async find(query: MessageUpQuery) {
|
public async find(query: MessageUpQuery) {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('finding message up');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding message up in db');
|
||||||
return await this.messageUpModel
|
return await this.messageUpModel
|
||||||
.find({ ...query.where })
|
.find({ ...query.where })
|
||||||
.sort({ datetime: -1 })
|
.sort({ datetime: -1 })
|
||||||
.limit(query?.limit ?? 0);
|
.limit(query?.limit ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding message up in store');
|
||||||
|
|
||||||
const messageUpdate: MessageUpdateRaw[] = [];
|
const messageUpdate: MessageUpdateRaw[] = [];
|
||||||
if (query?.where?.id) {
|
if (query?.where?.id) {
|
||||||
|
this.logger.verbose('finding message up in store by id');
|
||||||
|
|
||||||
messageUpdate.push(
|
messageUpdate.push(
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
readFileSync(
|
readFileSync(
|
||||||
@@ -73,6 +103,8 @@ export class MessageUpRepository extends Repository {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.verbose('finding message up in store by owner');
|
||||||
|
|
||||||
const openDir = opendirSync(
|
const openDir = opendirSync(
|
||||||
join(this.storePath, 'message-up', query.where.owner),
|
join(this.storePath, 'message-up', query.where.owner),
|
||||||
{ encoding: 'utf-8' },
|
{ encoding: 'utf-8' },
|
||||||
@@ -92,6 +124,9 @@ export class MessageUpRepository extends Repository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose(
|
||||||
|
'message up found in store: ' + messageUpdate.length + ' message up',
|
||||||
|
);
|
||||||
return messageUpdate
|
return messageUpdate
|
||||||
.sort((x, y) => {
|
.sort((x, y) => {
|
||||||
return y.datetime - x.datetime;
|
return y.datetime - x.datetime;
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ import { ContactRepository } from './contact.repository';
|
|||||||
import { MessageUpRepository } from './messageUp.repository';
|
import { MessageUpRepository } from './messageUp.repository';
|
||||||
import { MongoClient } from 'mongodb';
|
import { MongoClient } from 'mongodb';
|
||||||
import { WebhookRepository } from './webhook.repository';
|
import { WebhookRepository } from './webhook.repository';
|
||||||
|
import { ChatwootRepository } from './chatwoot.repository';
|
||||||
|
import { SettingsRepository } from './settings.repository';
|
||||||
|
|
||||||
import { AuthRepository } from './auth.repository';
|
import { AuthRepository } from './auth.repository';
|
||||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||||
import { execSync } from 'child_process';
|
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
export class RepositoryBroker {
|
export class RepositoryBroker {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly message: MessageRepository,
|
public readonly message: MessageRepository,
|
||||||
@@ -16,6 +19,8 @@ export class RepositoryBroker {
|
|||||||
public readonly contact: ContactRepository,
|
public readonly contact: ContactRepository,
|
||||||
public readonly messageUpdate: MessageUpRepository,
|
public readonly messageUpdate: MessageUpRepository,
|
||||||
public readonly webhook: WebhookRepository,
|
public readonly webhook: WebhookRepository,
|
||||||
|
public readonly chatwoot: ChatwootRepository,
|
||||||
|
public readonly settings: SettingsRepository,
|
||||||
public readonly auth: AuthRepository,
|
public readonly auth: AuthRepository,
|
||||||
private configService: ConfigService,
|
private configService: ConfigService,
|
||||||
dbServer?: MongoClient,
|
dbServer?: MongoClient,
|
||||||
@@ -25,26 +30,92 @@ export class RepositoryBroker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private dbClient?: MongoClient;
|
private dbClient?: MongoClient;
|
||||||
|
private readonly logger = new Logger('RepositoryBroker');
|
||||||
|
|
||||||
public get dbServer() {
|
public get dbServer() {
|
||||||
return this.dbClient;
|
return this.dbClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
private __init_repo_without_db__() {
|
private __init_repo_without_db__() {
|
||||||
|
this.logger.verbose('initializing repository without db');
|
||||||
if (!this.configService.get<Database>('DATABASE').ENABLED) {
|
if (!this.configService.get<Database>('DATABASE').ENABLED) {
|
||||||
const storePath = join(process.cwd(), 'store');
|
const storePath = join(process.cwd(), 'store');
|
||||||
execSync(
|
|
||||||
`mkdir -p ${join(
|
this.logger.verbose('creating store path: ' + storePath);
|
||||||
|
try {
|
||||||
|
const authDir = join(
|
||||||
storePath,
|
storePath,
|
||||||
'auth',
|
'auth',
|
||||||
this.configService.get<Auth>('AUTHENTICATION').TYPE,
|
this.configService.get<Auth>('AUTHENTICATION').TYPE,
|
||||||
)}`,
|
|
||||||
);
|
);
|
||||||
execSync(`mkdir -p ${join(storePath, 'chats')}`);
|
const chatsDir = join(storePath, 'chats');
|
||||||
execSync(`mkdir -p ${join(storePath, 'contacts')}`);
|
const contactsDir = join(storePath, 'contacts');
|
||||||
execSync(`mkdir -p ${join(storePath, 'messages')}`);
|
const messagesDir = join(storePath, 'messages');
|
||||||
execSync(`mkdir -p ${join(storePath, 'message-up')}`);
|
const messageUpDir = join(storePath, 'message-up');
|
||||||
execSync(`mkdir -p ${join(storePath, 'webhook')}`);
|
const webhookDir = join(storePath, 'webhook');
|
||||||
|
const chatwootDir = join(storePath, 'chatwoot');
|
||||||
|
const settingsDir = join(storePath, 'settings');
|
||||||
|
const tempDir = join(storePath, 'temp');
|
||||||
|
|
||||||
|
if (!fs.existsSync(authDir)) {
|
||||||
|
this.logger.verbose('creating auth dir: ' + authDir);
|
||||||
|
fs.mkdirSync(authDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(chatsDir)) {
|
||||||
|
this.logger.verbose('creating chats dir: ' + chatsDir);
|
||||||
|
fs.mkdirSync(chatsDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(contactsDir)) {
|
||||||
|
this.logger.verbose('creating contacts dir: ' + contactsDir);
|
||||||
|
fs.mkdirSync(contactsDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(messagesDir)) {
|
||||||
|
this.logger.verbose('creating messages dir: ' + messagesDir);
|
||||||
|
fs.mkdirSync(messagesDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(messageUpDir)) {
|
||||||
|
this.logger.verbose('creating message-up dir: ' + messageUpDir);
|
||||||
|
fs.mkdirSync(messageUpDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(webhookDir)) {
|
||||||
|
this.logger.verbose('creating webhook dir: ' + webhookDir);
|
||||||
|
fs.mkdirSync(webhookDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(chatwootDir)) {
|
||||||
|
this.logger.verbose('creating chatwoot dir: ' + chatwootDir);
|
||||||
|
fs.mkdirSync(chatwootDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(settingsDir)) {
|
||||||
|
this.logger.verbose('creating settings dir: ' + settingsDir);
|
||||||
|
fs.mkdirSync(settingsDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(tempDir)) {
|
||||||
|
this.logger.verbose('creating temp dir: ' + tempDir);
|
||||||
|
fs.mkdirSync(tempDir, { recursive: true });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const storePath = join(process.cwd(), 'store');
|
||||||
|
|
||||||
|
this.logger.verbose('creating store path: ' + storePath);
|
||||||
|
|
||||||
|
const tempDir = join(storePath, 'temp');
|
||||||
|
const chatwootDir = join(storePath, 'chatwoot');
|
||||||
|
|
||||||
|
if (!fs.existsSync(chatwootDir)) {
|
||||||
|
this.logger.verbose('creating chatwoot dir: ' + chatwootDir);
|
||||||
|
fs.mkdirSync(chatwootDir, { recursive: true });
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(tempDir)) {
|
||||||
|
this.logger.verbose('creating temp dir: ' + tempDir);
|
||||||
|
fs.mkdirSync(tempDir, { recursive: true });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
75
src/whatsapp/repository/settings.repository.ts
Normal file
75
src/whatsapp/repository/settings.repository.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||||
|
import { ConfigService } from '../../config/env.config';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { ISettingsModel, SettingsRaw } from '../models';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
export class SettingsRepository extends Repository {
|
||||||
|
constructor(
|
||||||
|
private readonly settingsModel: ISettingsModel,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
) {
|
||||||
|
super(configService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly logger = new Logger('SettingsRepository');
|
||||||
|
|
||||||
|
public async create(data: SettingsRaw, instance: string): Promise<IInsert> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('creating settings');
|
||||||
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('saving settings to db');
|
||||||
|
const insert = await this.settingsModel.replaceOne(
|
||||||
|
{ _id: instance },
|
||||||
|
{ ...data },
|
||||||
|
{ upsert: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.verbose(
|
||||||
|
'settings saved to db: ' + insert.modifiedCount + ' settings',
|
||||||
|
);
|
||||||
|
return { insertCount: insert.modifiedCount };
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving settings to store');
|
||||||
|
|
||||||
|
this.writeStore<SettingsRaw>({
|
||||||
|
path: join(this.storePath, 'settings'),
|
||||||
|
fileName: instance,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.verbose(
|
||||||
|
'settings saved to store in path: ' +
|
||||||
|
join(this.storePath, 'settings') +
|
||||||
|
'/' +
|
||||||
|
instance,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('settings created');
|
||||||
|
return { insertCount: 1 };
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async find(instance: string): Promise<SettingsRaw> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('finding settings');
|
||||||
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding settings in db');
|
||||||
|
return await this.settingsModel.findOne({ _id: instance });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding settings in store');
|
||||||
|
return JSON.parse(
|
||||||
|
readFileSync(join(this.storePath, 'settings', instance + '.json'), {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
}),
|
||||||
|
) as SettingsRaw;
|
||||||
|
} catch (error) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { ConfigService } from '../../config/env.config';
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { IWebhookModel, WebhookRaw } from '../models';
|
import { IWebhookModel, WebhookRaw } from '../models';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
export class WebhookRepository extends Repository {
|
export class WebhookRepository extends Repository {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -12,23 +13,39 @@ export class WebhookRepository extends Repository {
|
|||||||
super(configService);
|
super(configService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly logger = new Logger('WebhookRepository');
|
||||||
|
|
||||||
public async create(data: WebhookRaw, instance: string): Promise<IInsert> {
|
public async create(data: WebhookRaw, instance: string): Promise<IInsert> {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('creating webhook');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('saving webhook to db');
|
||||||
const insert = await this.webhookModel.replaceOne(
|
const insert = await this.webhookModel.replaceOne(
|
||||||
{ _id: instance },
|
{ _id: instance },
|
||||||
{ ...data },
|
{ ...data },
|
||||||
{ upsert: true },
|
{ upsert: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('webhook saved to db: ' + insert.modifiedCount + ' webhook');
|
||||||
return { insertCount: insert.modifiedCount };
|
return { insertCount: insert.modifiedCount };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('saving webhook to store');
|
||||||
|
|
||||||
this.writeStore<WebhookRaw>({
|
this.writeStore<WebhookRaw>({
|
||||||
path: join(this.storePath, 'webhook'),
|
path: join(this.storePath, 'webhook'),
|
||||||
fileName: instance,
|
fileName: instance,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logger.verbose(
|
||||||
|
'webhook saved to store in path: ' +
|
||||||
|
join(this.storePath, 'webhook') +
|
||||||
|
'/' +
|
||||||
|
instance,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('webhook created');
|
||||||
return { insertCount: 1 };
|
return { insertCount: 1 };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
@@ -37,10 +54,13 @@ export class WebhookRepository extends Repository {
|
|||||||
|
|
||||||
public async find(instance: string): Promise<WebhookRaw> {
|
public async find(instance: string): Promise<WebhookRaw> {
|
||||||
try {
|
try {
|
||||||
|
this.logger.verbose('finding webhook');
|
||||||
if (this.dbSettings.ENABLED) {
|
if (this.dbSettings.ENABLED) {
|
||||||
|
this.logger.verbose('finding webhook in db');
|
||||||
return await this.webhookModel.findOne({ _id: instance });
|
return await this.webhookModel.findOne({ _id: instance });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('finding webhook in store');
|
||||||
return JSON.parse(
|
return JSON.parse(
|
||||||
readFileSync(join(this.storePath, 'webhook', instance + '.json'), {
|
readFileSync(join(this.storePath, 'webhook', instance + '.json'), {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
privacySettingsSchema,
|
privacySettingsSchema,
|
||||||
profileNameSchema,
|
profileNameSchema,
|
||||||
profilePictureSchema,
|
profilePictureSchema,
|
||||||
|
profileSchema,
|
||||||
profileStatusSchema,
|
profileStatusSchema,
|
||||||
readMessageSchema,
|
readMessageSchema,
|
||||||
whatsappNumberSchema,
|
whatsappNumberSchema,
|
||||||
@@ -32,12 +33,22 @@ import { HttpStatus } from './index.router';
|
|||||||
import { MessageUpQuery } from '../repository/messageUp.repository';
|
import { MessageUpQuery } from '../repository/messageUp.repository';
|
||||||
import { proto } from '@whiskeysockets/baileys';
|
import { proto } from '@whiskeysockets/baileys';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('ChatRouter');
|
||||||
|
|
||||||
export class ChatRouter extends RouterBroker {
|
export class ChatRouter extends RouterBroker {
|
||||||
constructor(...guards: RequestHandler[]) {
|
constructor(...guards: RequestHandler[]) {
|
||||||
super();
|
super();
|
||||||
this.router
|
this.router
|
||||||
.post(this.routerPath('whatsappNumbers'), ...guards, async (req, res) => {
|
.post(this.routerPath('whatsappNumbers'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in whatsappNumbers');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<WhatsAppNumberDto>({
|
const response = await this.dataValidate<WhatsAppNumberDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: whatsappNumberSchema,
|
schema: whatsappNumberSchema,
|
||||||
@@ -48,6 +59,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('markMessageAsRead'), ...guards, async (req, res) => {
|
.put(this.routerPath('markMessageAsRead'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in markMessageAsRead');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ReadMessageDto>({
|
const response = await this.dataValidate<ReadMessageDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: readMessageSchema,
|
schema: readMessageSchema,
|
||||||
@@ -58,6 +76,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('archiveChat'), ...guards, async (req, res) => {
|
.put(this.routerPath('archiveChat'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in archiveChat');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ArchiveChatDto>({
|
const response = await this.dataValidate<ArchiveChatDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: archiveChatSchema,
|
schema: archiveChatSchema,
|
||||||
@@ -71,6 +96,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
this.routerPath('deleteMessageForEveryone'),
|
this.routerPath('deleteMessageForEveryone'),
|
||||||
...guards,
|
...guards,
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
|
logger.verbose('request received in deleteMessageForEveryone');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<DeleteMessage>({
|
const response = await this.dataValidate<DeleteMessage>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: deleteMessageSchema,
|
schema: deleteMessageSchema,
|
||||||
@@ -82,6 +114,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.post(this.routerPath('fetchProfilePictureUrl'), ...guards, async (req, res) => {
|
.post(this.routerPath('fetchProfilePictureUrl'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in fetchProfilePictureUrl');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<NumberDto>({
|
const response = await this.dataValidate<NumberDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: profilePictureSchema,
|
schema: profilePictureSchema,
|
||||||
@@ -91,7 +130,31 @@ export class ChatRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
|
.post(this.routerPath('fetchProfile'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in fetchProfile');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
|
const response = await this.dataValidate<NumberDto>({
|
||||||
|
request: req,
|
||||||
|
schema: profileSchema,
|
||||||
|
ClassRef: NumberDto,
|
||||||
|
execute: (instance, data) => chatController.fetchProfile(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(HttpStatus.OK).json(response);
|
||||||
|
})
|
||||||
.post(this.routerPath('findContacts'), ...guards, async (req, res) => {
|
.post(this.routerPath('findContacts'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findContacts');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ContactQuery>({
|
const response = await this.dataValidate<ContactQuery>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: contactValidateSchema,
|
schema: contactValidateSchema,
|
||||||
@@ -102,6 +165,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('getBase64FromMediaMessage'), ...guards, async (req, res) => {
|
.post(this.routerPath('getBase64FromMediaMessage'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in getBase64FromMediaMessage');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<getBase64FromMediaMessageDto>({
|
const response = await this.dataValidate<getBase64FromMediaMessageDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: null,
|
schema: null,
|
||||||
@@ -113,6 +183,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('findMessages'), ...guards, async (req, res) => {
|
.post(this.routerPath('findMessages'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findMessages');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<MessageQuery>({
|
const response = await this.dataValidate<MessageQuery>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: messageValidateSchema,
|
schema: messageValidateSchema,
|
||||||
@@ -123,6 +200,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('findStatusMessage'), ...guards, async (req, res) => {
|
.post(this.routerPath('findStatusMessage'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findStatusMessage');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<MessageUpQuery>({
|
const response = await this.dataValidate<MessageUpQuery>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: messageUpSchema,
|
schema: messageUpSchema,
|
||||||
@@ -133,6 +217,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('findChats'), ...guards, async (req, res) => {
|
.get(this.routerPath('findChats'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findChats');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: null,
|
schema: null,
|
||||||
@@ -144,6 +235,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
})
|
})
|
||||||
// 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 body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: null,
|
schema: null,
|
||||||
@@ -154,6 +252,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('updatePrivacySettings'), ...guards, async (req, res) => {
|
.put(this.routerPath('updatePrivacySettings'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updatePrivacySettings');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<PrivacySettingDto>({
|
const response = await this.dataValidate<PrivacySettingDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: privacySettingsSchema,
|
schema: privacySettingsSchema,
|
||||||
@@ -165,6 +270,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
|
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in fetchBusinessProfile');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ProfilePictureDto>({
|
const response = await this.dataValidate<ProfilePictureDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: profilePictureSchema,
|
schema: profilePictureSchema,
|
||||||
@@ -176,6 +288,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('updateProfileName'), ...guards, async (req, res) => {
|
.post(this.routerPath('updateProfileName'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateProfileName');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ProfileNameDto>({
|
const response = await this.dataValidate<ProfileNameDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: profileNameSchema,
|
schema: profileNameSchema,
|
||||||
@@ -186,6 +305,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('updateProfileStatus'), ...guards, async (req, res) => {
|
.post(this.routerPath('updateProfileStatus'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateProfileStatus');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ProfileStatusDto>({
|
const response = await this.dataValidate<ProfileStatusDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: profileStatusSchema,
|
schema: profileStatusSchema,
|
||||||
@@ -196,6 +322,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('updateProfilePicture'), ...guards, async (req, res) => {
|
.put(this.routerPath('updateProfilePicture'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateProfilePicture');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ProfilePictureDto>({
|
const response = await this.dataValidate<ProfilePictureDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: profilePictureSchema,
|
schema: profilePictureSchema,
|
||||||
@@ -207,6 +340,13 @@ export class ChatRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.delete(this.routerPath('removeProfilePicture'), ...guards, async (req, res) => {
|
.delete(this.routerPath('removeProfilePicture'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in removeProfilePicture');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<ProfilePictureDto>({
|
const response = await this.dataValidate<ProfilePictureDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: profilePictureSchema,
|
schema: profilePictureSchema,
|
||||||
|
|||||||
68
src/whatsapp/routers/chatwoot.router.ts
Normal file
68
src/whatsapp/routers/chatwoot.router.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { RequestHandler, Router } from 'express';
|
||||||
|
import { instanceNameSchema, chatwootSchema } from '../../validate/validate.schema';
|
||||||
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||||
|
import { chatwootController } from '../whatsapp.module';
|
||||||
|
import { ChatwootService } from '../services/chatwoot.service';
|
||||||
|
import { HttpStatus } from './index.router';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('ChatwootRouter');
|
||||||
|
|
||||||
|
export class ChatwootRouter extends RouterBroker {
|
||||||
|
constructor(...guards: RequestHandler[]) {
|
||||||
|
super();
|
||||||
|
this.router
|
||||||
|
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in setChatwoot');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.dataValidate<ChatwootDto>({
|
||||||
|
request: req,
|
||||||
|
schema: chatwootSchema,
|
||||||
|
ClassRef: ChatwootDto,
|
||||||
|
execute: (instance, data) => chatwootController.createChatwoot(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
|
})
|
||||||
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findChatwoot');
|
||||||
|
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) => chatwootController.findChatwoot(instance),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json(response);
|
||||||
|
})
|
||||||
|
.post(this.routerPath('webhook'), async (req, res) => {
|
||||||
|
logger.verbose('request received in findChatwoot');
|
||||||
|
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, data) => chatwootController.receiveWebhook(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly router = Router();
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
updateGroupDescriptionSchema,
|
updateGroupDescriptionSchema,
|
||||||
groupInviteSchema,
|
groupInviteSchema,
|
||||||
groupSendInviteSchema,
|
groupSendInviteSchema,
|
||||||
|
getParticipantsSchema,
|
||||||
} from '../../validate/validate.schema';
|
} from '../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import {
|
import {
|
||||||
@@ -23,15 +24,25 @@ import {
|
|||||||
GroupUpdateSettingDto,
|
GroupUpdateSettingDto,
|
||||||
GroupToggleEphemeralDto,
|
GroupToggleEphemeralDto,
|
||||||
GroupSendInvite,
|
GroupSendInvite,
|
||||||
|
GetParticipant,
|
||||||
} from '../dto/group.dto';
|
} from '../dto/group.dto';
|
||||||
import { groupController } from '../whatsapp.module';
|
import { groupController } from '../whatsapp.module';
|
||||||
import { HttpStatus } from './index.router';
|
import { HttpStatus } from './index.router';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('GroupRouter');
|
||||||
|
|
||||||
export class GroupRouter extends RouterBroker {
|
export class GroupRouter extends RouterBroker {
|
||||||
constructor(...guards: RequestHandler[]) {
|
constructor(...guards: RequestHandler[]) {
|
||||||
super();
|
super();
|
||||||
this.router
|
this.router
|
||||||
.post(this.routerPath('create'), ...guards, async (req, res) => {
|
.post(this.routerPath('create'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in createGroup');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<CreateGroupDto>({
|
const response = await this.dataValidate<CreateGroupDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: createGroupSchema,
|
schema: createGroupSchema,
|
||||||
@@ -42,6 +53,13 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('updateGroupSubject'), ...guards, async (req, res) => {
|
.put(this.routerPath('updateGroupSubject'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateGroupSubject');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.groupValidate<GroupSubjectDto>({
|
const response = await this.groupValidate<GroupSubjectDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: updateGroupSubjectSchema,
|
schema: updateGroupSubjectSchema,
|
||||||
@@ -52,6 +70,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('updateGroupPicture'), ...guards, async (req, res) => {
|
.put(this.routerPath('updateGroupPicture'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateGroupPicture');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupPictureDto>({
|
const response = await this.groupValidate<GroupPictureDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: updateGroupPictureSchema,
|
schema: updateGroupPictureSchema,
|
||||||
@@ -62,6 +86,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('updateGroupDescription'), ...guards, async (req, res) => {
|
.put(this.routerPath('updateGroupDescription'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateGroupDescription');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupDescriptionDto>({
|
const response = await this.groupValidate<GroupDescriptionDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: updateGroupDescriptionSchema,
|
schema: updateGroupDescriptionSchema,
|
||||||
@@ -73,6 +103,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('findGroupInfos'), ...guards, async (req, res) => {
|
.get(this.routerPath('findGroupInfos'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findGroupInfos');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupJid>({
|
const response = await this.groupValidate<GroupJid>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: groupJidSchema,
|
schema: groupJidSchema,
|
||||||
@@ -83,16 +119,28 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.OK).json(response);
|
res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('fetchAllGroups'), ...guards, async (req, res) => {
|
.get(this.routerPath('fetchAllGroups'), ...guards, async (req, res) => {
|
||||||
const response = await this.groupNoValidate<GroupJid>({
|
logger.verbose('request received in fetchAllGroups');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.getParticipantsValidate<GetParticipant>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: {},
|
schema: getParticipantsSchema,
|
||||||
ClassRef: GroupJid,
|
ClassRef: GetParticipant,
|
||||||
execute: (instance) => groupController.fetchAllGroups(instance),
|
execute: (instance, data) => groupController.fetchAllGroups(instance, data),
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(HttpStatus.OK).json(response);
|
res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('participants'), ...guards, async (req, res) => {
|
.get(this.routerPath('participants'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in participants');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupJid>({
|
const response = await this.groupValidate<GroupJid>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: groupJidSchema,
|
schema: groupJidSchema,
|
||||||
@@ -103,6 +151,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.OK).json(response);
|
res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('inviteCode'), ...guards, async (req, res) => {
|
.get(this.routerPath('inviteCode'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in inviteCode');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupJid>({
|
const response = await this.groupValidate<GroupJid>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: groupJidSchema,
|
schema: groupJidSchema,
|
||||||
@@ -113,6 +167,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.OK).json(response);
|
res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('inviteInfo'), ...guards, async (req, res) => {
|
.get(this.routerPath('inviteInfo'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in inviteInfo');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.inviteCodeValidate<GroupInvite>({
|
const response = await this.inviteCodeValidate<GroupInvite>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: groupInviteSchema,
|
schema: groupInviteSchema,
|
||||||
@@ -123,6 +183,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.OK).json(response);
|
res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendInvite'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendInvite'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendInvite');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupNoValidate<GroupSendInvite>({
|
const response = await this.groupNoValidate<GroupSendInvite>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: groupSendInviteSchema,
|
schema: groupSendInviteSchema,
|
||||||
@@ -133,6 +199,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.OK).json(response);
|
res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('revokeInviteCode'), ...guards, async (req, res) => {
|
.put(this.routerPath('revokeInviteCode'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in revokeInviteCode');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupJid>({
|
const response = await this.groupValidate<GroupJid>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: groupJidSchema,
|
schema: groupJidSchema,
|
||||||
@@ -143,6 +215,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('updateParticipant'), ...guards, async (req, res) => {
|
.put(this.routerPath('updateParticipant'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateParticipant');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupUpdateParticipantDto>({
|
const response = await this.groupValidate<GroupUpdateParticipantDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: updateParticipantsSchema,
|
schema: updateParticipantsSchema,
|
||||||
@@ -153,6 +231,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('updateSetting'), ...guards, async (req, res) => {
|
.put(this.routerPath('updateSetting'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in updateSetting');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupUpdateSettingDto>({
|
const response = await this.groupValidate<GroupUpdateSettingDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: updateSettingsSchema,
|
schema: updateSettingsSchema,
|
||||||
@@ -163,6 +247,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('toggleEphemeral'), ...guards, async (req, res) => {
|
.put(this.routerPath('toggleEphemeral'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in toggleEphemeral');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupToggleEphemeralDto>({
|
const response = await this.groupValidate<GroupToggleEphemeralDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: toggleEphemeralSchema,
|
schema: toggleEphemeralSchema,
|
||||||
@@ -173,6 +263,12 @@ export class GroupRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.delete(this.routerPath('leaveGroup'), ...guards, async (req, res) => {
|
.delete(this.routerPath('leaveGroup'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in leaveGroup');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.groupValidate<GroupJid>({
|
const response = await this.groupValidate<GroupJid>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: {},
|
schema: {},
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import { InstanceRouter } from './instance.router';
|
|||||||
import { MessageRouter } from './sendMessage.router';
|
import { MessageRouter } from './sendMessage.router';
|
||||||
import { ViewsRouter } from './view.router';
|
import { ViewsRouter } from './view.router';
|
||||||
import { WebhookRouter } from './webhook.router';
|
import { WebhookRouter } from './webhook.router';
|
||||||
|
import { ChatwootRouter } from './chatwoot.router';
|
||||||
|
import fs from 'fs';
|
||||||
|
import { SettingsRouter } from './settings.router';
|
||||||
|
|
||||||
enum HttpStatus {
|
enum HttpStatus {
|
||||||
OK = 200,
|
OK = 200,
|
||||||
@@ -23,7 +26,16 @@ const router = Router();
|
|||||||
const authType = configService.get<Auth>('AUTHENTICATION').TYPE;
|
const authType = configService.get<Auth>('AUTHENTICATION').TYPE;
|
||||||
const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard[authType]];
|
const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard[authType]];
|
||||||
|
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||||
|
|
||||||
router
|
router
|
||||||
|
.get('/', (req, res) => {
|
||||||
|
res.status(HttpStatus.OK).json({
|
||||||
|
status: HttpStatus.OK,
|
||||||
|
message: 'Welcome to the Evolution API, it is working!',
|
||||||
|
version: packageJson.version,
|
||||||
|
});
|
||||||
|
})
|
||||||
.use(
|
.use(
|
||||||
'/instance',
|
'/instance',
|
||||||
new InstanceRouter(configService, ...guards).router,
|
new InstanceRouter(configService, ...guards).router,
|
||||||
@@ -32,6 +44,8 @@ router
|
|||||||
.use('/message', new MessageRouter(...guards).router)
|
.use('/message', new MessageRouter(...guards).router)
|
||||||
.use('/chat', new ChatRouter(...guards).router)
|
.use('/chat', new ChatRouter(...guards).router)
|
||||||
.use('/group', new GroupRouter(...guards).router)
|
.use('/group', new GroupRouter(...guards).router)
|
||||||
.use('/webhook', new WebhookRouter(...guards).router);
|
.use('/webhook', new WebhookRouter(...guards).router)
|
||||||
|
.use('/chatwoot', new ChatwootRouter(...guards).router)
|
||||||
|
.use('/settings', new SettingsRouter(...guards).router);
|
||||||
|
|
||||||
export { router, HttpStatus };
|
export { router, HttpStatus };
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import { HttpStatus } from './index.router';
|
|||||||
import { OldToken } from '../services/auth.service';
|
import { OldToken } from '../services/auth.service';
|
||||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||||
import { dbserver } from '../../db/db.connect';
|
import { dbserver } from '../../db/db.connect';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('InstanceRouter');
|
||||||
|
|
||||||
export class InstanceRouter extends RouterBroker {
|
export class InstanceRouter extends RouterBroker {
|
||||||
constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) {
|
constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) {
|
||||||
@@ -14,6 +17,13 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
const auth = configService.get<Auth>('AUTHENTICATION');
|
const auth = configService.get<Auth>('AUTHENTICATION');
|
||||||
this.router
|
this.router
|
||||||
.post('/create', ...guards, async (req, res) => {
|
.post('/create', ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in createInstance');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
@@ -24,6 +34,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.put(this.routerPath('restart'), ...guards, async (req, res) => {
|
.put(this.routerPath('restart'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in restartInstance');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
@@ -34,6 +50,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('connect'), ...guards, async (req, res) => {
|
.get(this.routerPath('connect'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in connectInstance');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
@@ -44,6 +66,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('connectionState'), ...guards, async (req, res) => {
|
.get(this.routerPath('connectionState'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in connectionState');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
@@ -54,6 +82,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('fetchInstances', false), ...guards, async (req, res) => {
|
.get(this.routerPath('fetchInstances', false), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in fetchInstances');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: null,
|
schema: null,
|
||||||
@@ -64,6 +98,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.delete(this.routerPath('logout'), ...guards, async (req, res) => {
|
.delete(this.routerPath('logout'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in logoutInstances');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
@@ -74,6 +114,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
.delete(this.routerPath('delete'), ...guards, async (req, res) => {
|
.delete(this.routerPath('delete'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in deleteInstances');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
@@ -86,6 +132,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
|
|
||||||
if (auth.TYPE === 'jwt') {
|
if (auth.TYPE === 'jwt') {
|
||||||
this.router.put('/refreshToken', async (req, res) => {
|
this.router.put('/refreshToken', async (req, res) => {
|
||||||
|
logger.verbose('request received in refreshToken');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<OldToken>({
|
const response = await this.dataValidate<OldToken>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: oldTokenSchema,
|
schema: oldTokenSchema,
|
||||||
@@ -98,6 +150,12 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.router.delete('/deleteDatabase', async (req, res) => {
|
this.router.delete('/deleteDatabase', async (req, res) => {
|
||||||
|
logger.verbose('request received in deleteDatabase');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const db = this.configService.get<Database>('DATABASE');
|
const db = this.configService.get<Database>('DATABASE');
|
||||||
if (db.ENABLED) {
|
if (db.ENABLED) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import {
|
|||||||
audioMessageSchema,
|
audioMessageSchema,
|
||||||
buttonMessageSchema,
|
buttonMessageSchema,
|
||||||
contactMessageSchema,
|
contactMessageSchema,
|
||||||
linkPreviewSchema,
|
|
||||||
listMessageSchema,
|
listMessageSchema,
|
||||||
locationMessageSchema,
|
locationMessageSchema,
|
||||||
mediaMessageSchema,
|
mediaMessageSchema,
|
||||||
pollMessageSchema,
|
pollMessageSchema,
|
||||||
reactionMessageSchema,
|
reactionMessageSchema,
|
||||||
|
statusMessageSchema,
|
||||||
stickerMessageSchema,
|
stickerMessageSchema,
|
||||||
textMessageSchema,
|
textMessageSchema,
|
||||||
} from '../../validate/validate.schema';
|
} from '../../validate/validate.schema';
|
||||||
@@ -16,24 +16,33 @@ import {
|
|||||||
SendAudioDto,
|
SendAudioDto,
|
||||||
SendButtonDto,
|
SendButtonDto,
|
||||||
SendContactDto,
|
SendContactDto,
|
||||||
SendLinkPreviewDto,
|
|
||||||
SendListDto,
|
SendListDto,
|
||||||
SendLocationDto,
|
SendLocationDto,
|
||||||
SendMediaDto,
|
SendMediaDto,
|
||||||
SendPollDto,
|
SendPollDto,
|
||||||
SendReactionDto,
|
SendReactionDto,
|
||||||
|
SendStatusDto,
|
||||||
SendStickerDto,
|
SendStickerDto,
|
||||||
SendTextDto,
|
SendTextDto,
|
||||||
} from '../dto/sendMessage.dto';
|
} from '../dto/sendMessage.dto';
|
||||||
import { sendMessageController } from '../whatsapp.module';
|
import { sendMessageController } from '../whatsapp.module';
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import { HttpStatus } from './index.router';
|
import { HttpStatus } from './index.router';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('MessageRouter');
|
||||||
|
|
||||||
export class MessageRouter extends RouterBroker {
|
export class MessageRouter extends RouterBroker {
|
||||||
constructor(...guards: RequestHandler[]) {
|
constructor(...guards: RequestHandler[]) {
|
||||||
super();
|
super();
|
||||||
this.router
|
this.router
|
||||||
.post(this.routerPath('sendText'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendText'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendText');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendTextDto>({
|
const response = await this.dataValidate<SendTextDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: textMessageSchema,
|
schema: textMessageSchema,
|
||||||
@@ -44,6 +53,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendMedia'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendMedia'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendMedia');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendMediaDto>({
|
const response = await this.dataValidate<SendMediaDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: mediaMessageSchema,
|
schema: mediaMessageSchema,
|
||||||
@@ -54,6 +69,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendWhatsAppAudio'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendWhatsAppAudio'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendWhatsAppAudio');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendAudioDto>({
|
const response = await this.dataValidate<SendAudioDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: audioMessageSchema,
|
schema: audioMessageSchema,
|
||||||
@@ -65,6 +86,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendButtons'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendButtons'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendButtons');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendButtonDto>({
|
const response = await this.dataValidate<SendButtonDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: buttonMessageSchema,
|
schema: buttonMessageSchema,
|
||||||
@@ -75,6 +102,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendLocation'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendLocation'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendLocation');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendLocationDto>({
|
const response = await this.dataValidate<SendLocationDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: locationMessageSchema,
|
schema: locationMessageSchema,
|
||||||
@@ -85,6 +118,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendList'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendList'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendList');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendListDto>({
|
const response = await this.dataValidate<SendListDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: listMessageSchema,
|
schema: listMessageSchema,
|
||||||
@@ -95,6 +134,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendContact'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendContact'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendContact');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendContactDto>({
|
const response = await this.dataValidate<SendContactDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: contactMessageSchema,
|
schema: contactMessageSchema,
|
||||||
@@ -105,6 +150,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendReaction'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendReaction'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendReaction');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendReactionDto>({
|
const response = await this.dataValidate<SendReactionDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: reactionMessageSchema,
|
schema: reactionMessageSchema,
|
||||||
@@ -115,6 +166,12 @@ export class MessageRouter extends RouterBroker {
|
|||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendPoll'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendPoll'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendPoll');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendPollDto>({
|
const response = await this.dataValidate<SendPollDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: pollMessageSchema,
|
schema: pollMessageSchema,
|
||||||
@@ -124,18 +181,29 @@ export class MessageRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendLinkPreview'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendStatus'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<SendLinkPreviewDto>({
|
logger.verbose('request received in sendStatus');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.dataValidate<SendStatusDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: linkPreviewSchema,
|
schema: statusMessageSchema,
|
||||||
ClassRef: SendLinkPreviewDto,
|
ClassRef: SendStatusDto,
|
||||||
execute: (instance, data) =>
|
execute: (instance, data) => sendMessageController.sendStatus(instance, data),
|
||||||
sendMessageController.sendLinkPreview(instance, data),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.post(this.routerPath('sendSticker'), ...guards, async (req, res) => {
|
.post(this.routerPath('sendSticker'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in sendSticker');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<SendStickerDto>({
|
const response = await this.dataValidate<SendStickerDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: stickerMessageSchema,
|
schema: stickerMessageSchema,
|
||||||
|
|||||||
52
src/whatsapp/routers/settings.router.ts
Normal file
52
src/whatsapp/routers/settings.router.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { RequestHandler, Router } from 'express';
|
||||||
|
import { instanceNameSchema, settingsSchema } from '../../validate/validate.schema';
|
||||||
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { SettingsDto } from '../dto/settings.dto';
|
||||||
|
import { settingsController } from '../whatsapp.module';
|
||||||
|
import { SettingsService } from '../services/settings.service';
|
||||||
|
import { HttpStatus } from './index.router';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('SettingsRouter');
|
||||||
|
|
||||||
|
export class SettingsRouter extends RouterBroker {
|
||||||
|
constructor(...guards: RequestHandler[]) {
|
||||||
|
super();
|
||||||
|
this.router
|
||||||
|
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in setSettings');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.dataValidate<SettingsDto>({
|
||||||
|
request: req,
|
||||||
|
schema: settingsSchema,
|
||||||
|
ClassRef: SettingsDto,
|
||||||
|
execute: (instance, data) => settingsController.createSettings(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
|
})
|
||||||
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findSettings');
|
||||||
|
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) => settingsController.findSettings(instance),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly router = Router();
|
||||||
|
}
|
||||||
@@ -5,12 +5,21 @@ import { InstanceDto } from '../dto/instance.dto';
|
|||||||
import { WebhookDto } from '../dto/webhook.dto';
|
import { WebhookDto } from '../dto/webhook.dto';
|
||||||
import { webhookController } from '../whatsapp.module';
|
import { webhookController } from '../whatsapp.module';
|
||||||
import { HttpStatus } from './index.router';
|
import { HttpStatus } from './index.router';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
const logger = new Logger('WebhookRouter');
|
||||||
|
|
||||||
export class WebhookRouter extends RouterBroker {
|
export class WebhookRouter extends RouterBroker {
|
||||||
constructor(...guards: RequestHandler[]) {
|
constructor(...guards: RequestHandler[]) {
|
||||||
super();
|
super();
|
||||||
this.router
|
this.router
|
||||||
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in setWebhook');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<WebhookDto>({
|
const response = await this.dataValidate<WebhookDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: webhookSchema,
|
schema: webhookSchema,
|
||||||
@@ -21,6 +30,12 @@ export class WebhookRouter extends RouterBroker {
|
|||||||
res.status(HttpStatus.CREATED).json(response);
|
res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in findWebhook');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
|
|||||||
1671
src/whatsapp/services/chatwoot.service.ts
Normal file
1671
src/whatsapp/services/chatwoot.service.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
import { opendirSync, readdirSync, rmSync } from 'fs';
|
import { opendirSync, readdirSync, rmSync } from 'fs';
|
||||||
import { WAStartupService } from './whatsapp.service';
|
import { WAStartupService } from './whatsapp.service';
|
||||||
import { INSTANCE_DIR } from '../../config/path.config';
|
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
|
||||||
import EventEmitter2 from 'eventemitter2';
|
import EventEmitter2 from 'eventemitter2';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
@@ -9,13 +9,25 @@ import {
|
|||||||
ConfigService,
|
ConfigService,
|
||||||
Database,
|
Database,
|
||||||
DelInstance,
|
DelInstance,
|
||||||
|
HttpServer,
|
||||||
Redis,
|
Redis,
|
||||||
} from '../../config/env.config';
|
} from '../../config/env.config';
|
||||||
import { RepositoryBroker } from '../repository/repository.manager';
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
import { NotFoundException } from '../../exceptions';
|
import { NotFoundException } from '../../exceptions';
|
||||||
import { Db } from 'mongodb';
|
import { Db } from 'mongodb';
|
||||||
import { initInstance } from '../whatsapp.module';
|
|
||||||
import { RedisCache } from '../../db/redis.client';
|
import { RedisCache } from '../../db/redis.client';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
import { dbserver } from '../../db/db.connect';
|
||||||
|
import mongoose from 'mongoose';
|
||||||
|
import {
|
||||||
|
AuthModel,
|
||||||
|
ChatwootModel,
|
||||||
|
ContactModel,
|
||||||
|
MessageModel,
|
||||||
|
MessageUpModel,
|
||||||
|
SettingsModel,
|
||||||
|
WebhookModel,
|
||||||
|
} from '../models';
|
||||||
|
|
||||||
export class WAMonitoringService {
|
export class WAMonitoringService {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -43,6 +55,8 @@ export class WAMonitoringService {
|
|||||||
|
|
||||||
private dbInstance: Db;
|
private dbInstance: Db;
|
||||||
|
|
||||||
|
private dbStore = dbserver;
|
||||||
|
|
||||||
private readonly logger = new Logger(WAMonitoringService.name);
|
private readonly logger = new Logger(WAMonitoringService.name);
|
||||||
public readonly waInstances: Record<string, WAStartupService> = {};
|
public readonly waInstances: Record<string, WAStartupService> = {};
|
||||||
|
|
||||||
@@ -82,70 +96,69 @@ export class WAMonitoringService {
|
|||||||
for await (const [key, value] of Object.entries(this.waInstances)) {
|
for await (const [key, value] of Object.entries(this.waInstances)) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.logger.verbose('get instance info: ' + key);
|
this.logger.verbose('get instance info: ' + key);
|
||||||
|
let chatwoot: any;
|
||||||
|
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
const findChatwoot = await this.waInstances[key].findChatwoot();
|
||||||
|
|
||||||
|
if (findChatwoot && findChatwoot.enabled) {
|
||||||
|
chatwoot = {
|
||||||
|
...findChatwoot,
|
||||||
|
webhook_url: `${urlServer}/chatwoot/webhook/${key}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (value.connectionStatus.state === 'open') {
|
if (value.connectionStatus.state === 'open') {
|
||||||
this.logger.verbose('instance: ' + key + ' - connectionStatus: open');
|
this.logger.verbose('instance: ' + key + ' - connectionStatus: open');
|
||||||
let apikey: string;
|
|
||||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
|
||||||
this.logger.verbose(
|
|
||||||
'instance: ' + key + ' - hash exposed in fetch instances',
|
|
||||||
);
|
|
||||||
const tokenStore = await this.repository.auth.find(key);
|
|
||||||
apikey = tokenStore.apikey || 'Apikey not found';
|
|
||||||
|
|
||||||
instances.push({
|
const instanceData = {
|
||||||
instance: {
|
instance: {
|
||||||
instanceName: key,
|
instanceName: key,
|
||||||
owner: value.wuid,
|
owner: value.wuid,
|
||||||
profileName: (await value.getProfileName()) || 'not loaded',
|
profileName: (await value.getProfileName()) || 'not loaded',
|
||||||
profilePictureUrl: value.profilePictureUrl,
|
profilePictureUrl: value.profilePictureUrl,
|
||||||
status: (await value.getProfileStatus()) || '',
|
profileStatus: (await value.getProfileStatus()) || '',
|
||||||
apikey,
|
status: value.connectionStatus.state,
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
} else {
|
|
||||||
this.logger.verbose(
|
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||||
'instance: ' + key + ' - hash not exposed in fetch instances',
|
instanceData.instance['serverUrl'] =
|
||||||
);
|
this.configService.get<HttpServer>('SERVER').URL;
|
||||||
instances.push({
|
|
||||||
instance: {
|
instanceData.instance['apikey'] = (
|
||||||
instanceName: key,
|
await this.repository.auth.find(key)
|
||||||
owner: value.wuid,
|
).apikey;
|
||||||
profileName: (await value.getProfileName()) || 'not loaded',
|
|
||||||
profilePictureUrl: value.profilePictureUrl,
|
instanceData.instance['chatwoot'] = chatwoot;
|
||||||
status: (await value.getProfileStatus()) || '',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instances.push(instanceData);
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
'instance: ' + key + ' - connectionStatus: ' + value.connectionStatus.state,
|
'instance: ' + key + ' - connectionStatus: ' + value.connectionStatus.state,
|
||||||
);
|
);
|
||||||
let apikey: string;
|
|
||||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
|
||||||
this.logger.verbose(
|
|
||||||
'instance: ' + key + ' - hash exposed in fetch instances',
|
|
||||||
);
|
|
||||||
const tokenStore = await this.repository.auth.find(key);
|
|
||||||
apikey = tokenStore.apikey || 'Apikey not found';
|
|
||||||
|
|
||||||
instances.push({
|
const instanceData = {
|
||||||
instance: {
|
|
||||||
instanceName: key,
|
|
||||||
status: value.connectionStatus.state,
|
|
||||||
apikey,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.logger.verbose(
|
|
||||||
'instance: ' + key + ' - hash not exposed in fetch instances',
|
|
||||||
);
|
|
||||||
instances.push({
|
|
||||||
instance: {
|
instance: {
|
||||||
instanceName: key,
|
instanceName: key,
|
||||||
status: value.connectionStatus.state,
|
status: value.connectionStatus.state,
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||||
|
instanceData.instance['serverUrl'] =
|
||||||
|
this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
instanceData.instance['apikey'] = (
|
||||||
|
await this.repository.auth.find(key)
|
||||||
|
).apikey;
|
||||||
|
|
||||||
|
instanceData.instance['chatwoot'] = chatwoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instances.push(instanceData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,6 +229,38 @@ export class WAMonitoringService {
|
|||||||
rmSync(join(INSTANCE_DIR, instanceName), { recursive: true, force: true });
|
rmSync(join(INSTANCE_DIR, instanceName), { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async cleaningStoreFiles(instanceName: string) {
|
||||||
|
if (!this.db.ENABLED) {
|
||||||
|
this.logger.verbose('cleaning store files instance: ' + instanceName);
|
||||||
|
rmSync(join(INSTANCE_DIR, instanceName), { recursive: true, force: true });
|
||||||
|
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'chats', instanceName)}`);
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'contacts', instanceName)}`);
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'message-up', instanceName)}`);
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'messages', instanceName)}`);
|
||||||
|
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'auth', 'apikey', instanceName + '.json')}`);
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'webhook', instanceName + '.json')}`);
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'chatwoot', instanceName + '*')}`);
|
||||||
|
execSync(`rm -rf ${join(STORE_DIR, 'settings', instanceName + '*')}`);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('cleaning store database instance: ' + instanceName);
|
||||||
|
|
||||||
|
await AuthModel.deleteMany({ owner: instanceName });
|
||||||
|
await ContactModel.deleteMany({ owner: instanceName });
|
||||||
|
await MessageModel.deleteMany({ owner: instanceName });
|
||||||
|
await MessageUpModel.deleteMany({ owner: instanceName });
|
||||||
|
await AuthModel.deleteMany({ _id: instanceName });
|
||||||
|
await WebhookModel.deleteMany({ _id: instanceName });
|
||||||
|
await ChatwootModel.deleteMany({ _id: instanceName });
|
||||||
|
await SettingsModel.deleteMany({ _id: instanceName });
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public async loadInstance() {
|
public async loadInstance() {
|
||||||
this.logger.verbose('load instances');
|
this.logger.verbose('load instances');
|
||||||
const set = async (name: string) => {
|
const set = async (name: string) => {
|
||||||
@@ -244,7 +289,6 @@ export class WAMonitoringService {
|
|||||||
keys.forEach(async (k) => await set(k.split(':')[1]));
|
keys.forEach(async (k) => await set(k.split(':')[1]));
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('no instance keys found');
|
this.logger.verbose('no instance keys found');
|
||||||
initInstance();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -260,7 +304,6 @@ export class WAMonitoringService {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('no collections found');
|
this.logger.verbose('no collections found');
|
||||||
initInstance();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -281,7 +324,6 @@ export class WAMonitoringService {
|
|||||||
await set(dirent.name);
|
await set(dirent.name);
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('no instance files found');
|
this.logger.verbose('no instance files found');
|
||||||
initInstance();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -300,6 +342,7 @@ export class WAMonitoringService {
|
|||||||
try {
|
try {
|
||||||
this.logger.verbose('request cleaning up instance: ' + instanceName);
|
this.logger.verbose('request cleaning up instance: ' + instanceName);
|
||||||
this.cleaningUp(instanceName);
|
this.cleaningUp(instanceName);
|
||||||
|
this.cleaningStoreFiles(instanceName);
|
||||||
} finally {
|
} finally {
|
||||||
this.logger.warn(`Instance "${instanceName}" - REMOVED`);
|
this.logger.warn(`Instance "${instanceName}" - REMOVED`);
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/whatsapp/services/settings.service.ts
Normal file
34
src/whatsapp/services/settings.service.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
import { SettingsDto } from '../dto/settings.dto';
|
||||||
|
import { WAMonitoringService } from './monitor.service';
|
||||||
|
import { Logger } from '../../config/logger.config';
|
||||||
|
|
||||||
|
export class SettingsService {
|
||||||
|
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||||
|
|
||||||
|
private readonly logger = new Logger(SettingsService.name);
|
||||||
|
|
||||||
|
public create(instance: InstanceDto, data: SettingsDto) {
|
||||||
|
this.logger.verbose('create settings: ' + instance.instanceName);
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].setSettings(data);
|
||||||
|
|
||||||
|
return { settings: { ...instance, settings: data } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public async find(instance: InstanceDto): Promise<SettingsDto> {
|
||||||
|
try {
|
||||||
|
this.logger.verbose('find settings: ' + instance.instanceName);
|
||||||
|
const result = await this.waMonitor.waInstances[
|
||||||
|
instance.instanceName
|
||||||
|
].findSettings();
|
||||||
|
|
||||||
|
if (Object.keys(result).length === 0) {
|
||||||
|
throw new Error('Settings not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
return { reject_call: false, msg_call: '', groups_ignore: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,9 +18,17 @@ export class WebhookService {
|
|||||||
public async find(instance: InstanceDto): Promise<WebhookDto> {
|
public async find(instance: InstanceDto): Promise<WebhookDto> {
|
||||||
try {
|
try {
|
||||||
this.logger.verbose('find webhook: ' + instance.instanceName);
|
this.logger.verbose('find webhook: ' + instance.instanceName);
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].findWebhook();
|
const result = await this.waMonitor.waInstances[
|
||||||
|
instance.instanceName
|
||||||
|
].findWebhook();
|
||||||
|
|
||||||
|
if (Object.keys(result).length === 0) {
|
||||||
|
throw new Error('Webhook not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { enabled: null, url: '' };
|
return { enabled: false, url: '', events: [], webhook_by_events: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,8 @@ export enum Events {
|
|||||||
MESSAGES_SET = 'messages.set',
|
MESSAGES_SET = 'messages.set',
|
||||||
MESSAGES_UPSERT = 'messages.upsert',
|
MESSAGES_UPSERT = 'messages.upsert',
|
||||||
MESSAGES_UPDATE = 'messages.update',
|
MESSAGES_UPDATE = 'messages.update',
|
||||||
|
MESSAGES_DELETE = 'messages.delete',
|
||||||
|
SEND_MESSAGE = 'send.message',
|
||||||
CONTACTS_SET = 'contacts.set',
|
CONTACTS_SET = 'contacts.set',
|
||||||
CONTACTS_UPSERT = 'contacts.upsert',
|
CONTACTS_UPSERT = 'contacts.upsert',
|
||||||
CONTACTS_UPDATE = 'contacts.update',
|
CONTACTS_UPDATE = 'contacts.update',
|
||||||
@@ -20,12 +22,19 @@ export enum Events {
|
|||||||
GROUPS_UPSERT = 'groups.upsert',
|
GROUPS_UPSERT = 'groups.upsert',
|
||||||
GROUPS_UPDATE = 'groups.update',
|
GROUPS_UPDATE = 'groups.update',
|
||||||
GROUP_PARTICIPANTS_UPDATE = 'group-participants.update',
|
GROUP_PARTICIPANTS_UPDATE = 'group-participants.update',
|
||||||
|
CALL = 'call',
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare namespace wa {
|
export declare namespace wa {
|
||||||
export type QrCode = { count?: number; base64?: string; code?: string };
|
export type QrCode = {
|
||||||
|
count?: number;
|
||||||
|
pairingCode?: string;
|
||||||
|
base64?: string;
|
||||||
|
code?: string;
|
||||||
|
};
|
||||||
export type Instance = {
|
export type Instance = {
|
||||||
qrcode?: QrCode;
|
qrcode?: QrCode;
|
||||||
|
pairingCode?: string;
|
||||||
authState?: { state: AuthenticationState; saveCreds: () => void };
|
authState?: { state: AuthenticationState; saveCreds: () => void };
|
||||||
name?: string;
|
name?: string;
|
||||||
wuid?: string;
|
wuid?: string;
|
||||||
@@ -40,6 +49,27 @@ export declare namespace wa {
|
|||||||
webhook_by_events?: boolean;
|
webhook_by_events?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LocalChatwoot = {
|
||||||
|
enabled?: boolean;
|
||||||
|
account_id?: string;
|
||||||
|
token?: string;
|
||||||
|
url?: string;
|
||||||
|
name_inbox?: string;
|
||||||
|
sign_msg?: boolean;
|
||||||
|
number?: string;
|
||||||
|
reopen_conversation?: boolean;
|
||||||
|
conversation_pending?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LocalSettings = {
|
||||||
|
reject_call?: boolean;
|
||||||
|
msg_call?: string;
|
||||||
|
groups_ignore?: boolean;
|
||||||
|
always_online?: boolean;
|
||||||
|
read_messages?: boolean;
|
||||||
|
read_status?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type StateConnection = {
|
export type StateConnection = {
|
||||||
instance?: string;
|
instance?: string;
|
||||||
state?: WAConnectionState | 'refused';
|
state?: WAConnectionState | 'refused';
|
||||||
@@ -52,6 +82,7 @@ export declare namespace wa {
|
|||||||
| 'SERVER_ACK'
|
| 'SERVER_ACK'
|
||||||
| 'DELIVERY_ACK'
|
| 'DELIVERY_ACK'
|
||||||
| 'READ'
|
| 'READ'
|
||||||
|
| 'DELETED'
|
||||||
| 'PLAYED';
|
| 'PLAYED';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import { GroupController } from './controllers/group.controller';
|
|||||||
import { ViewsController } from './controllers/views.controller';
|
import { ViewsController } from './controllers/views.controller';
|
||||||
import { WebhookService } from './services/webhook.service';
|
import { WebhookService } from './services/webhook.service';
|
||||||
import { WebhookController } from './controllers/webhook.controller';
|
import { WebhookController } from './controllers/webhook.controller';
|
||||||
|
import { ChatwootService } from './services/chatwoot.service';
|
||||||
|
import { ChatwootController } from './controllers/chatwoot.controller';
|
||||||
import { RepositoryBroker } from './repository/repository.manager';
|
import { RepositoryBroker } from './repository/repository.manager';
|
||||||
import {
|
import {
|
||||||
AuthModel,
|
AuthModel,
|
||||||
@@ -21,15 +23,21 @@ import {
|
|||||||
ContactModel,
|
ContactModel,
|
||||||
MessageModel,
|
MessageModel,
|
||||||
MessageUpModel,
|
MessageUpModel,
|
||||||
|
ChatwootModel,
|
||||||
|
WebhookModel,
|
||||||
|
SettingsModel,
|
||||||
} from './models';
|
} from './models';
|
||||||
import { dbserver } from '../db/db.connect';
|
import { dbserver } from '../db/db.connect';
|
||||||
import { WebhookRepository } from './repository/webhook.repository';
|
import { WebhookRepository } from './repository/webhook.repository';
|
||||||
import { WebhookModel } from './models/webhook.model';
|
import { ChatwootRepository } from './repository/chatwoot.repository';
|
||||||
import { AuthRepository } from './repository/auth.repository';
|
import { AuthRepository } from './repository/auth.repository';
|
||||||
import { WAStartupService } from './services/whatsapp.service';
|
import { WAStartupService } from './services/whatsapp.service';
|
||||||
import { delay } from '@whiskeysockets/baileys';
|
import { delay } from '@whiskeysockets/baileys';
|
||||||
import { Events } from './types/wa.types';
|
import { Events } from './types/wa.types';
|
||||||
import { RedisCache } from '../db/redis.client';
|
import { RedisCache } from '../db/redis.client';
|
||||||
|
import { SettingsRepository } from './repository/settings.repository';
|
||||||
|
import { SettingsService } from './services/settings.service';
|
||||||
|
import { SettingsController } from './controllers/settings.controller';
|
||||||
|
|
||||||
const logger = new Logger('WA MODULE');
|
const logger = new Logger('WA MODULE');
|
||||||
|
|
||||||
@@ -38,6 +46,8 @@ const chatRepository = new ChatRepository(ChatModel, configService);
|
|||||||
const contactRepository = new ContactRepository(ContactModel, configService);
|
const contactRepository = new ContactRepository(ContactModel, configService);
|
||||||
const messageUpdateRepository = new MessageUpRepository(MessageUpModel, configService);
|
const messageUpdateRepository = new MessageUpRepository(MessageUpModel, configService);
|
||||||
const webhookRepository = new WebhookRepository(WebhookModel, configService);
|
const webhookRepository = new WebhookRepository(WebhookModel, configService);
|
||||||
|
const chatwootRepository = new ChatwootRepository(ChatwootModel, configService);
|
||||||
|
const settingsRepository = new SettingsRepository(SettingsModel, configService);
|
||||||
const authRepository = new AuthRepository(AuthModel, configService);
|
const authRepository = new AuthRepository(AuthModel, configService);
|
||||||
|
|
||||||
export const repository = new RepositoryBroker(
|
export const repository = new RepositoryBroker(
|
||||||
@@ -46,6 +56,8 @@ export const repository = new RepositoryBroker(
|
|||||||
contactRepository,
|
contactRepository,
|
||||||
messageUpdateRepository,
|
messageUpdateRepository,
|
||||||
webhookRepository,
|
webhookRepository,
|
||||||
|
chatwootRepository,
|
||||||
|
settingsRepository,
|
||||||
authRepository,
|
authRepository,
|
||||||
configService,
|
configService,
|
||||||
dbserver?.getClient(),
|
dbserver?.getClient(),
|
||||||
@@ -66,6 +78,14 @@ const webhookService = new WebhookService(waMonitor);
|
|||||||
|
|
||||||
export const webhookController = new WebhookController(webhookService);
|
export const webhookController = new WebhookController(webhookService);
|
||||||
|
|
||||||
|
const chatwootService = new ChatwootService(waMonitor, configService);
|
||||||
|
|
||||||
|
export const chatwootController = new ChatwootController(chatwootService, configService);
|
||||||
|
|
||||||
|
const settingsService = new SettingsService(waMonitor);
|
||||||
|
|
||||||
|
export const settingsController = new SettingsController(settingsService);
|
||||||
|
|
||||||
export const instanceController = new InstanceController(
|
export const instanceController = new InstanceController(
|
||||||
waMonitor,
|
waMonitor,
|
||||||
configService,
|
configService,
|
||||||
@@ -73,6 +93,8 @@ export const instanceController = new InstanceController(
|
|||||||
eventEmitter,
|
eventEmitter,
|
||||||
authService,
|
authService,
|
||||||
webhookService,
|
webhookService,
|
||||||
|
chatwootService,
|
||||||
|
settingsService,
|
||||||
cache,
|
cache,
|
||||||
);
|
);
|
||||||
export const viewsController = new ViewsController(waMonitor, configService);
|
export const viewsController = new ViewsController(waMonitor, configService);
|
||||||
@@ -80,84 +102,4 @@ 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);
|
||||||
|
|
||||||
export async function initInstance() {
|
|
||||||
const instance = new WAStartupService(configService, eventEmitter, repository, cache);
|
|
||||||
|
|
||||||
const mode = configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
|
||||||
|
|
||||||
logger.verbose('Sending data webhook for event: ' + Events.APPLICATION_STARTUP);
|
|
||||||
instance.sendDataWebhook(
|
|
||||||
Events.APPLICATION_STARTUP,
|
|
||||||
{
|
|
||||||
message: 'Application startup',
|
|
||||||
mode,
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (mode === 'container') {
|
|
||||||
logger.verbose('Application startup in container mode');
|
|
||||||
|
|
||||||
const instanceName = configService.get<Auth>('AUTHENTICATION').INSTANCE.NAME;
|
|
||||||
logger.verbose('Instance name: ' + instanceName);
|
|
||||||
|
|
||||||
const instanceWebhook =
|
|
||||||
configService.get<Auth>('AUTHENTICATION').INSTANCE.WEBHOOK_URL;
|
|
||||||
logger.verbose('Instance webhook: ' + instanceWebhook);
|
|
||||||
|
|
||||||
instance.instanceName = instanceName;
|
|
||||||
|
|
||||||
waMonitor.waInstances[instance.instanceName] = instance;
|
|
||||||
waMonitor.delInstanceTime(instance.instanceName);
|
|
||||||
|
|
||||||
const hash = await authService.generateHash({
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
token: configService.get<Auth>('AUTHENTICATION').API_KEY.KEY,
|
|
||||||
});
|
|
||||||
logger.verbose('Hash generated: ' + hash);
|
|
||||||
|
|
||||||
if (instanceWebhook) {
|
|
||||||
logger.verbose('Creating webhook for instance: ' + instanceName);
|
|
||||||
try {
|
|
||||||
webhookService.create(instance, { enabled: true, url: instanceWebhook });
|
|
||||||
logger.verbose('Webhook created');
|
|
||||||
} catch (error) {
|
|
||||||
logger.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const state = instance.connectionStatus?.state;
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case 'close':
|
|
||||||
await instance.connectToWhatsapp();
|
|
||||||
await delay(2000);
|
|
||||||
return instance.qrCode;
|
|
||||||
case 'connecting':
|
|
||||||
return instance.qrCode;
|
|
||||||
default:
|
|
||||||
return await this.connectionState({ instanceName });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
instance: {
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
status: 'created',
|
|
||||||
},
|
|
||||||
hash,
|
|
||||||
webhook: instanceWebhook,
|
|
||||||
};
|
|
||||||
|
|
||||||
logger.info(result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Module - ON');
|
logger.info('Module - ON');
|
||||||
|
|||||||
Reference in New Issue
Block a user