mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 03:42:23 -06:00
Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05b5ae8a84 | ||
|
|
2e9c14a0a8 | ||
|
|
3350cec589 | ||
|
|
bd7a42646b | ||
|
|
2ae4ddee18 | ||
|
|
2fb6e2b209 | ||
|
|
91f869b136 | ||
|
|
1284a97625 | ||
|
|
3a5cfbf36f | ||
|
|
47b8ecd43b | ||
|
|
25ce1a4689 | ||
|
|
a5156709ab | ||
|
|
fd2d37d862 | ||
|
|
87bf433e9a | ||
|
|
b5ec79daae | ||
|
|
3b19200997 | ||
|
|
0ab040080c | ||
|
|
5719896d18 | ||
|
|
e9e1cb6ebc | ||
|
|
ceee6a7e74 | ||
|
|
ebfc6d4fa5 | ||
|
|
0d62557a15 | ||
|
|
097c09328f | ||
|
|
732103292b | ||
|
|
3191e9b450 | ||
|
|
bf88fdbb31 | ||
|
|
4c3fb5e762 | ||
|
|
e4b6f4ff0d | ||
|
|
ca0b0d4602 | ||
|
|
d7c3779ff7 | ||
|
|
f0d40eea15 | ||
|
|
68dcc1c86a | ||
|
|
f7dcab3736 | ||
|
|
2fcb476c50 | ||
|
|
44a7cd62c8 | ||
|
|
f7f0f8251b | ||
|
|
395b81a6ac | ||
|
|
da06ed1185 | ||
|
|
67afbd6a77 | ||
|
|
8fce53b4af | ||
|
|
65bba23519 | ||
|
|
283b497788 | ||
|
|
8cc1b8daa8 | ||
|
|
9ccdb45a7a | ||
|
|
f78d360c38 | ||
|
|
6144fbe856 | ||
|
|
8446be7646 | ||
|
|
8875ab1e93 | ||
|
|
7c207a50e1 | ||
|
|
dcc32479ff | ||
|
|
09911c472d | ||
|
|
7a0149ee23 | ||
|
|
3ae8cf32b0 | ||
|
|
11cf947bbb | ||
|
|
60a20f61af | ||
|
|
e65c7b6bcf | ||
|
|
80c892aca3 | ||
|
|
39ee266598 | ||
|
|
aa58d7744e | ||
|
|
ea3b0b3712 | ||
|
|
d9d8707123 | ||
|
|
8e9a1e2ba5 | ||
|
|
e29b4865e8 | ||
|
|
4b60ca175d | ||
|
|
2fbbc7b5a9 |
70
.github/workflows/publish_docker_image.yml
vendored
70
.github/workflows/publish_docker_image.yml
vendored
@@ -2,63 +2,47 @@ name: Build Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ['v*']
|
||||
tags:
|
||||
- "*.*.*"
|
||||
|
||||
jobs:
|
||||
build-amd:
|
||||
build_deploy:
|
||||
name: Build and Deploy
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v3
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Extract existing image metadata
|
||||
id: image-meta
|
||||
uses: docker/metadata-action@v4
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: atendai/evolution-api
|
||||
tags: type=semver,pattern=v{{version}}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and push AMD image
|
||||
uses: docker/build-push-action@v4
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
labels: ${{ steps.image-meta.outputs.labels }}
|
||||
platforms: linux/amd64
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
build-arm:
|
||||
runs-on: buildjet-4vcpu-ubuntu-2204-arm
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Extract existing image metadata
|
||||
id: image-meta
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: atendai/evolution-api
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and push ARM image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
labels: ${{ steps.image-meta.outputs.labels }}
|
||||
platforms: linux/arm64
|
||||
push: true
|
||||
- name: Image digest
|
||||
run: echo ${{ steps.docker_build.outputs.digest }}
|
||||
48
.github/workflows/publish_docker_image_homolog.yml
vendored
Normal file
48
.github/workflows/publish_docker_image_homolog.yml
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
name: Build Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
|
||||
jobs:
|
||||
build_deploy:
|
||||
name: Build and Deploy
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: atendai/evolution-api
|
||||
tags: homolog
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
- name: Image digest
|
||||
run: echo ${{ steps.docker_build.outputs.digest }}
|
||||
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,3 +1,26 @@
|
||||
# 1.8.0 (2024-05-27 16:10)
|
||||
|
||||
### Feature
|
||||
|
||||
* Now in the manager, when logging in with the client's apikey, the listing only shows the instance corresponding to the provided apikey (only with MongoDB)
|
||||
* New global mode for rabbitmq events
|
||||
* Build in docker for linux/amd64, linux/arm64 platforms
|
||||
|
||||
### Fixed
|
||||
* Correction in message formatting when generated by AI as markdown in typebot
|
||||
* Security fix in fetch instance with client key when not connected to mongodb
|
||||
|
||||
# 1.7.5 (2024-05-21 08:50)
|
||||
|
||||
### Fixed
|
||||
* Add merge_brazil_contacts function to solve nine digit in brazilian numbers
|
||||
* Optimize ChatwootService method for updating contact
|
||||
* Fix swagger auth
|
||||
* Update aws sdk v3
|
||||
* Fix getOpenConversationByContact and init queries error
|
||||
* Method to mark chat as unread
|
||||
* Added environment variable to manually select the WhatsApp web version for the baileys lib (optional)
|
||||
|
||||
# 1.7.4 (2024-04-28 09:46)
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -47,9 +47,33 @@ DATABASE_SAVE_DATA_CONTACTS=false
|
||||
DATABASE_SAVE_DATA_CHATS=false
|
||||
|
||||
RABBITMQ_ENABLED=false
|
||||
RABBITMQ_RABBITMQ_MODE=global
|
||||
RABBITMQ_EXCHANGE_NAME=evolution_exchange
|
||||
RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
||||
RABBITMQ_EXCHANGE_NAME=evolution_exchange
|
||||
RABBITMQ_GLOBAL_ENABLED=false
|
||||
RABBITMQ_EVENTS_APPLICATION_STARTUP=false
|
||||
RABBITMQ_EVENTS_QRCODE_UPDATED=true
|
||||
RABBITMQ_EVENTS_MESSAGES_SET=true
|
||||
RABBITMQ_EVENTS_MESSAGES_UPSERT=true
|
||||
RABBITMQ_EVENTS_MESSAGES_UPDATE=true
|
||||
RABBITMQ_EVENTS_MESSAGES_DELETE=true
|
||||
RABBITMQ_EVENTS_SEND_MESSAGE=true
|
||||
RABBITMQ_EVENTS_CONTACTS_SET=true
|
||||
RABBITMQ_EVENTS_CONTACTS_UPSERT=true
|
||||
RABBITMQ_EVENTS_CONTACTS_UPDATE=true
|
||||
RABBITMQ_EVENTS_PRESENCE_UPDATE=true
|
||||
RABBITMQ_EVENTS_CHATS_SET=true
|
||||
RABBITMQ_EVENTS_CHATS_UPSERT=true
|
||||
RABBITMQ_EVENTS_CHATS_UPDATE=true
|
||||
RABBITMQ_EVENTS_CHATS_DELETE=true
|
||||
RABBITMQ_EVENTS_GROUPS_UPSERT=true
|
||||
RABBITMQ_EVENTS_GROUPS_UPDATE=true
|
||||
RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
||||
RABBITMQ_EVENTS_CONNECTION_UPDATE=true
|
||||
RABBITMQ_EVENTS_LABELS_EDIT=true
|
||||
RABBITMQ_EVENTS_LABELS_ASSOCIATION=true
|
||||
RABBITMQ_EVENTS_CALL=true
|
||||
RABBITMQ_EVENTS_TYPEBOT_START=false
|
||||
RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS=false
|
||||
|
||||
WEBSOCKET_ENABLED=false
|
||||
WEBSOCKET_GLOBAL_EVENTS=false
|
||||
@@ -125,7 +149,7 @@ CHATWOOT_MESSAGE_DELETE=false # false | true
|
||||
# If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp.
|
||||
CHATWOOT_MESSAGE_READ=false # false | true
|
||||
# This db connection is used to import messages from whatsapp to chatwoot database
|
||||
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname
|
||||
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname?sslmode=disable
|
||||
CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE=true
|
||||
|
||||
CACHE_REDIS_ENABLED=false
|
||||
|
||||
32
Dockerfile
32
Dockerfile
@@ -1,6 +1,6 @@
|
||||
FROM node:20.7.0-alpine AS builder
|
||||
|
||||
LABEL version="1.7.4" description="Api to control whatsapp features through http requests."
|
||||
LABEL version="1.8.0" description="Api to control whatsapp features through http requests."
|
||||
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
||||
LABEL contact="contato@agenciadgcode.com"
|
||||
|
||||
@@ -59,9 +59,35 @@ ENV DATABASE_SAVE_DATA_CONTACTS=false
|
||||
ENV DATABASE_SAVE_DATA_CHATS=false
|
||||
|
||||
ENV RABBITMQ_ENABLED=false
|
||||
ENV RABBITMQ_MODE=global
|
||||
ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
|
||||
ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
||||
ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
|
||||
ENV RABBITMQ_GLOBAL_ENABLED=false
|
||||
ENV RABBITMQ_EVENTS_APPLICATION_STARTUP=false
|
||||
ENV RABBITMQ_EVENTS_INSTANCE_CREATE=false
|
||||
ENV RABBITMQ_EVENTS_INSTANCE_DELETE=false
|
||||
ENV RABBITMQ_EVENTS_QRCODE_UPDATED=true
|
||||
ENV RABBITMQ_EVENTS_MESSAGES_SET=true
|
||||
ENV RABBITMQ_EVENTS_MESSAGES_UPSERT=true
|
||||
ENV RABBITMQ_EVENTS_MESSAGES_UPDATE=true
|
||||
ENV RABBITMQ_EVENTS_MESSAGES_DELETE=true
|
||||
ENV RABBITMQ_EVENTS_SEND_MESSAGE=true
|
||||
ENV RABBITMQ_EVENTS_CONTACTS_SET=true
|
||||
ENV RABBITMQ_EVENTS_CONTACTS_UPSERT=true
|
||||
ENV RABBITMQ_EVENTS_CONTACTS_UPDATE=true
|
||||
ENV RABBITMQ_EVENTS_PRESENCE_UPDATE=true
|
||||
ENV RABBITMQ_EVENTS_CHATS_SET=true
|
||||
ENV RABBITMQ_EVENTS_CHATS_UPSERT=true
|
||||
ENV RABBITMQ_EVENTS_CHATS_UPDATE=true
|
||||
ENV RABBITMQ_EVENTS_CHATS_DELETE=true
|
||||
ENV RABBITMQ_EVENTS_GROUPS_UPSERT=true
|
||||
ENV RABBITMQ_EVENTS_GROUPS_UPDATE=true
|
||||
ENV RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
||||
ENV RABBITMQ_EVENTS_CONNECTION_UPDATE=true
|
||||
ENV RABBITMQ_EVENTS_LABELS_EDIT=true
|
||||
ENV RABBITMQ_EVENTS_LABELS_ASSOCIATION=true
|
||||
ENV RABBITMQ_EVENTS_CALL=true
|
||||
ENV RABBITMQ_EVENTS_TYPEBOT_START=false
|
||||
ENV RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS=false
|
||||
|
||||
ENV WEBSOCKET_ENABLED=false
|
||||
ENV WEBSOCKET_GLOBAL_EVENTS=false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "evolution-api",
|
||||
"version": "1.7.4",
|
||||
"version": "1.8.0",
|
||||
"description": "Rest api for communication with WhatsApp",
|
||||
"main": "./dist/src/main.js",
|
||||
"scripts": {
|
||||
@@ -47,9 +47,9 @@
|
||||
"@hapi/boom": "^10.0.1",
|
||||
"@sentry/node": "^7.59.2",
|
||||
"amqplib": "^0.10.3",
|
||||
"aws-sdk": "^2.1499.0",
|
||||
"@aws-sdk/client-sqs": "^3.569.0",
|
||||
"axios": "^1.6.5",
|
||||
"baileys": "^6.7.0",
|
||||
"@whiskeysockets/baileys": "^6.7.2",
|
||||
"class-validator": "^0.14.1",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
BlockUserDto,
|
||||
DeleteMessage,
|
||||
getBase64FromMediaMessageDto,
|
||||
MarkChatUnreadDto,
|
||||
NumberDto,
|
||||
PrivacySettingDto,
|
||||
ProfileNameDto,
|
||||
@@ -40,6 +41,11 @@ export class ChatController {
|
||||
return await this.waMonitor.waInstances[instanceName].archiveChat(data);
|
||||
}
|
||||
|
||||
public async markChatUnread({ instanceName }: InstanceDto, data: MarkChatUnreadDto) {
|
||||
logger.verbose('requested markChatUnread from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].markChatUnread(data);
|
||||
}
|
||||
|
||||
public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) {
|
||||
logger.verbose('requested deleteMessage from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].deleteMessage(data);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { delay } from 'baileys';
|
||||
import { delay } from '@whiskeysockets/baileys';
|
||||
import { isURL } from 'class-validator';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { ConfigService, HttpServer, WaBusiness } from '../../config/env.config';
|
||||
import { Auth, ConfigService, HttpServer, WaBusiness } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
|
||||
import { BadRequestException, InternalServerErrorException, UnauthorizedException } from '../../exceptions';
|
||||
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
|
||||
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
|
||||
import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service';
|
||||
@@ -66,6 +66,7 @@ export class InstanceController {
|
||||
chatwoot_conversation_pending,
|
||||
chatwoot_import_contacts,
|
||||
chatwoot_name_inbox,
|
||||
chatwoot_merge_brazil_contacts,
|
||||
chatwoot_import_messages,
|
||||
chatwoot_days_limit_import_messages,
|
||||
reject_call,
|
||||
@@ -519,6 +520,7 @@ export class InstanceController {
|
||||
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||
conversation_pending: chatwoot_conversation_pending || false,
|
||||
import_contacts: chatwoot_import_contacts ?? true,
|
||||
merge_brazil_contacts: chatwoot_merge_brazil_contacts ?? false,
|
||||
import_messages: chatwoot_import_messages ?? true,
|
||||
days_limit_import_messages: chatwoot_days_limit_import_messages ?? 60,
|
||||
auto_create: true,
|
||||
@@ -574,6 +576,7 @@ export class InstanceController {
|
||||
sign_msg: chatwoot_sign_msg || false,
|
||||
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||
conversation_pending: chatwoot_conversation_pending || false,
|
||||
merge_brazil_contacts: chatwoot_merge_brazil_contacts ?? false,
|
||||
import_contacts: chatwoot_import_contacts ?? true,
|
||||
import_messages: chatwoot_import_messages ?? true,
|
||||
days_limit_import_messages: chatwoot_days_limit_import_messages || 60,
|
||||
@@ -676,11 +679,26 @@ export class InstanceController {
|
||||
};
|
||||
}
|
||||
|
||||
public async fetchInstances({ instanceName, instanceId, number }: InstanceDto) {
|
||||
if (instanceName) {
|
||||
this.logger.verbose('requested fetchInstances from ' + instanceName + ' instance');
|
||||
this.logger.verbose('instanceName: ' + instanceName);
|
||||
return this.waMonitor.instanceInfo(instanceName);
|
||||
public async fetchInstances({ instanceName, instanceId, number }: InstanceDto, key: string) {
|
||||
const env = this.configService.get<Auth>('AUTHENTICATION').API_KEY;
|
||||
|
||||
let name = instanceName;
|
||||
let arrayReturn = false;
|
||||
|
||||
if (env.KEY !== key) {
|
||||
const instanceByKey = await this.repository.auth.findByKey(key);
|
||||
if (instanceByKey) {
|
||||
name = instanceByKey._id;
|
||||
arrayReturn = true;
|
||||
} else {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
}
|
||||
|
||||
if (name) {
|
||||
this.logger.verbose('requested fetchInstances from ' + name + ' instance');
|
||||
this.logger.verbose('instanceName: ' + name);
|
||||
return this.waMonitor.instanceInfo(name, arrayReturn);
|
||||
} else if (instanceId || number) {
|
||||
return this.waMonitor.instanceInfoById(instanceId, number);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from 'baileys';
|
||||
import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '@whiskeysockets/baileys';
|
||||
|
||||
export class OnWhatsAppDto {
|
||||
constructor(
|
||||
@@ -73,6 +73,11 @@ export class ArchiveChatDto {
|
||||
archive: boolean;
|
||||
}
|
||||
|
||||
export class MarkChatUnreadDto {
|
||||
lastMessage?: LastMessage;
|
||||
chat?: string;
|
||||
}
|
||||
|
||||
class PrivacySetting {
|
||||
readreceipts: WAReadReceiptsValue;
|
||||
profile: WAPrivacyValue;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { WAPresence } from 'baileys';
|
||||
import { WAPresence } from '@whiskeysockets/baileys';
|
||||
|
||||
import { ProxyDto } from './proxy.dto';
|
||||
|
||||
@@ -27,6 +27,7 @@ export class InstanceDto {
|
||||
chatwoot_sign_msg?: boolean;
|
||||
chatwoot_reopen_conversation?: boolean;
|
||||
chatwoot_conversation_pending?: boolean;
|
||||
chatwoot_merge_brazil_contacts?: boolean;
|
||||
chatwoot_import_contacts?: boolean;
|
||||
chatwoot_import_messages?: boolean;
|
||||
chatwoot_days_limit_import_messages?: number;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { proto, WAPresence } from 'baileys';
|
||||
import { proto, WAPresence } from '@whiskeysockets/baileys';
|
||||
|
||||
export class Quoted {
|
||||
key: proto.IMessageKey;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { NextFunction, Request, Response } from 'express';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
import { name } from '../../../package.json';
|
||||
import { Auth, configService } from '../../config/env.config';
|
||||
import { Auth, configService, Database } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { ForbiddenException, UnauthorizedException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
@@ -58,6 +58,11 @@ async function jwtGuard(req: Request, res: Response, next: NextFunction) {
|
||||
async function apikey(req: Request, _: Response, next: NextFunction) {
|
||||
const env = configService.get<Auth>('AUTHENTICATION').API_KEY;
|
||||
const key = req.get('apikey');
|
||||
const db = configService.get<Database>('DATABASE');
|
||||
|
||||
if (!key) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
if (env.KEY === key) {
|
||||
return next();
|
||||
@@ -66,12 +71,21 @@ async function apikey(req: Request, _: Response, next: NextFunction) {
|
||||
if ((req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) && !key) {
|
||||
throw new ForbiddenException('Missing global api key', 'The global api key must be set');
|
||||
}
|
||||
const param = req.params as unknown as InstanceDto;
|
||||
|
||||
try {
|
||||
const param = req.params as unknown as InstanceDto;
|
||||
const instanceKey = await repository.auth.find(param.instanceName);
|
||||
if (instanceKey.apikey === key) {
|
||||
return next();
|
||||
if (param?.instanceName) {
|
||||
const instanceKey = await repository.auth.find(param.instanceName);
|
||||
if (instanceKey?.apikey === key) {
|
||||
return next();
|
||||
}
|
||||
} else {
|
||||
if (req.originalUrl.includes('/instance/fetchInstances') && db.ENABLED) {
|
||||
const instanceByKey = await repository.auth.findByKey(key);
|
||||
if (instanceByKey) {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
|
||||
@@ -53,6 +53,7 @@ export class ChatwootController {
|
||||
data.conversation_pending = false;
|
||||
data.import_contacts = false;
|
||||
data.import_messages = false;
|
||||
data.merge_brazil_contacts = false;
|
||||
data.days_limit_import_messages = 0;
|
||||
data.auto_create = false;
|
||||
data.name_inbox = '';
|
||||
|
||||
@@ -9,6 +9,7 @@ export class ChatwootDto {
|
||||
number?: string;
|
||||
reopen_conversation?: boolean;
|
||||
conversation_pending?: boolean;
|
||||
merge_brazil_contacts?: boolean;
|
||||
import_contacts?: boolean;
|
||||
import_messages?: boolean;
|
||||
days_limit_import_messages?: number;
|
||||
|
||||
@@ -14,6 +14,7 @@ export class ChatwootRaw {
|
||||
number?: string;
|
||||
reopen_conversation?: boolean;
|
||||
conversation_pending?: boolean;
|
||||
merge_brazil_contacts?: boolean;
|
||||
import_contacts?: boolean;
|
||||
import_messages?: boolean;
|
||||
days_limit_import_messages?: number;
|
||||
@@ -31,6 +32,7 @@ const chatwootSchema = new Schema<ChatwootRaw>({
|
||||
number: { type: String, required: true },
|
||||
reopen_conversation: { type: Boolean, required: true },
|
||||
conversation_pending: { type: Boolean, required: true },
|
||||
merge_brazil_contacts: { type: Boolean, required: true },
|
||||
import_contacts: { type: Boolean, required: true },
|
||||
import_messages: { type: Boolean, required: true },
|
||||
days_limit_import_messages: { type: Number, required: true },
|
||||
|
||||
@@ -8,8 +8,8 @@ import ChatwootClient, {
|
||||
inbox,
|
||||
} from '@figuro/chatwoot-sdk';
|
||||
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
|
||||
import { proto } from '@whiskeysockets/baileys';
|
||||
import axios from 'axios';
|
||||
import { proto } from 'baileys';
|
||||
import FormData from 'form-data';
|
||||
import { createReadStream, unlinkSync, writeFileSync } from 'fs';
|
||||
import Jimp from 'jimp';
|
||||
@@ -86,13 +86,14 @@ export class ChatwootService {
|
||||
return client;
|
||||
}
|
||||
|
||||
public getClientCwConfig(): ChatwootAPIConfig & { name_inbox: string } {
|
||||
public getClientCwConfig(): ChatwootAPIConfig & { name_inbox: string; merge_brazil_contacts: boolean } {
|
||||
return {
|
||||
basePath: this.provider.url,
|
||||
with_credentials: true,
|
||||
credentials: 'include',
|
||||
token: this.provider.token,
|
||||
name_inbox: this.provider.name_inbox,
|
||||
merge_brazil_contacts: this.provider.merge_brazil_contacts,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -418,10 +419,49 @@ export class ChatwootService {
|
||||
}
|
||||
}
|
||||
|
||||
private async mergeBrazilianContacts(contacts: any[]) {
|
||||
try {
|
||||
//sdk chatwoot não tem função merge
|
||||
this.logger.verbose('merging contacts');
|
||||
const contact = await chatwootRequest(this.getClientCwConfig(), {
|
||||
method: 'POST',
|
||||
url: `/api/v1/accounts/${this.provider.account_id}/actions/contact_merge`,
|
||||
body: {
|
||||
base_contact_id: contacts.find((contact) => contact.phone_number.length === 14)?.id,
|
||||
mergee_contact_id: contacts.find((contact) => contact.phone_number.length === 13)?.id,
|
||||
},
|
||||
});
|
||||
|
||||
return contact;
|
||||
} catch {
|
||||
this.logger.error('Error merging contacts');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private findContactInContactList(contacts: any[], query: string) {
|
||||
const phoneNumbers = this.getNumbers(query);
|
||||
const searchableFields = this.getSearchableFields();
|
||||
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
if(contacts.length === 2 && this.getClientCwConfig().merge_brazil_contacts && query.startsWith('+55')){
|
||||
|
||||
const contact = this.mergeBrazilianContacts(contacts);
|
||||
if (contact) {
|
||||
return contact;
|
||||
}
|
||||
}
|
||||
|
||||
const phone = phoneNumbers.reduce(
|
||||
(savedNumber, number) => (number.length > savedNumber.length ? number : savedNumber),
|
||||
'',
|
||||
);
|
||||
|
||||
const contact_with9 = contacts.find((contact) => contact.phone_number === phone);
|
||||
if (contact_with9) {
|
||||
return contact_with9;
|
||||
}
|
||||
|
||||
for (const contact of contacts) {
|
||||
for (const field of searchableFields) {
|
||||
if (contact[field] && phoneNumbers.includes(contact[field])) {
|
||||
@@ -449,7 +489,7 @@ export class ChatwootService {
|
||||
}
|
||||
|
||||
private getSearchableFields() {
|
||||
return ['phone_number', 'identifier'];
|
||||
return ['phone_number'];
|
||||
}
|
||||
|
||||
private getFilterPayload(query: string) {
|
||||
@@ -463,7 +503,7 @@ export class ChatwootService {
|
||||
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
|
||||
filterPayload.push({
|
||||
attribute_key: field,
|
||||
filter_operator: ['phone_number', 'identifier'].includes(field) ? 'equal_to' : 'contains',
|
||||
filter_operator: 'equal_to',
|
||||
values: [number.replace('+', '')],
|
||||
query_operator: queryOperator,
|
||||
});
|
||||
@@ -561,53 +601,44 @@ export class ChatwootService {
|
||||
|
||||
const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(chatId);
|
||||
|
||||
const findContact = await this.findContact(instance, chatId);
|
||||
let contact = await this.findContact(instance, chatId);
|
||||
|
||||
let contact: any;
|
||||
if (body.key.fromMe) {
|
||||
if (findContact) {
|
||||
contact = await this.updateContact(instance, findContact.id, {
|
||||
avatar_url: picture_url.profilePictureUrl || null,
|
||||
});
|
||||
} else {
|
||||
const jid = isGroup ? null : body.key.remoteJid;
|
||||
contact = await this.createContact(
|
||||
instance,
|
||||
chatId,
|
||||
filterInbox.id,
|
||||
isGroup,
|
||||
nameContact,
|
||||
picture_url.profilePictureUrl || null,
|
||||
jid,
|
||||
);
|
||||
if (contact) {
|
||||
if (!body.key.fromMe) {
|
||||
const waProfilePictureFile =
|
||||
picture_url?.profilePictureUrl?.split('#')[0].split('?')[0].split('/').pop() || '';
|
||||
const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop() || '';
|
||||
const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile;
|
||||
const nameNeedsUpdate =
|
||||
!contact.name ||
|
||||
contact.name === chatId ||
|
||||
(`+${chatId}`.startsWith('+55')
|
||||
? this.getNumbers(`+${chatId}`).some(
|
||||
(v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1),
|
||||
)
|
||||
: false);
|
||||
|
||||
const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate;
|
||||
if (contactNeedsUpdate) {
|
||||
this.logger.verbose('update contact in chatwoot');
|
||||
contact = await this.updateContact(instance, contact.id, {
|
||||
...(nameNeedsUpdate && { name: nameContact }),
|
||||
...(waProfilePictureFile === '' && { avatar: null }),
|
||||
...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (findContact) {
|
||||
if (!findContact.name || findContact.name === chatId) {
|
||||
contact = await this.updateContact(instance, findContact.id, {
|
||||
name: nameContact,
|
||||
avatar_url: picture_url.profilePictureUrl || null,
|
||||
});
|
||||
} else {
|
||||
contact = await this.updateContact(instance, findContact.id, {
|
||||
avatar_url: picture_url.profilePictureUrl || null,
|
||||
});
|
||||
}
|
||||
if (!contact) {
|
||||
contact = await this.findContact(instance, chatId);
|
||||
}
|
||||
} else {
|
||||
const jid = isGroup ? null : body.key.remoteJid;
|
||||
contact = await this.createContact(
|
||||
instance,
|
||||
chatId,
|
||||
filterInbox.id,
|
||||
isGroup,
|
||||
nameContact,
|
||||
picture_url.profilePictureUrl || null,
|
||||
jid,
|
||||
);
|
||||
}
|
||||
const jid = isGroup ? null : body.key.remoteJid;
|
||||
contact = await this.createContact(
|
||||
instance,
|
||||
chatId,
|
||||
filterInbox.id,
|
||||
isGroup,
|
||||
nameContact,
|
||||
picture_url.profilePictureUrl || null,
|
||||
jid,
|
||||
);
|
||||
}
|
||||
|
||||
if (!contact) {
|
||||
@@ -617,13 +648,6 @@ export class ChatwootService {
|
||||
|
||||
const contactId = contact?.payload?.id || contact?.payload?.contact?.id || contact?.id;
|
||||
|
||||
if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) {
|
||||
this.logger.verbose('update contact name in chatwoot');
|
||||
await this.updateContact(instance, contactId, {
|
||||
name: nameContact,
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.verbose('get contact conversations in chatwoot');
|
||||
const contactConversations = (await client.contacts.listConversations({
|
||||
accountId: this.provider.account_id,
|
||||
@@ -789,26 +813,15 @@ export class ChatwootService {
|
||||
return null;
|
||||
}
|
||||
|
||||
const payload = [
|
||||
['inbox_id', inbox.id.toString()],
|
||||
['contact_id', contact.id.toString()],
|
||||
['status', 'open'],
|
||||
];
|
||||
const conversations = (await client.contacts.listConversations({
|
||||
accountId: this.provider.account_id,
|
||||
id: contact.id,
|
||||
})) as any;
|
||||
|
||||
return (
|
||||
(
|
||||
(await client.conversations.filter({
|
||||
accountId: this.provider.account_id,
|
||||
payload: payload.map((item, i, payload) => {
|
||||
return {
|
||||
attribute_key: item[0],
|
||||
filter_operator: 'equal_to',
|
||||
values: [item[1]],
|
||||
query_operator: i < payload.length - 1 ? 'AND' : null,
|
||||
};
|
||||
}),
|
||||
})) as { payload: conversation[] }
|
||||
).payload[0] || undefined
|
||||
conversations.payload.find(
|
||||
(conversation) => conversation.inbox_id === inbox.id && conversation.status === 'open',
|
||||
) || undefined
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { inbox } from '@figuro/chatwoot-sdk';
|
||||
import { proto } from 'baileys';
|
||||
import { proto } from '@whiskeysockets/baileys';
|
||||
|
||||
import { InstanceDto } from '../../../../api/dto/instance.dto';
|
||||
import { ChatwootRaw, ContactRaw, MessageRaw } from '../../../../api/models';
|
||||
|
||||
@@ -35,6 +35,7 @@ export const chatwootSchema: JSONSchema7 = {
|
||||
conversation_pending: { type: 'boolean', enum: [true, false] },
|
||||
auto_create: { type: 'boolean', enum: [true, false] },
|
||||
import_contacts: { type: 'boolean', enum: [true, false] },
|
||||
merge_brazil_contacts: { type: 'boolean', enum: [true, false] },
|
||||
import_messages: { type: 'boolean', enum: [true, false] },
|
||||
days_limit_import_messages: { type: 'number' },
|
||||
},
|
||||
|
||||
@@ -42,6 +42,41 @@ export const getAMQP = (): amqp.Channel | null => {
|
||||
return amqpChannel;
|
||||
};
|
||||
|
||||
export const initGlobalQueues = () => {
|
||||
logger.info('Initializing global queues');
|
||||
const events = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
|
||||
|
||||
if (!events) {
|
||||
logger.warn('No events to initialize on AMQP');
|
||||
return;
|
||||
}
|
||||
|
||||
const eventKeys = Object.keys(events);
|
||||
|
||||
eventKeys.forEach((event) => {
|
||||
if (events[event] === false) return;
|
||||
|
||||
const queueName = `${event.replace(/_/g, '.').toLowerCase()}`;
|
||||
const amqp = getAMQP();
|
||||
const exchangeName = 'evolution_exchange';
|
||||
|
||||
amqp.assertExchange(exchangeName, 'topic', {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
});
|
||||
|
||||
amqp.assertQueue(queueName, {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
arguments: {
|
||||
'x-queue-type': 'quorum',
|
||||
},
|
||||
});
|
||||
|
||||
amqp.bindQueue(queueName, exchangeName, event);
|
||||
});
|
||||
};
|
||||
|
||||
export const initQueues = (instanceName: string, events: string[]) => {
|
||||
if (!events || !events.length) return;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SQS } from 'aws-sdk';
|
||||
import { SQS } from '@aws-sdk/client-sqs';
|
||||
|
||||
import { configService, Sqs } from '../../../../config/env.config';
|
||||
import { Logger } from '../../../../config/logger.config';
|
||||
@@ -12,8 +12,11 @@ export const initSQS = () => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const awsConfig = configService.get<Sqs>('SQS');
|
||||
sqs = new SQS({
|
||||
accessKeyId: awsConfig.ACCESS_KEY_ID,
|
||||
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
|
||||
credentials: {
|
||||
accessKeyId: awsConfig.ACCESS_KEY_ID,
|
||||
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
|
||||
},
|
||||
|
||||
region: awsConfig.REGION,
|
||||
});
|
||||
|
||||
|
||||
@@ -519,18 +519,32 @@ export class TypebotService {
|
||||
text += element.text;
|
||||
}
|
||||
|
||||
if (
|
||||
element.children &&
|
||||
(element.type === 'p' ||
|
||||
element.type === 'a' ||
|
||||
element.type === 'inline-variable' ||
|
||||
element.type === 'variable')
|
||||
) {
|
||||
if (element.children && element.type !== 'a') {
|
||||
for (const child of element.children) {
|
||||
text += applyFormatting(child);
|
||||
}
|
||||
}
|
||||
|
||||
if (element.type === 'p') {
|
||||
text = text.trim() + '\n';
|
||||
}
|
||||
|
||||
if (element.type === 'ol') {
|
||||
text =
|
||||
'\n' +
|
||||
text
|
||||
.split('\n')
|
||||
.map((line, index) => (line ? `${index + 1}. ${line}` : ''))
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
if (element.type === 'li') {
|
||||
text = text
|
||||
.split('\n')
|
||||
.map((line) => (line ? ` ${line}` : ''))
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
let formats = '';
|
||||
|
||||
if (element.bold) {
|
||||
|
||||
@@ -9,12 +9,12 @@ export class IntegrationRaw {
|
||||
token?: string;
|
||||
}
|
||||
|
||||
const sqsSchema = new Schema<IntegrationRaw>({
|
||||
const integrationSchema = new Schema<IntegrationRaw>({
|
||||
_id: { type: String, _id: true },
|
||||
integration: { type: String, required: true },
|
||||
number: { type: String, required: true },
|
||||
token: { type: String, required: true },
|
||||
});
|
||||
|
||||
export const IntegrationModel = dbserver?.model(IntegrationRaw.name, sqsSchema, 'integration');
|
||||
export const IntegrationModel = dbserver?.model(IntegrationRaw.name, integrationSchema, 'integration');
|
||||
export type IntegrationModel = typeof IntegrationModel;
|
||||
|
||||
@@ -68,6 +68,20 @@ export class AuthRepository extends Repository {
|
||||
}
|
||||
}
|
||||
|
||||
public async findByKey(key: string): Promise<AuthRaw> {
|
||||
try {
|
||||
this.logger.verbose('finding auth');
|
||||
if (this.dbSettings.ENABLED) {
|
||||
this.logger.verbose('finding auth in db');
|
||||
return await this.authModel.findOne({ apikey: key });
|
||||
}
|
||||
|
||||
return {};
|
||||
} catch (error) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
public async list(): Promise<AuthRaw[]> {
|
||||
try {
|
||||
if (this.dbSettings.ENABLED) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
blockUserSchema,
|
||||
contactValidateSchema,
|
||||
deleteMessageSchema,
|
||||
markChatUnreadSchema,
|
||||
messageUpSchema,
|
||||
messageValidateSchema,
|
||||
presenceSchema,
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
BlockUserDto,
|
||||
DeleteMessage,
|
||||
getBase64FromMediaMessageDto,
|
||||
MarkChatUnreadDto,
|
||||
NumberDto,
|
||||
PrivacySettingDto,
|
||||
ProfileNameDto,
|
||||
@@ -98,6 +100,23 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('markChatUnread'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in markChatUnread');
|
||||
logger.verbose('request body: ');
|
||||
logger.verbose(req.body);
|
||||
|
||||
logger.verbose('request query: ');
|
||||
logger.verbose(req.query);
|
||||
|
||||
const response = await this.dataValidate<MarkChatUnreadDto>({
|
||||
request: req,
|
||||
schema: markChatUnreadSchema,
|
||||
ClassRef: MarkChatUnreadDto,
|
||||
execute: (instance, data) => chatController.markChatUnread(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.delete(this.routerPath('deleteMessageForEveryone'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in deleteMessageForEveryone');
|
||||
logger.verbose('request body: ');
|
||||
|
||||
@@ -103,13 +103,15 @@ export class InstanceRouter extends RouterBroker {
|
||||
logger.verbose('request body: ');
|
||||
logger.verbose(req.body);
|
||||
|
||||
const key = req.get('apikey');
|
||||
|
||||
logger.verbose('request query: ');
|
||||
logger.verbose(req.query);
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: null,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => instanceController.fetchInstances(instance),
|
||||
execute: (instance) => instanceController.fetchInstances(instance, key),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BufferJSON } from 'baileys';
|
||||
import { BufferJSON } from '@whiskeysockets/baileys';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { ICache } from '../abstract/abstract.cache';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { WASocket } from '@whiskeysockets/baileys';
|
||||
import axios from 'axios';
|
||||
import { WASocket } from 'baileys';
|
||||
import { execSync } from 'child_process';
|
||||
import { isURL } from 'class-validator';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Database,
|
||||
HttpServer,
|
||||
Log,
|
||||
Rabbitmq,
|
||||
Sqs,
|
||||
Webhook,
|
||||
Websocket,
|
||||
@@ -305,6 +306,9 @@ export class ChannelStartupService {
|
||||
this.localChatwoot.conversation_pending = data?.conversation_pending;
|
||||
this.logger.verbose(`Chatwoot conversation pending: ${this.localChatwoot.conversation_pending}`);
|
||||
|
||||
this.localChatwoot.merge_brazil_contacts = data?.merge_brazil_contacts;
|
||||
this.logger.verbose(`Chatwoot merge brazil contacts: ${this.localChatwoot.merge_brazil_contacts}`);
|
||||
|
||||
this.localChatwoot.import_contacts = data?.import_contacts;
|
||||
this.logger.verbose(`Chatwoot import contacts: ${this.localChatwoot.import_contacts}`);
|
||||
|
||||
@@ -328,6 +332,7 @@ export class ChannelStartupService {
|
||||
this.logger.verbose(`Chatwoot sign delimiter: ${data.sign_delimiter}`);
|
||||
this.logger.verbose(`Chatwoot reopen conversation: ${data.reopen_conversation}`);
|
||||
this.logger.verbose(`Chatwoot conversation pending: ${data.conversation_pending}`);
|
||||
this.logger.verbose(`Chatwoot merge brazil contacts: ${data.merge_brazil_contacts}`);
|
||||
this.logger.verbose(`Chatwoot import contacts: ${data.import_contacts}`);
|
||||
this.logger.verbose(`Chatwoot import messages: ${data.import_messages}`);
|
||||
this.logger.verbose(`Chatwoot days limit import messages: ${data.days_limit_import_messages}`);
|
||||
@@ -356,6 +361,7 @@ export class ChannelStartupService {
|
||||
this.logger.verbose(`Chatwoot sign delimiter: ${data.sign_delimiter}`);
|
||||
this.logger.verbose(`Chatwoot reopen conversation: ${data.reopen_conversation}`);
|
||||
this.logger.verbose(`Chatwoot conversation pending: ${data.conversation_pending}`);
|
||||
this.logger.verbose(`Chatwoot merge brazilian contacts: ${data.merge_brazil_contacts}`);
|
||||
this.logger.verbose(`Chatwoot import contacts: ${data.import_contacts}`);
|
||||
this.logger.verbose(`Chatwoot import messages: ${data.import_messages}`);
|
||||
this.logger.verbose(`Chatwoot days limit import messages: ${data.days_limit_import_messages}`);
|
||||
@@ -370,6 +376,7 @@ export class ChannelStartupService {
|
||||
sign_delimiter: data.sign_delimiter || null,
|
||||
reopen_conversation: data.reopen_conversation,
|
||||
conversation_pending: data.conversation_pending,
|
||||
merge_brazil_contacts: data.merge_brazil_contacts,
|
||||
import_contacts: data.import_contacts,
|
||||
import_messages: data.import_messages,
|
||||
days_limit_import_messages: data.days_limit_import_messages,
|
||||
@@ -686,6 +693,9 @@ export class ChannelStartupService {
|
||||
const rabbitmqLocal = this.localRabbitmq.events;
|
||||
const sqsLocal = this.localSqs.events;
|
||||
const serverUrl = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const rabbitmqEnabled = this.configService.get<Rabbitmq>('RABBITMQ').ENABLED;
|
||||
const rabbitmqGlobal = this.configService.get<Rabbitmq>('RABBITMQ').GLOBAL_ENABLED;
|
||||
const rabbitmqEvents = this.configService.get<Rabbitmq>('RABBITMQ').EVENTS;
|
||||
const we = event.replace(/[.-]/gm, '_').toUpperCase();
|
||||
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
||||
const tzoffset = new Date().getTimezoneOffset() * 60000; //offset in milliseconds
|
||||
@@ -696,67 +706,134 @@ export class ChannelStartupService {
|
||||
const tokenStore = await this.repository.auth.find(this.instanceName);
|
||||
const instanceApikey = tokenStore?.apikey || 'Apikey not found';
|
||||
|
||||
if (this.localRabbitmq.enabled) {
|
||||
if (rabbitmqEnabled) {
|
||||
const amqp = getAMQP();
|
||||
|
||||
if (amqp) {
|
||||
if (this.localRabbitmq.enabled && amqp) {
|
||||
if (Array.isArray(rabbitmqLocal) && rabbitmqLocal.includes(we)) {
|
||||
const exchangeName = this.instanceName ?? 'evolution_exchange';
|
||||
|
||||
// await amqp.assertExchange(exchangeName, 'topic', {
|
||||
// durable: true,
|
||||
// autoDelete: false,
|
||||
// });
|
||||
let retry = 0;
|
||||
|
||||
await this.assertExchangeAsync(amqp, exchangeName, 'topic', {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
});
|
||||
while (retry < 3) {
|
||||
try {
|
||||
await amqp.assertExchange(exchangeName, 'topic', {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
});
|
||||
|
||||
const queueName = `${this.instanceName}.${event}`;
|
||||
const queueName = `${this.instanceName}.${event}`;
|
||||
|
||||
await amqp.assertQueue(queueName, {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
arguments: {
|
||||
'x-queue-type': 'quorum',
|
||||
},
|
||||
});
|
||||
await amqp.assertQueue(queueName, {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
arguments: {
|
||||
'x-queue-type': 'quorum',
|
||||
},
|
||||
});
|
||||
|
||||
await amqp.bindQueue(queueName, exchangeName, event);
|
||||
await amqp.bindQueue(queueName, exchangeName, event);
|
||||
|
||||
const message = {
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
server_url: serverUrl,
|
||||
date_time: now,
|
||||
sender: this.wuid,
|
||||
};
|
||||
const message = {
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
server_url: serverUrl,
|
||||
date_time: now,
|
||||
sender: this.wuid,
|
||||
};
|
||||
|
||||
if (expose && instanceApikey) {
|
||||
message['apikey'] = instanceApikey;
|
||||
if (expose && instanceApikey) {
|
||||
message['apikey'] = instanceApikey;
|
||||
}
|
||||
|
||||
await amqp.publish(exchangeName, event, Buffer.from(JSON.stringify(message)));
|
||||
|
||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||
const logData = {
|
||||
local: ChannelStartupService.name + '.sendData-RabbitMQ',
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
server_url: serverUrl,
|
||||
apikey: (expose && instanceApikey) || null,
|
||||
date_time: now,
|
||||
sender: this.wuid,
|
||||
};
|
||||
|
||||
if (expose && instanceApikey) {
|
||||
logData['apikey'] = instanceApikey;
|
||||
}
|
||||
|
||||
this.logger.log(logData);
|
||||
}
|
||||
break;
|
||||
} catch (error) {
|
||||
retry++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await amqp.publish(exchangeName, event, Buffer.from(JSON.stringify(message)));
|
||||
if (rabbitmqGlobal && rabbitmqEvents[we] && amqp) {
|
||||
const exchangeName = 'evolution_exchange';
|
||||
|
||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||
const logData = {
|
||||
local: ChannelStartupService.name + '.sendData-RabbitMQ',
|
||||
let retry = 0;
|
||||
|
||||
while (retry < 3) {
|
||||
try {
|
||||
await amqp.assertExchange(exchangeName, 'topic', {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
});
|
||||
|
||||
const queueName = transformedWe;
|
||||
|
||||
await amqp.assertQueue(queueName, {
|
||||
durable: true,
|
||||
autoDelete: false,
|
||||
arguments: {
|
||||
'x-queue-type': 'quorum',
|
||||
},
|
||||
});
|
||||
|
||||
await amqp.bindQueue(queueName, exchangeName, event);
|
||||
|
||||
const message = {
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
server_url: serverUrl,
|
||||
apikey: (expose && instanceApikey) || null,
|
||||
date_time: now,
|
||||
sender: this.wuid,
|
||||
};
|
||||
|
||||
if (expose && instanceApikey) {
|
||||
logData['apikey'] = instanceApikey;
|
||||
message['apikey'] = instanceApikey;
|
||||
}
|
||||
await amqp.publish(exchangeName, event, Buffer.from(JSON.stringify(message)));
|
||||
|
||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||
const logData = {
|
||||
local: ChannelStartupService.name + '.sendData-RabbitMQ-Global',
|
||||
event,
|
||||
instance: this.instance.name,
|
||||
data,
|
||||
server_url: serverUrl,
|
||||
apikey: (expose && instanceApikey) || null,
|
||||
date_time: now,
|
||||
sender: this.wuid,
|
||||
};
|
||||
|
||||
if (expose && instanceApikey) {
|
||||
logData['apikey'] = instanceApikey;
|
||||
}
|
||||
|
||||
this.logger.log(logData);
|
||||
}
|
||||
|
||||
this.logger.log(logData);
|
||||
break;
|
||||
} catch (error) {
|
||||
retry++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
|
||||
import { Boom } from '@hapi/boom';
|
||||
import axios from 'axios';
|
||||
import makeWASocket, {
|
||||
AnyMessageContent,
|
||||
BufferedEventData,
|
||||
@@ -36,9 +35,10 @@ import makeWASocket, {
|
||||
WAMessageUpdate,
|
||||
WAPresence,
|
||||
WASocket,
|
||||
} from 'baileys';
|
||||
import { Label } from 'baileys/lib/Types/Label';
|
||||
import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
|
||||
} from '@whiskeysockets/baileys';
|
||||
import { Label } from '@whiskeysockets/baileys/lib/Types/Label';
|
||||
import { LabelAssociation } from '@whiskeysockets/baileys/lib/Types/LabelAssociation';
|
||||
import axios from 'axios';
|
||||
import { exec } from 'child_process';
|
||||
import { isBase64, isURL } from 'class-validator';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
@@ -68,6 +68,7 @@ import {
|
||||
DeleteMessage,
|
||||
getBase64FromMediaMessageDto,
|
||||
LastMessage,
|
||||
MarkChatUnreadDto,
|
||||
NumberBusiness,
|
||||
OnWhatsAppDto,
|
||||
PrivacySettingDto,
|
||||
@@ -495,13 +496,24 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
const { version } = await fetchLatestBaileysVersion();
|
||||
|
||||
this.logger.verbose('Baileys version: ' + version);
|
||||
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
||||
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
||||
this.logger.verbose('Browser: ' + JSON.stringify(browser));
|
||||
|
||||
let version;
|
||||
let log;
|
||||
|
||||
if (session.VERSION) {
|
||||
version = session.VERSION.split(',');
|
||||
log = `Baileys version env: ${version}`;
|
||||
} else {
|
||||
const baileysVersion = await fetchLatestBaileysVersion();
|
||||
version = baileysVersion.version;
|
||||
log = `Baileys version: ${version}`;
|
||||
}
|
||||
|
||||
this.logger.info(log);
|
||||
|
||||
let options;
|
||||
|
||||
if (this.localProxy.enabled) {
|
||||
@@ -670,10 +682,23 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
try {
|
||||
this.instance.authState = await this.defineAuthState();
|
||||
|
||||
const { version } = await fetchLatestBaileysVersion();
|
||||
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
||||
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
||||
|
||||
let version;
|
||||
let log;
|
||||
|
||||
if (session.VERSION) {
|
||||
version = session.VERSION.split(',');
|
||||
log = `Baileys version env: ${version}`;
|
||||
} else {
|
||||
const baileysVersion = await fetchLatestBaileysVersion();
|
||||
version = baileysVersion.version;
|
||||
log = `Baileys version: ${version}`;
|
||||
}
|
||||
|
||||
this.logger.info(log);
|
||||
|
||||
let options;
|
||||
|
||||
if (this.localProxy.enabled) {
|
||||
@@ -1970,18 +1995,37 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
|
||||
const sender = isWA.jid;
|
||||
|
||||
this.logger.verbose('Sending presence');
|
||||
await this.client.presenceSubscribe(sender);
|
||||
this.logger.verbose('Subscribing to presence');
|
||||
if (data?.options?.delay && data?.options?.delay > 20000) {
|
||||
let remainingDelay = data?.options.delay;
|
||||
while (remainingDelay > 20000) {
|
||||
await this.client.presenceSubscribe(sender);
|
||||
|
||||
await this.client.sendPresenceUpdate(data.options?.presence ?? 'composing', sender);
|
||||
this.logger.verbose('Sending presence update: ' + data.options?.presence ?? 'composing');
|
||||
await this.client.sendPresenceUpdate((data?.options?.presence as WAPresence) ?? 'composing', sender);
|
||||
|
||||
await delay(data.options.delay);
|
||||
this.logger.verbose('Set delay: ' + data.options.delay);
|
||||
await delay(20000);
|
||||
|
||||
await this.client.sendPresenceUpdate('paused', sender);
|
||||
this.logger.verbose('Sending presence update: paused');
|
||||
await this.client.sendPresenceUpdate('paused', sender);
|
||||
|
||||
remainingDelay -= 20000;
|
||||
}
|
||||
if (remainingDelay > 0) {
|
||||
await this.client.presenceSubscribe(sender);
|
||||
|
||||
await this.client.sendPresenceUpdate((data?.options?.presence as WAPresence) ?? 'composing', sender);
|
||||
|
||||
await delay(remainingDelay);
|
||||
|
||||
await this.client.sendPresenceUpdate('paused', sender);
|
||||
}
|
||||
} else {
|
||||
await this.client.presenceSubscribe(sender);
|
||||
|
||||
await this.client.sendPresenceUpdate((data?.options?.presence as WAPresence) ?? 'composing', sender);
|
||||
|
||||
await delay(data?.options?.delay);
|
||||
|
||||
await this.client.sendPresenceUpdate('paused', sender);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw new BadRequestException(error.toString());
|
||||
@@ -2714,6 +2758,45 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
public async markChatUnread(data: MarkChatUnreadDto) {
|
||||
this.logger.verbose('Marking chat as unread');
|
||||
|
||||
try {
|
||||
let last_message = data.lastMessage;
|
||||
let number = data.chat;
|
||||
|
||||
if (!last_message && number) {
|
||||
last_message = await this.getLastMessage(number);
|
||||
} else {
|
||||
last_message = data.lastMessage;
|
||||
last_message.messageTimestamp = last_message?.messageTimestamp ?? Date.now();
|
||||
number = last_message?.key?.remoteJid;
|
||||
}
|
||||
|
||||
if (!last_message || Object.keys(last_message).length === 0) {
|
||||
throw new NotFoundException('Last message not found');
|
||||
}
|
||||
|
||||
await this.client.chatModify(
|
||||
{
|
||||
markRead: false,
|
||||
lastMessages: [last_message],
|
||||
},
|
||||
this.createJid(number),
|
||||
);
|
||||
|
||||
return {
|
||||
chatId: number,
|
||||
markedChatUnread: true,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new InternalServerErrorException({
|
||||
markedChatUnread: false,
|
||||
message: ['An error occurred while marked unread the chat. Open a calling.', error.toString()],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteMessage(del: DeleteMessage) {
|
||||
this.logger.verbose('Deleting message');
|
||||
try {
|
||||
|
||||
@@ -1258,6 +1258,9 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
public async archiveChat() {
|
||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||
}
|
||||
public async markChatUnread() {
|
||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||
}
|
||||
public async fetchProfile() {
|
||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ export class WAMonitoringService {
|
||||
}
|
||||
}
|
||||
|
||||
public async instanceInfo(instanceName?: string) {
|
||||
public async instanceInfo(instanceName?: string, arrayReturn = false) {
|
||||
this.logger.verbose('get instance info');
|
||||
if (instanceName && !this.waInstances[instanceName]) {
|
||||
throw new NotFoundException(`Instance "${instanceName}" not found`);
|
||||
@@ -171,6 +171,9 @@ export class WAMonitoringService {
|
||||
|
||||
this.logger.verbose('return instance info: ' + instances.length);
|
||||
|
||||
if (arrayReturn) {
|
||||
return [instances.find((i) => i.instance.instanceName === instanceName) ?? instances];
|
||||
}
|
||||
return instances.find((i) => i.instance.instanceName === instanceName) ?? instances;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
import { AuthenticationState, WAConnectionState } from 'baileys';
|
||||
import { AuthenticationState, WAConnectionState } from '@whiskeysockets/baileys';
|
||||
|
||||
export enum Events {
|
||||
APPLICATION_STARTUP = 'application.startup',
|
||||
@@ -69,6 +69,7 @@ export declare namespace wa {
|
||||
number?: string;
|
||||
reopen_conversation?: boolean;
|
||||
conversation_pending?: boolean;
|
||||
merge_brazil_contacts?: boolean;
|
||||
import_contacts?: boolean;
|
||||
import_messages?: boolean;
|
||||
days_limit_import_messages?: number;
|
||||
|
||||
2
src/cache/rediscache.ts
vendored
2
src/cache/rediscache.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import { BufferJSON } from 'baileys';
|
||||
import { BufferJSON } from '@whiskeysockets/baileys';
|
||||
import { RedisClientType } from 'redis';
|
||||
|
||||
import { ICache } from '../api/abstract/abstract.cache';
|
||||
|
||||
@@ -63,11 +63,42 @@ export type Database = {
|
||||
SAVE_DATA: SaveData;
|
||||
};
|
||||
|
||||
export type EventsRabbitmq = {
|
||||
APPLICATION_STARTUP: boolean;
|
||||
INSTANCE_CREATE: boolean;
|
||||
INSTANCE_DELETE: boolean;
|
||||
QRCODE_UPDATED: boolean;
|
||||
MESSAGES_SET: boolean;
|
||||
MESSAGES_UPSERT: boolean;
|
||||
MESSAGES_UPDATE: boolean;
|
||||
MESSAGES_DELETE: boolean;
|
||||
SEND_MESSAGE: boolean;
|
||||
CONTACTS_SET: boolean;
|
||||
CONTACTS_UPDATE: boolean;
|
||||
CONTACTS_UPSERT: boolean;
|
||||
PRESENCE_UPDATE: boolean;
|
||||
CHATS_SET: boolean;
|
||||
CHATS_UPDATE: boolean;
|
||||
CHATS_DELETE: boolean;
|
||||
CHATS_UPSERT: boolean;
|
||||
CONNECTION_UPDATE: boolean;
|
||||
LABELS_EDIT: boolean;
|
||||
LABELS_ASSOCIATION: boolean;
|
||||
GROUPS_UPSERT: boolean;
|
||||
GROUP_UPDATE: boolean;
|
||||
GROUP_PARTICIPANTS_UPDATE: boolean;
|
||||
CALL: boolean;
|
||||
NEW_JWT_TOKEN: boolean;
|
||||
TYPEBOT_START: boolean;
|
||||
TYPEBOT_CHANGE_STATUS: boolean;
|
||||
};
|
||||
|
||||
export type Rabbitmq = {
|
||||
ENABLED: boolean;
|
||||
MODE: string; // global, single, isolated
|
||||
EXCHANGE_NAME: string; // available for global and single, isolated mode will use instance name as exchange
|
||||
URI: string;
|
||||
EXCHANGE_NAME: string;
|
||||
GLOBAL_ENABLED: boolean;
|
||||
EVENTS: EventsRabbitmq;
|
||||
};
|
||||
|
||||
export type Sqs = {
|
||||
@@ -155,7 +186,7 @@ export type CacheConfLocal = {
|
||||
};
|
||||
export type SslConf = { PRIVKEY: string; FULLCHAIN: string };
|
||||
export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook };
|
||||
export type ConfigSessionPhone = { CLIENT: string; NAME: string };
|
||||
export type ConfigSessionPhone = { CLIENT: string; NAME: string; VERSION: string };
|
||||
export type QrCode = { LIMIT: number; COLOR: string };
|
||||
export type Typebot = { API_VERSION: string; KEEP_OPEN: boolean };
|
||||
export type Chatwoot = {
|
||||
@@ -251,8 +282,8 @@ export class ConfigService {
|
||||
LABELS: process.env?.STORE_LABELS === 'true',
|
||||
},
|
||||
CLEAN_STORE: {
|
||||
CLEANING_INTERVAL: Number.isInteger(process.env?.CLEAN_STORE_CLEANING_TERMINAL)
|
||||
? Number.parseInt(process.env.CLEAN_STORE_CLEANING_TERMINAL)
|
||||
CLEANING_INTERVAL: Number.isInteger(process.env?.CLEAN_STORE_CLEANING_INTERVAL)
|
||||
? Number.parseInt(process.env.CLEAN_STORE_CLEANING_INTERVAL)
|
||||
: 7200,
|
||||
MESSAGES: process.env?.CLEAN_STORE_MESSAGES === 'true',
|
||||
MESSAGE_UP: process.env?.CLEAN_STORE_MESSAGE_UP === 'true',
|
||||
@@ -276,9 +307,38 @@ export class ConfigService {
|
||||
},
|
||||
RABBITMQ: {
|
||||
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
||||
MODE: process.env?.RABBITMQ_MODE || 'isolated',
|
||||
GLOBAL_ENABLED: process.env?.RABBITMQ_GLOBAL_ENABLED === 'true',
|
||||
EXCHANGE_NAME: process.env?.RABBITMQ_EXCHANGE_NAME || 'evolution_exchange',
|
||||
URI: process.env.RABBITMQ_URI || '',
|
||||
EVENTS: {
|
||||
APPLICATION_STARTUP: process.env?.RABBITMQ_EVENTS_APPLICATION_STARTUP === 'true',
|
||||
INSTANCE_CREATE: process.env?.RABBITMQ_EVENTS_INSTANCE_CREATE === 'true',
|
||||
INSTANCE_DELETE: process.env?.RABBITMQ_EVENTS_INSTANCE_DELETE === 'true',
|
||||
QRCODE_UPDATED: process.env?.RABBITMQ_EVENTS_QRCODE_UPDATED === 'true',
|
||||
MESSAGES_SET: process.env?.RABBITMQ_EVENTS_MESSAGES_SET === 'true',
|
||||
MESSAGES_UPSERT: process.env?.RABBITMQ_EVENTS_MESSAGES_UPSERT === 'true',
|
||||
MESSAGES_UPDATE: process.env?.RABBITMQ_EVENTS_MESSAGES_UPDATE === 'true',
|
||||
MESSAGES_DELETE: process.env?.RABBITMQ_EVENTS_MESSAGES_DELETE === 'true',
|
||||
SEND_MESSAGE: process.env?.RABBITMQ_EVENTS_SEND_MESSAGE === 'true',
|
||||
CONTACTS_SET: process.env?.RABBITMQ_EVENTS_CONTACTS_SET === 'true',
|
||||
CONTACTS_UPDATE: process.env?.RABBITMQ_EVENTS_CONTACTS_UPDATE === 'true',
|
||||
CONTACTS_UPSERT: process.env?.RABBITMQ_EVENTS_CONTACTS_UPSERT === 'true',
|
||||
PRESENCE_UPDATE: process.env?.RABBITMQ_EVENTS_PRESENCE_UPDATE === 'true',
|
||||
CHATS_SET: process.env?.RABBITMQ_EVENTS_CHATS_SET === 'true',
|
||||
CHATS_UPDATE: process.env?.RABBITMQ_EVENTS_CHATS_UPDATE === 'true',
|
||||
CHATS_UPSERT: process.env?.RABBITMQ_EVENTS_CHATS_UPSERT === 'true',
|
||||
CHATS_DELETE: process.env?.RABBITMQ_EVENTS_CHATS_DELETE === 'true',
|
||||
CONNECTION_UPDATE: process.env?.RABBITMQ_EVENTS_CONNECTION_UPDATE === 'true',
|
||||
LABELS_EDIT: process.env?.RABBITMQ_EVENTS_LABELS_EDIT === 'true',
|
||||
LABELS_ASSOCIATION: process.env?.RABBITMQ_EVENTS_LABELS_ASSOCIATION === 'true',
|
||||
GROUPS_UPSERT: process.env?.RABBITMQ_EVENTS_GROUPS_UPSERT === 'true',
|
||||
GROUP_UPDATE: process.env?.RABBITMQ_EVENTS_GROUPS_UPDATE === 'true',
|
||||
GROUP_PARTICIPANTS_UPDATE: process.env?.RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE === 'true',
|
||||
CALL: process.env?.RABBITMQ_EVENTS_CALL === 'true',
|
||||
NEW_JWT_TOKEN: process.env?.RABBITMQ_EVENTS_NEW_JWT_TOKEN === 'true',
|
||||
TYPEBOT_START: process.env?.RABBITMQ_EVENTS_TYPEBOT_START === 'true',
|
||||
TYPEBOT_CHANGE_STATUS: process.env?.RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS === 'true',
|
||||
},
|
||||
},
|
||||
SQS: {
|
||||
ENABLED: process.env?.SQS_ENABLED === 'true',
|
||||
@@ -360,6 +420,7 @@ export class ConfigService {
|
||||
CONFIG_SESSION_PHONE: {
|
||||
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API',
|
||||
NAME: process.env?.CONFIG_SESSION_PHONE_NAME || 'Chrome',
|
||||
VERSION: process.env?.CONFIG_SESSION_PHONE_VERSION || null,
|
||||
},
|
||||
QRCODE: {
|
||||
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,
|
||||
|
||||
@@ -79,9 +79,35 @@ DATABASE:
|
||||
|
||||
RABBITMQ:
|
||||
ENABLED: false
|
||||
MODE: "global"
|
||||
EXCHANGE_NAME: "evolution_exchange"
|
||||
URI: "amqp://guest:guest@localhost:5672"
|
||||
EXCHANGE_NAME: evolution_exchange
|
||||
GLOBAL_ENABLED: true
|
||||
EVENTS:
|
||||
APPLICATION_STARTUP: false
|
||||
INSTANCE_CREATE: false
|
||||
INSTANCE_DELETE: false
|
||||
QRCODE_UPDATED: false
|
||||
MESSAGES_SET: false
|
||||
MESSAGES_UPSERT: true
|
||||
MESSAGES_UPDATE: true
|
||||
MESSAGES_DELETE: false
|
||||
SEND_MESSAGE: false
|
||||
CONTACTS_SET: false
|
||||
CONTACTS_UPSERT: false
|
||||
CONTACTS_UPDATE: false
|
||||
PRESENCE_UPDATE: false
|
||||
CHATS_SET: false
|
||||
CHATS_UPSERT: false
|
||||
CHATS_UPDATE: false
|
||||
CHATS_DELETE: false
|
||||
GROUPS_UPSERT: true
|
||||
GROUP_UPDATE: true
|
||||
GROUP_PARTICIPANTS_UPDATE: true
|
||||
CONNECTION_UPDATE: true
|
||||
CALL: false
|
||||
# This events is used with Typebot
|
||||
TYPEBOT_START: false
|
||||
TYPEBOT_CHANGE_STATUS: false
|
||||
|
||||
SQS:
|
||||
ENABLED: true
|
||||
@@ -168,7 +194,7 @@ CHATWOOT:
|
||||
# This db connection is used to import messages from whatsapp to chatwoot database
|
||||
DATABASE:
|
||||
CONNECTION:
|
||||
URI: "postgres://user:password@hostname:port/dbname"
|
||||
URI: "postgres://user:password@hostname:port/dbname?sslmode=disable"
|
||||
PLACEHOLDER_MEDIA_MESSAGE: true
|
||||
|
||||
# Cache to optimize application performance
|
||||
|
||||
@@ -25,7 +25,7 @@ info:
|
||||
</font>
|
||||
|
||||
[](https://god.gw.postman.com/run-collection/26869335-5546d063-156b-4529-915f-909dd628c090?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D26869335-5546d063-156b-4529-915f-909dd628c090%26entityType%3Dcollection%26workspaceId%3D339a4ee7-378b-45c9-b5b8-fd2c0a9c2442)
|
||||
version: 1.7.4
|
||||
version: 1.8.0
|
||||
contact:
|
||||
name: DavidsonGomes
|
||||
email: contato@agenciadgcode.com
|
||||
@@ -194,6 +194,8 @@ paths:
|
||||
type: string
|
||||
description: Check the connection state of your instance.
|
||||
example: "evolution"
|
||||
security:
|
||||
- apikeyAuth: []
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@@ -2242,6 +2244,9 @@ paths:
|
||||
conversation_pending:
|
||||
type: boolean
|
||||
description: "Indicates whether to mark conversations as pending."
|
||||
merge_brazil_contacts:
|
||||
type: boolean
|
||||
description: "Indicates whether to merge Brazil numbers in case of numbers with and without ninth digit."
|
||||
import_contacts:
|
||||
type: boolean
|
||||
description: "Indicates whether to import contacts from phone to Chatwoot when connecting."
|
||||
|
||||
@@ -6,7 +6,7 @@ import cors from 'cors';
|
||||
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
||||
import { join } from 'path';
|
||||
|
||||
import { initAMQP } from './api/integrations/rabbitmq/libs/amqp.server';
|
||||
import { initAMQP, initGlobalQueues } from './api/integrations/rabbitmq/libs/amqp.server';
|
||||
import { initSQS } from './api/integrations/sqs/libs/sqs.server';
|
||||
import { initIO } from './api/integrations/websocket/libs/socket.server';
|
||||
import { HttpStatus, router } from './api/routes/index.router';
|
||||
@@ -128,7 +128,11 @@ function bootstrap() {
|
||||
|
||||
initIO(server);
|
||||
|
||||
if (configService.get<Rabbitmq>('RABBITMQ')?.ENABLED) initAMQP();
|
||||
if (configService.get<Rabbitmq>('RABBITMQ')?.ENABLED) {
|
||||
initAMQP().then(() => {
|
||||
if (configService.get<Rabbitmq>('RABBITMQ')?.GLOBAL_ENABLED) initGlobalQueues();
|
||||
});
|
||||
}
|
||||
|
||||
if (configService.get<Sqs>('SQS')?.ENABLED) initSQS();
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { AuthenticationCreds, AuthenticationState, BufferJSON, initAuthCreds, proto, SignalDataTypeMap } from 'baileys';
|
||||
import {
|
||||
AuthenticationCreds,
|
||||
AuthenticationState,
|
||||
BufferJSON,
|
||||
initAuthCreds,
|
||||
proto,
|
||||
SignalDataTypeMap,
|
||||
} from '@whiskeysockets/baileys';
|
||||
|
||||
import { configService, Database } from '../config/env.config';
|
||||
import { Logger } from '../config/logger.config';
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { AuthenticationCreds, AuthenticationState, initAuthCreds, proto, SignalDataTypeMap } from 'baileys';
|
||||
import {
|
||||
AuthenticationCreds,
|
||||
AuthenticationState,
|
||||
initAuthCreds,
|
||||
proto,
|
||||
SignalDataTypeMap,
|
||||
} from '@whiskeysockets/baileys';
|
||||
|
||||
import { CacheService } from '../api/services/cache.service';
|
||||
import { Logger } from '../config/logger.config';
|
||||
|
||||
@@ -597,6 +597,33 @@ export const archiveChatSchema: JSONSchema7 = {
|
||||
required: ['archive'],
|
||||
};
|
||||
|
||||
export const markChatUnreadSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
chat: { type: 'string' },
|
||||
lastMessage: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
key: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string' },
|
||||
remoteJid: { type: 'string' },
|
||||
fromMe: { type: 'boolean', enum: [true, false] },
|
||||
},
|
||||
required: ['id', 'fromMe', 'remoteJid'],
|
||||
...isNotEmpty('id', 'remoteJid'),
|
||||
},
|
||||
messageTimestamp: { type: 'integer', minLength: 1 },
|
||||
},
|
||||
required: ['key'],
|
||||
...isNotEmpty('messageTimestamp'),
|
||||
},
|
||||
},
|
||||
required: ['lastMessage'],
|
||||
};
|
||||
|
||||
export const deleteMessageSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
|
||||
Reference in New Issue
Block a user