Merge branch 'develop' into patch-1

This commit is contained in:
Davidson Gomes 2023-07-19 12:32:06 -03:00 committed by GitHub
commit 22ead22499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 568 additions and 457 deletions

View File

@ -1,3 +1,40 @@
# 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) # 1.2.2 (2023-07-15 09:36)
### Fixed ### Fixed

View File

@ -59,6 +59,7 @@ WEBHOOK_EVENTS_QRCODE_UPDATED=true
WEBHOOK_EVENTS_MESSAGES_SET=true WEBHOOK_EVENTS_MESSAGES_SET=true
WEBHOOK_EVENTS_MESSAGES_UPSERT=true WEBHOOK_EVENTS_MESSAGES_UPSERT=true
WEBHOOK_EVENTS_MESSAGES_UPDATE=true WEBHOOK_EVENTS_MESSAGES_UPDATE=true
WEBHOOK_EVENTS_MESSAGES_DELETE=true
WEBHOOK_EVENTS_SEND_MESSAGE=true WEBHOOK_EVENTS_SEND_MESSAGE=true
WEBHOOK_EVENTS_CONTACTS_SET=true WEBHOOK_EVENTS_CONTACTS_SET=true
WEBHOOK_EVENTS_CONTACTS_UPSERT=true WEBHOOK_EVENTS_CONTACTS_UPSERT=true

View File

@ -15,8 +15,6 @@ services:
volumes: volumes:
- evolution_mongodb_data:/data/db - evolution_mongodb_data:/data/db
- evolution_mongodb_configdb:/data/configdb - evolution_mongodb_configdb:/data/configdb
networks:
- evolution-net
expose: expose:
- 27017 - 27017
@ -38,6 +36,6 @@ volumes:
evolution_mongodb_configdb: evolution_mongodb_configdb:
networks: networks:
default: evolution-net:
name: evolution-net external: true

View File

@ -24,5 +24,5 @@ volumes:
evolution_redis: evolution_redis:
networks: networks:
default: evolution-net:
name: evolution-net external: true

View File

@ -13,86 +13,90 @@ 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 SERVER_URL=$SERVER_URL
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=$LOG_COLOR 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_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 REDIS_PREFIX_KEY=$REDIS_PREFIX_KEY 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_UPSERT=$WEBHOOK_EVENTS_MESSAGES_UPSERT
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
ENV WEBHOOK_EVENTS_SEND_MESSAGE=$WEBHOOK_EVENTS_SEND_MESSAGE
ENV WEBHOOK_EVENTS_CONTACTS_SET=$WEBHOOK_EVENTS_CONTACTS_SET
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=$WEBHOOK_EVENTS_CONTACTS_UPSERT
ENV WEBHOOK_EVENTS_CONTACTS_UPDATE=$WEBHOOK_EVENTS_CONTACTS_UPDATE
ENV WEBHOOK_EVENTS_PRESENCE_UPDATE=$WEBHOOK_EVENTS_PRESENCE_UPDATE
ENV WEBHOOK_EVENTS_CHATS_SET=$WEBHOOK_EVENTS_CHATS_SET
ENV WEBHOOK_EVENTS_CHATS_UPSERT=$WEBHOOK_EVENTS_CHATS_UPSERT
ENV WEBHOOK_EVENTS_CHATS_UPDATE=$WEBHOOK_EVENTS_CHATS_UPDATE
ENV WEBHOOK_EVENTS_CONNECTION_UPDATE=$WEBHOOK_EVENTS_CONNECTION_UPDATE
ENV WEBHOOK_EVENTS_GROUPS_UPSERT=$WEBHOOK_EVENTS_GROUPS_UPSERT
ENV WEBHOOK_EVENTS_GROUPS_UPDATE=$WEBHOOK_EVENTS_GROUPS_UPDATE
ENV WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=$WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE
ENV WEBHOOK_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 QRCODE_LIMIT=$QRCODE_LIMIT ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
ENV AUTHENTICATION_TYPE=$AUTHENTICATION_TYPE ENV CONFIG_SESSION_PHONE_CLIENT='Evolution API'
ENV CONFIG_SESSION_PHONE_NAME=chrome
ENV AUTHENTICATION_API_KEY=$AUTHENTICATION_API_KEY ENV 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_CHATWOOT_ACCOUNT_ID=$AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID
ENV AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=$AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN ENV AUTHENTICATION_JWT_EXPIRIN_IN=0
ENV AUTHENTICATION_INSTANCE_CHATWOOT_URL=$AUTHENTICATION_INSTANCE_CHATWOOT_URL ENV AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
ENV AUTHENTICATION_INSTANCE_MODE=$AUTHENTICATION_INSTANCE_MODE
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

View File

@ -1,72 +0,0 @@
version: '3.3'
services:
redis:
image: redis:latest
container_name: redis
ports:
- 6379:6379
rebrow:
image: marian/rebrow
ports:
- 5001:5001
links:
- redis
mongodb:
container_name: mongodb
image: mongo
restart: always
volumes:
- evolution_mongodb_data:/data/db
- evolution_mongodb_configdb:/data/configdb
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
expose:
- 27017
mongo-express:
image: mongo-express
environment:
ME_CONFIG_BASICAUTH_USERNAME: root
ME_CONFIG_BASICAUTH_PASSWORD: root
ME_CONFIG_MONGODB_SERVER: mongodb
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: root
ports:
- 8081:8081
links:
- mongodb
api:
container_name: evolution_api
image: evolution/api:local
restart: always
ports:
- 8080:8080
volumes:
- evolution_instances:/evolution/instances
- evolution_store:/evolution/store
env_file:
- ./Docker/.env
command: ['node', './dist/src/main.js']
expose:
- 8080
links:
- mongodb
- redis
volumes:
evolution_instances:
evolution_store:
evolution_mongodb_data:
evolution_mongodb_configdb:
evolution_redis:
networks:
default:
name: evolution-net

View File

@ -21,6 +21,6 @@ volumes:
evolution_store: evolution_store:
networks: networks:
default: evolution-net:
name: evolution-net external: true

View File

@ -1,6 +1,6 @@
{ {
"name": "evolution-api", "name": "evolution-api",
"version": "1.2.2", "version": "1.3.0",
"description": "Rest api for communication with WhatsApp", "description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js", "main": "./dist/src/main.js",
"scripts": { "scripts": {
@ -44,7 +44,8 @@
"@ffmpeg-installer/ffmpeg": "^1.1.0", "@ffmpeg-installer/ffmpeg": "^1.1.0",
"@figuro/chatwoot-sdk": "^1.1.14", "@figuro/chatwoot-sdk": "^1.1.14",
"@hapi/boom": "^10.0.1", "@hapi/boom": "^10.0.1",
"@whiskeysockets/baileys": "github:DavidsonGomes/Baileys", "@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",

View File

@ -1,7 +1,6 @@
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; URL: string }; export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
@ -76,6 +75,7 @@ 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; SEND_MESSAGE: boolean;
CONTACTS_SET: boolean; CONTACTS_SET: boolean;
CONTACTS_UPDATE: boolean; CONTACTS_UPDATE: boolean;
@ -98,9 +98,9 @@ export type Instance = {
NAME: string; NAME: string;
WEBHOOK_URL: string; WEBHOOK_URL: string;
MODE: string; MODE: string;
CHATWOOT_ACCOUNT_ID?: string; CHATWOOT_ACCOUNT_ID: string;
CHATWOOT_TOKEN?: string; CHATWOOT_TOKEN: string;
CHATWOOT_URL?: string; CHATWOOT_URL: string;
}; };
export type Auth = { export type Auth = {
API_KEY: ApiKey; API_KEY: ApiKey;
@ -193,7 +193,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',
@ -225,7 +225,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,
@ -238,6 +238,7 @@ 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', 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',
@ -256,11 +257,11 @@ export class ConfigService {
}, },
}, },
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',

View File

@ -39,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
@ -96,6 +96,7 @@ WEBHOOK:
MESSAGES_SET: true MESSAGES_SET: true
MESSAGES_UPSERT: true MESSAGES_UPSERT: true
MESSAGES_UPDATE: true MESSAGES_UPDATE: true
MESSAGES_DELETE: true
SEND_MESSAGE: true SEND_MESSAGE: true
CONTACTS_SET: true CONTACTS_SET: true
CONTACTS_UPSERT: true CONTACTS_UPSERT: true

View File

@ -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) {

View File

@ -39,6 +39,7 @@ export const instanceNameSchema: JSONSchema7 = {
'MESSAGES_SET', 'MESSAGES_SET',
'MESSAGES_UPSERT', 'MESSAGES_UPSERT',
'MESSAGES_UPDATE', 'MESSAGES_UPDATE',
'MESSAGES_DELETE',
'SEND_MESSAGE', 'SEND_MESSAGE',
'CONTACTS_SET', 'CONTACTS_SET',
'CONTACTS_UPSERT', 'CONTACTS_UPSERT',
@ -81,8 +82,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' },
}, },
@ -144,24 +145,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',
@ -846,6 +829,7 @@ export const webhookSchema: JSONSchema7 = {
'MESSAGES_SET', 'MESSAGES_SET',
'MESSAGES_UPSERT', 'MESSAGES_UPSERT',
'MESSAGES_UPDATE', 'MESSAGES_UPDATE',
'MESSAGES_DELETE',
'SEND_MESSAGE', 'SEND_MESSAGE',
'CONTACTS_SET', 'CONTACTS_SET',
'CONTACTS_UPSERT', 'CONTACTS_UPSERT',

View File

@ -160,8 +160,6 @@ export abstract class RouterBroker {
const v = validate(ref, schema); const v = validate(ref, schema);
console.log(v, '@checkei aqui');
if (!v.valid) { if (!v.valid) {
const message: any[] = v.errors.map(({ property, stack, schema }) => { const message: any[] = v.errors.map(({ property, stack, schema }) => {
let message: string; let message: string;
@ -203,8 +201,6 @@ export abstract class RouterBroker {
const v = validate(ref, schema); const v = validate(ref, schema);
console.log(v, '@checkei aqui');
if (!v.valid) { if (!v.valid) {
const message: any[] = v.errors.map(({ property, stack, schema }) => { const message: any[] = v.errors.map(({ property, stack, schema }) => {
let message: string; let message: string;

View File

@ -66,6 +66,18 @@ export class ChatwootController {
const urlServer = this.configService.get<HttpServer>('SERVER').URL; const urlServer = this.configService.get<HttpServer>('SERVER').URL;
if (Object.keys(result).length === 0) {
return {
enabled: false,
url: '',
account_id: '',
token: '',
sign_msg: false,
name_inbox: '',
webhook_url: '',
};
}
const response = { const response = {
...result, ...result,
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`, webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
@ -78,7 +90,7 @@ export class ChatwootController {
logger.verbose( logger.verbose(
'requested receiveWebhook from ' + instance.instanceName + ' instance', 'requested receiveWebhook from ' + instance.instanceName + ' instance',
); );
const chatwootService = new ChatwootService(waMonitor); const chatwootService = new ChatwootService(waMonitor, this.configService);
return chatwootService.receiveWebhook(instance, data); return chatwootService.receiveWebhook(instance, data);
} }

View File

@ -12,6 +12,7 @@ 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';
export class InstanceController { export class InstanceController {
constructor( constructor(
@ -63,7 +64,10 @@ export class InstanceController {
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.logger.verbose('instance: ' + instance.instanceName + ' created');
this.waMonitor.waInstances[instance.instanceName] = instance; this.waMonitor.waInstances[instance.instanceName] = instance;
@ -82,6 +86,9 @@ export class InstanceController {
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'); this.logger.verbose('creating webhook');
try { try {
this.webhookService.create(instance, { this.webhookService.create(instance, {
@ -132,6 +139,10 @@ export class InstanceController {
throw new BadRequestException('url is required'); throw new BadRequestException('url is required');
} }
if (!isURL(chatwoot_url, { require_tld: false })) {
throw new BadRequestException('Invalid "url" property in chatwoot');
}
const urlServer = this.configService.get<HttpServer>('SERVER').URL; const urlServer = this.configService.get<HttpServer>('SERVER').URL;
try { try {
@ -183,7 +194,10 @@ export class InstanceController {
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.logger.verbose('instance: ' + instance.instanceName + ' created');
@ -203,6 +217,10 @@ export class InstanceController {
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'); this.logger.verbose('creating webhook');
try { try {
this.webhookService.create(instance, { this.webhookService.create(instance, {
@ -266,6 +284,10 @@ export class InstanceController {
throw new BadRequestException('url is required'); throw new BadRequestException('url is required');
} }
if (!isURL(chatwoot_url, { require_tld: false })) {
throw new BadRequestException('Invalid "url" property in chatwoot');
}
const urlServer = this.configService.get<HttpServer>('SERVER').URL; const urlServer = this.configService.get<HttpServer>('SERVER').URL;
try { try {
@ -341,24 +363,8 @@ export class InstanceController {
try { try {
this.logger.verbose('requested restartInstance from ' + instanceName + ' instance'); this.logger.verbose('requested restartInstance from ' + instanceName + ' instance');
this.logger.verbose('deleting instance: ' + instanceName); this.logger.verbose('logging out instance: ' + instanceName);
delete this.waMonitor.waInstances[instanceName]; this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
this.logger.verbose('creating instance: ' + instanceName);
const instance = new WAStartupService(
this.configService,
this.eventEmitter,
this.repository,
this.cache,
);
instance.instanceName = instanceName;
this.logger.verbose('instance: ' + instance.instanceName + ' created');
this.logger.verbose('connecting instance: ' + instanceName);
await instance.connectToWhatsapp();
this.waMonitor.waInstances[instance.instanceName] = instance;
return { error: false, message: 'Instance restarted' }; return { error: false, message: 'Instance restarted' };
} catch (error) { } catch (error) {

View File

@ -5,7 +5,6 @@ import {
SendAudioDto, SendAudioDto,
SendButtonDto, SendButtonDto,
SendContactDto, SendContactDto,
SendLinkPreviewDto,
SendListDto, SendListDto,
SendLocationDto, SendLocationDto,
SendMediaDto, SendMediaDto,
@ -31,9 +30,15 @@ export class SendMessageController {
public async sendMedia({ instanceName }: InstanceDto, data: SendMediaDto) { public async sendMedia({ instanceName }: InstanceDto, data: SendMediaDto) {
logger.verbose('requested sendMedia from ' + instanceName + ' instance'); logger.verbose('requested sendMedia from ' + instanceName + ' instance');
if (isBase64(data?.mediaMessage?.media) && !data?.mediaMessage?.fileName) {
throw new BadRequestException('For bse64 the file name must be informed.'); if (
isBase64(data?.mediaMessage?.media) &&
!data?.mediaMessage?.fileName &&
data?.mediaMessage?.mediatype === 'document'
) {
throw new BadRequestException('For base64 the file name must be informed.');
} }
logger.verbose( logger.verbose(
'isURL: ' + 'isURL: ' +
isURL(data?.mediaMessage?.media) + isURL(data?.mediaMessage?.media) +
@ -119,9 +124,4 @@ export class SendMessageController {
logger.verbose('requested sendStatus from ' + instanceName + ' instance'); logger.verbose('requested sendStatus from ' + instanceName + ' instance');
return await this.waMonitor.waInstances[instanceName].statusMessage(data); return await this.waMonitor.waInstances[instanceName].statusMessage(data);
} }
public async sendLinkPreview({ instanceName }: InstanceDto, data: SendLinkPreviewDto) {
logger.verbose('requested sendLinkPreview from ' + instanceName + ' instance');
return await this.waMonitor.waInstances[instanceName].linkPreview(data);
}
} }

View File

@ -28,10 +28,6 @@ class TextMessage {
text: string; text: string;
} }
class linkPreviewMessage {
text: string;
}
export class StatusMessage { export class StatusMessage {
type: string; type: string;
content: string; content: string;
@ -52,10 +48,6 @@ export class SendTextDto extends Metadata {
textMessage: TextMessage; textMessage: TextMessage;
} }
export class SendLinkPreviewDto extends Metadata {
linkPreview: linkPreviewMessage;
}
export class SendStatusDto extends Metadata { export class SendStatusDto extends Metadata {
statusMessage: StatusMessage; statusMessage: StatusMessage;
} }

View File

@ -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');

View File

@ -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');

View File

@ -5,12 +5,13 @@ 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 { ChatwootRepository } from './chatwoot.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 { execSync } from 'child_process';
import { join } from 'path'; import { join } from 'path';
import fs from 'fs';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../config/logger.config';
export class RepositoryBroker { export class RepositoryBroker {
constructor( constructor(
public readonly message: MessageRepository, public readonly message: MessageRepository,
@ -23,7 +24,6 @@ export class RepositoryBroker {
private configService: ConfigService, private configService: ConfigService,
dbServer?: MongoClient, dbServer?: MongoClient,
) { ) {
this.logger.verbose('initializing repository broker');
this.dbClient = dbServer; this.dbClient = dbServer;
this.__init_repo_without_db__(); this.__init_repo_without_db__();
} }
@ -38,39 +38,54 @@ export class RepositoryBroker {
private __init_repo_without_db__() { private __init_repo_without_db__() {
this.logger.verbose('initializing repository without db'); this.logger.verbose('initializing repository without db');
if (!this.configService.get<Database>('DATABASE').ENABLED) { if (!this.configService.get<Database>('DATABASE').ENABLED) {
this.logger.verbose('database is disabled');
const storePath = join(process.cwd(), 'store'); const storePath = join(process.cwd(), 'store');
this.logger.verbose('creating store path: ' + storePath); this.logger.verbose('creating store path: ' + storePath);
execSync( try {
`mkdir -p ${join( const authDir = join(
storePath, storePath,
'auth', 'auth',
this.configService.get<Auth>('AUTHENTICATION').TYPE, this.configService.get<Auth>('AUTHENTICATION').TYPE,
)}`, );
); const chatsDir = join(storePath, 'chats');
const contactsDir = join(storePath, 'contacts');
const messagesDir = join(storePath, 'messages');
const messageUpDir = join(storePath, 'message-up');
const webhookDir = join(storePath, 'webhook');
const chatwootDir = join(storePath, 'chatwoot');
this.logger.verbose('creating chats path: ' + join(storePath, 'chats')); // Check if directories exist, create them if not
execSync(`mkdir -p ${join(storePath, 'chats')}`); if (!fs.existsSync(authDir)) {
this.logger.verbose('creating auth dir: ' + authDir);
this.logger.verbose('creating contacts path: ' + join(storePath, 'contacts')); fs.mkdirSync(authDir, { recursive: true });
execSync(`mkdir -p ${join(storePath, 'contacts')}`); }
if (!fs.existsSync(chatsDir)) {
this.logger.verbose('creating messages path: ' + join(storePath, 'messages')); this.logger.verbose('creating chats dir: ' + chatsDir);
execSync(`mkdir -p ${join(storePath, 'messages')}`); fs.mkdirSync(chatsDir, { recursive: true });
}
this.logger.verbose('creating message-up path: ' + join(storePath, 'message-up')); if (!fs.existsSync(contactsDir)) {
execSync(`mkdir -p ${join(storePath, 'message-up')}`); this.logger.verbose('creating contacts dir: ' + contactsDir);
fs.mkdirSync(contactsDir, { recursive: true });
this.logger.verbose('creating webhook path: ' + join(storePath, 'webhook')); }
execSync(`mkdir -p ${join(storePath, 'webhook')}`); if (!fs.existsSync(messagesDir)) {
this.logger.verbose('creating messages dir: ' + messagesDir);
this.logger.verbose('creating chatwoot path: ' + join(storePath, 'chatwoot')); fs.mkdirSync(messagesDir, { recursive: true });
execSync(`mkdir -p ${join(storePath, 'chatwoot')}`); }
if (!fs.existsSync(messageUpDir)) {
this.logger.verbose('creating temp path: ' + join(storePath, 'temp')); this.logger.verbose('creating message-up dir: ' + messageUpDir);
execSync(`mkdir -p ${join(storePath, 'temp')}`); 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 });
}
} catch (error) {
this.logger.error(error);
}
} }
} }
} }

View File

@ -23,6 +23,7 @@ export class InstanceRouter extends RouterBroker {
logger.verbose('request query: '); logger.verbose('request query: ');
logger.verbose(req.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,

View File

@ -3,7 +3,6 @@ import {
audioMessageSchema, audioMessageSchema,
buttonMessageSchema, buttonMessageSchema,
contactMessageSchema, contactMessageSchema,
linkPreviewSchema,
listMessageSchema, listMessageSchema,
locationMessageSchema, locationMessageSchema,
mediaMessageSchema, mediaMessageSchema,
@ -17,7 +16,6 @@ import {
SendAudioDto, SendAudioDto,
SendButtonDto, SendButtonDto,
SendContactDto, SendContactDto,
SendLinkPreviewDto,
SendListDto, SendListDto,
SendLocationDto, SendLocationDto,
SendMediaDto, SendMediaDto,
@ -199,23 +197,6 @@ 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) => {
logger.verbose('request received in sendLinkPreview');
logger.verbose('request body: ');
logger.verbose(req.body);
logger.verbose('request query: ');
logger.verbose(req.query);
const response = await this.dataValidate<SendLinkPreviewDto>({
request: req,
schema: linkPreviewSchema,
ClassRef: SendLinkPreviewDto,
execute: (instance, data) =>
sendMessageController.sendLinkPreview(instance, data),
});
return res.status(HttpStatus.CREATED).json(response);
})
.post(this.routerPath('sendSticker'), ...guards, async (req, res) => { .post(this.routerPath('sendSticker'), ...guards, async (req, res) => {
logger.verbose('request received in sendSticker'); logger.verbose('request received in sendSticker');
logger.verbose('request body: '); logger.verbose('request body: ');

View File

@ -12,6 +12,7 @@ import mimeTypes from 'mime-types';
import { SendAudioDto } from '../dto/sendMessage.dto'; import { SendAudioDto } from '../dto/sendMessage.dto';
import { SendMediaDto } from '../dto/sendMessage.dto'; import { SendMediaDto } from '../dto/sendMessage.dto';
import { ROOT_DIR } from '../../config/path.config'; import { ROOT_DIR } from '../../config/path.config';
import { ConfigService, HttpServer } from '../../config/env.config';
export class ChatwootService { export class ChatwootService {
private messageCacheFile: string; private messageCacheFile: string;
@ -21,7 +22,10 @@ export class ChatwootService {
private provider: any; private provider: any;
constructor(private readonly waMonitor: WAMonitoringService) { constructor(
private readonly waMonitor: WAMonitoringService,
private readonly configService: ConfigService,
) {
this.messageCache = new Set(); this.messageCache = new Set();
} }
@ -243,7 +247,7 @@ export class ChatwootService {
accountId: this.provider.account_id, accountId: this.provider.account_id,
conversationId: conversation.id, conversationId: conversation.id,
data: { data: {
content: '/iniciar', content: '/init',
message_type: 'outgoing', message_type: 'outgoing',
}, },
}); });
@ -433,7 +437,7 @@ export class ChatwootService {
instance, instance,
body.key.participant.split('@')[0], body.key.participant.split('@')[0],
filterInbox.id, filterInbox.id,
isGroup, false,
body.pushName, body.pushName,
picture_url.profilePictureUrl || null, picture_url.profilePictureUrl || null,
); );
@ -449,21 +453,24 @@ export class ChatwootService {
const findContact = await this.findContact(instance, chatId); const findContact = await this.findContact(instance, chatId);
let contact: any; let contact: any;
if (body.key.fromMe) {
if (findContact) { contact = findContact;
contact = await this.updateContact(instance, findContact.id, {
name: nameContact,
avatar_url: picture_url.profilePictureUrl || null,
});
} else { } else {
contact = await this.createContact( if (findContact) {
instance, contact = await this.updateContact(instance, findContact.id, {
chatId, name: nameContact,
filterInbox.id, avatar_url: picture_url.profilePictureUrl || null,
isGroup, });
nameContact, } else {
picture_url.profilePictureUrl || null, contact = await this.createContact(
); instance,
chatId,
filterInbox.id,
isGroup,
nameContact,
picture_url.profilePictureUrl || null,
);
}
} }
if (!contact) { if (!contact) {
@ -471,7 +478,8 @@ export class ChatwootService {
return null; return null;
} }
const contactId = contact.payload.id || contact.payload.contact.id; const contactId =
contact?.payload?.id || contact?.payload?.contact?.id || contact?.id;
if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) { if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) {
this.logger.verbose('update contact name in chatwoot'); this.logger.verbose('update contact name in chatwoot');
@ -928,8 +936,8 @@ export class ChatwootService {
const command = messageReceived.replace('/', ''); const command = messageReceived.replace('/', '');
if (command === 'iniciar') { if (command === 'init' || command === 'iniciar') {
this.logger.verbose('command iniciar found'); this.logger.verbose('command init found');
const state = waInstance?.connectionStatus?.state; const state = waInstance?.connectionStatus?.state;
if (state !== 'open') { if (state !== 'open') {
@ -939,7 +947,7 @@ export class ChatwootService {
this.logger.verbose('whatsapp already connected'); this.logger.verbose('whatsapp already connected');
await this.createBotMessage( await this.createBotMessage(
instance, instance,
`🚨 Instância ${body.inbox.name} já está conectada.`, `🚨 ${body.inbox.name} instance is connected.`,
'incoming', 'incoming',
); );
} }
@ -954,7 +962,7 @@ export class ChatwootService {
this.logger.verbose('state not found'); this.logger.verbose('state not found');
await this.createBotMessage( await this.createBotMessage(
instance, instance,
`⚠️ Instância ${body.inbox.name} não existe.`, `⚠️ ${body.inbox.name} instance not found.`,
'incoming', 'incoming',
); );
} }
@ -963,16 +971,16 @@ export class ChatwootService {
this.logger.verbose('state: ' + state + ' found'); this.logger.verbose('state: ' + state + ' found');
await this.createBotMessage( await this.createBotMessage(
instance, instance,
`⚠️ Status da instância ${body.inbox.name}: *${state}*`, `⚠️ ${body.inbox.name} instance status: *${state}*`,
'incoming', 'incoming',
); );
} }
} }
if (command === 'desconectar') { if (command === 'disconnect' || command === 'desconectar') {
this.logger.verbose('command desconectar found'); this.logger.verbose('command disconnect found');
const msgLogout = `🚨 Desconectando Whatsapp da caixa de entrada *${body.inbox.name}*: `; const msgLogout = `🚨 Disconnecting Whatsapp from inbox *${body.inbox.name}*: `;
this.logger.verbose('send message to chatwoot'); this.logger.verbose('send message to chatwoot');
await this.createBotMessage(instance, msgLogout, 'incoming'); await this.createBotMessage(instance, msgLogout, 'incoming');
@ -981,6 +989,33 @@ export class ChatwootService {
await waInstance?.client?.logout('Log out instance: ' + instance.instanceName); await waInstance?.client?.logout('Log out instance: ' + instance.instanceName);
await waInstance?.client?.ws?.close(); await waInstance?.client?.ws?.close();
} }
if (command.includes('#inbox_whatsapp')) {
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
const data = {
instanceName: command.split(':')[1],
qrcode: true,
chatwoot_account_id: this.provider.account_id,
chatwoot_token: this.provider.token,
chatwoot_url: this.provider.url,
chatwoot_sign_msg: this.provider.sign_msg,
};
const config = {
method: 'post',
maxBodyLength: Infinity,
url: `${urlServer}/instance/create`,
headers: {
'Content-Type': 'application/json',
apikey: apiKey,
},
data: data,
};
await axios.request(config);
}
} }
if ( if (
@ -1059,7 +1094,11 @@ export class ChatwootService {
} }
} }
if (body.message_type === 'template' && body.content_type === 'input_csat') { if (
body.message_type === 'template' &&
body.content_type === 'input_csat' &&
body.event === 'message_created'
) {
this.logger.verbose('check if is csat'); this.logger.verbose('check if is csat');
const data: SendTextDto = { const data: SendTextDto = {
@ -1119,6 +1158,8 @@ export class ChatwootService {
documentWithCaptionMessage: documentWithCaptionMessage:
msg.documentWithCaptionMessage?.message?.documentMessage?.caption, msg.documentWithCaptionMessage?.message?.documentMessage?.caption,
audioMessage: msg.audioMessage?.caption, audioMessage: msg.audioMessage?.caption,
contactMessage: msg.contactMessage?.vcard,
contactsArrayMessage: msg.contactsArrayMessage,
}; };
this.logger.verbose('type message: ' + types); this.logger.verbose('type message: ' + types);
@ -1132,6 +1173,67 @@ export class ChatwootService {
const result = typeKey ? types[typeKey] : undefined; const result = typeKey ? types[typeKey] : undefined;
if (typeKey === 'contactMessage') {
const vCardData = result.split('\n');
const contactInfo = {};
vCardData.forEach((line) => {
const [key, value] = line.split(':');
if (key && value) {
contactInfo[key] = value;
}
});
let formattedContact = `**Contact:**
**name:** ${contactInfo['FN']}`;
let numberCount = 1;
Object.keys(contactInfo).forEach((key) => {
if (key.startsWith('item') && key.includes('TEL')) {
const phoneNumber = contactInfo[key];
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
numberCount++;
}
});
this.logger.verbose('message content: ' + formattedContact);
return formattedContact;
}
if (typeKey === 'contactsArrayMessage') {
const formattedContacts = result.contacts.map((contact) => {
const vCardData = contact.vcard.split('\n');
const contactInfo = {};
vCardData.forEach((line) => {
const [key, value] = line.split(':');
if (key && value) {
contactInfo[key] = value;
}
});
let formattedContact = `**Contact:**
**name:** ${contact.displayName}`;
let numberCount = 1;
Object.keys(contactInfo).forEach((key) => {
if (key.startsWith('item') && key.includes('TEL')) {
const phoneNumber = contactInfo[key];
formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`;
numberCount++;
}
});
return formattedContact;
});
const formattedContactsArray = formattedContacts.join('\n\n');
this.logger.verbose('formatted contacts: ' + formattedContactsArray);
return formattedContactsArray;
}
this.logger.verbose('message content: ' + result); this.logger.verbose('message content: ' + result);
return result; return result;
@ -1386,7 +1488,7 @@ export class ChatwootService {
return; return;
} }
const msgStatus = `⚡️ Status da instância ${inbox.name}: ${data.status}`; const msgStatus = `⚡️ Instance status ${inbox.name}: ${data.status}`;
this.logger.verbose('send message to chatwoot'); this.logger.verbose('send message to chatwoot');
await this.createBotMessage(instance, msgStatus, 'incoming'); await this.createBotMessage(instance, msgStatus, 'incoming');
@ -1394,43 +1496,20 @@ export class ChatwootService {
if (event === 'connection.update') { if (event === 'connection.update') {
this.logger.verbose('event connection.update'); this.logger.verbose('event connection.update');
if (body.state === 'open') {
const msgConnection = `🚀 Conexão realizada com sucesso!`; if (body.status === 'open') {
const msgConnection = `🚀 Connection successfully established!`;
this.logger.verbose('send message to chatwoot'); this.logger.verbose('send message to chatwoot');
await this.createBotMessage(instance, msgConnection, 'incoming'); await this.createBotMessage(instance, msgConnection, 'incoming');
} }
} }
if (event === 'contacts.update') {
this.logger.verbose('event contacts.update');
const data = body;
if (data.length) {
this.logger.verbose('contacts found');
for (const item of data) {
const number = item.id.split('@')[0];
const photo = item.profilePictureUrl || null;
this.logger.verbose('find contact in chatwoot');
const find = await this.findContact(instance, number);
if (find) {
this.logger.verbose('contact found');
this.logger.verbose('update contact in chatwoot');
await this.updateContact(instance, find.id, {
avatar_url: photo,
});
}
}
}
}
if (event === 'qrcode.updated') { if (event === 'qrcode.updated') {
this.logger.verbose('event qrcode.updated'); this.logger.verbose('event qrcode.updated');
if (body.statusCode === 500) { if (body.statusCode === 500) {
this.logger.verbose('qrcode error'); this.logger.verbose('qrcode error');
const erroQRcode = `🚨 Limite de geração de QRCode atingido, para gerar um novo QRCode, envie a mensagem /iniciar novamente.`; const erroQRcode = `🚨 QRCode generation limit reached, to generate a new QRCode, send the /init message again.`;
this.logger.verbose('send message to chatwoot'); this.logger.verbose('send message to chatwoot');
return await this.createBotMessage(instance, erroQRcode, 'incoming'); return await this.createBotMessage(instance, erroQRcode, 'incoming');
@ -1455,12 +1534,12 @@ export class ChatwootService {
this.logger.verbose('send qrcode to chatwoot'); this.logger.verbose('send qrcode to chatwoot');
await this.createBotQr( await this.createBotQr(
instance, instance,
'QRCode gerado com sucesso!', 'QRCode successfully generated!',
'incoming', 'incoming',
fileName, fileName,
); );
const msgQrCode = `⚡️ QRCode gerado com sucesso!\n\nDigitalize este código QR nos próximos 40 segundos:`; const msgQrCode = `⚡️ QRCode successfully generated!\n\nScan this QR code within the next 40 seconds:`;
this.logger.verbose('send message to chatwoot'); this.logger.verbose('send message to chatwoot');
await this.createBotMessage(instance, msgQrCode, 'incoming'); await this.createBotMessage(instance, msgQrCode, 'incoming');

View File

@ -99,72 +99,54 @@ export class WAMonitoringService {
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,
profileStatus: (await value.getProfileStatus()) || '', profileStatus: (await value.getProfileStatus()) || '',
status: value.connectionStatus.state, status: value.connectionStatus.state,
apikey, },
chatwoot, };
},
}); if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
} else { instanceData.instance['serverUrl'] =
this.logger.verbose( this.configService.get<HttpServer>('SERVER').URL;
'instance: ' + key + ' - hash not exposed in fetch instances',
); instanceData.instance['apikey'] = (
instances.push({ await this.repository.auth.find(key)
instance: { ).apikey;
instanceName: key,
owner: value.wuid, instanceData.instance['chatwoot'] = chatwoot;
profileName: (await value.getProfileName()) || 'not loaded',
profilePictureUrl: value.profilePictureUrl,
profileStatus: (await value.getProfileStatus()) || '',
status: value.connectionStatus.state,
},
});
} }
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: { instance: {
instanceName: key, instanceName: key,
status: value.connectionStatus.state, status: value.connectionStatus.state,
apikey, },
chatwoot, };
},
}); if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
} else { instanceData.instance['serverUrl'] =
this.logger.verbose( this.configService.get<HttpServer>('SERVER').URL;
'instance: ' + key + ' - hash not exposed in fetch instances',
); instanceData.instance['apikey'] = (
instances.push({ await this.repository.auth.find(key)
instance: { ).apikey;
instanceName: key,
status: value.connectionStatus.state, instanceData.instance['chatwoot'] = chatwoot;
},
});
} }
instances.push(instanceData);
} }
} }
} }

View File

@ -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 };
} }
} }
} }

View File

@ -76,7 +76,6 @@ import {
SendReactionDto, SendReactionDto,
SendTextDto, SendTextDto,
SendPollDto, SendPollDto,
SendLinkPreviewDto,
SendStickerDto, SendStickerDto,
SendStatusDto, SendStatusDto,
StatusMessage, StatusMessage,
@ -150,7 +149,7 @@ export class WAStartupService {
private endSession = false; private endSession = false;
private logBaileys = this.configService.get<Log>('LOG').BAILEYS; private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
private chatwootService = new ChatwootService(waMonitor); private chatwootService = new ChatwootService(waMonitor, this.configService);
public set instanceName(name: string) { public set instanceName(name: string) {
this.logger.verbose(`Initializing instance '${name}'`); this.logger.verbose(`Initializing instance '${name}'`);
@ -343,12 +342,19 @@ export class WAStartupService {
public async sendDataWebhook<T = any>(event: Events, data: T, local = true) { public async sendDataWebhook<T = any>(event: Events, data: T, local = true) {
const webhookGlobal = this.configService.get<Webhook>('WEBHOOK'); const webhookGlobal = this.configService.get<Webhook>('WEBHOOK');
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
const webhookLocal = this.localWebhook.events; const webhookLocal = this.localWebhook.events;
const serverUrl = this.configService.get<HttpServer>('SERVER').URL;
const we = event.replace(/[\.-]/gm, '_').toUpperCase(); const we = event.replace(/[\.-]/gm, '_').toUpperCase();
const transformedWe = we.replace(/_/gm, '-').toLowerCase(); const transformedWe = we.replace(/_/gm, '-').toLowerCase();
const instance = this.configService.get<Auth>('AUTHENTICATION').INSTANCE; const instance = this.configService.get<Auth>('AUTHENTICATION').INSTANCE;
const expose =
this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES;
const tokenStore = await this.repository.auth.find(this.instanceName);
const instanceApikey = tokenStore.apikey || 'Apikey not found';
const globalApiKey = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
if (local && instance.MODE !== 'container') { if (local && instance.MODE !== 'container') {
if (Array.isArray(webhookLocal) && webhookLocal.includes(we)) { if (Array.isArray(webhookLocal) && webhookLocal.includes(we)) {
this.logger.verbose('Sending data to webhook local'); this.logger.verbose('Sending data to webhook local');
@ -361,27 +367,40 @@ export class WAStartupService {
} }
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
this.logger.log({ const logData = {
local: WAStartupService.name + '.sendDataWebhook-local', local: WAStartupService.name + '.sendDataWebhook-local',
url: baseURL, url: baseURL,
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
destination: this.localWebhook.url, destination: this.localWebhook.url,
urlServer, server_url: serverUrl,
}); apikey: (expose && instanceApikey) || null,
};
if (expose && instanceApikey) {
logData['apikey'] = instanceApikey;
}
this.logger.log(logData);
} }
try { try {
if (this.localWebhook.enabled && isURL(this.localWebhook.url)) { if (this.localWebhook.enabled && isURL(this.localWebhook.url)) {
const httpService = axios.create({ baseURL }); const httpService = axios.create({ baseURL });
await httpService.post('', { const postData = {
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
destination: this.localWebhook.url, destination: this.localWebhook.url,
urlServer, server_url: serverUrl,
}); };
if (expose && instanceApikey) {
postData['apikey'] = instanceApikey;
}
await httpService.post('', postData);
} }
} catch (error) { } catch (error) {
this.logger.error({ this.logger.error({
@ -394,6 +413,7 @@ export class WAStartupService {
stack: error?.stack, stack: error?.stack,
name: error?.name, name: error?.name,
url: baseURL, url: baseURL,
server_url: serverUrl,
}); });
} }
} }
@ -421,27 +441,39 @@ export class WAStartupService {
} }
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
this.logger.log({ const logData = {
local: WAStartupService.name + '.sendDataWebhook-global', local: WAStartupService.name + '.sendDataWebhook-global',
url: globalURL, url: globalURL,
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
destination: localUrl, destination: localUrl,
urlServer, server_url: serverUrl,
}); };
if (expose && globalApiKey) {
logData['apikey'] = globalApiKey;
}
this.logger.log(logData);
} }
try { try {
if (globalWebhook && globalWebhook?.ENABLED && isURL(globalURL)) { if (globalWebhook && globalWebhook?.ENABLED && isURL(globalURL)) {
const httpService = axios.create({ baseURL: globalURL }); const httpService = axios.create({ baseURL: globalURL });
await httpService.post('', { const postData = {
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
destination: localUrl, destination: localUrl,
urlServer, server_url: serverUrl,
}); };
if (expose && globalApiKey) {
postData['apikey'] = globalApiKey;
}
await httpService.post('', postData);
} }
} catch (error) { } catch (error) {
this.logger.error({ this.logger.error({
@ -454,6 +486,7 @@ export class WAStartupService {
stack: error?.stack, stack: error?.stack,
name: error?.name, name: error?.name,
url: globalURL, url: globalURL,
server_url: serverUrl,
}); });
} }
} }
@ -623,6 +656,17 @@ export class WAStartupService {
CONNECTED TO WHATSAPP CONNECTED TO WHATSAPP
`.replace(/^ +/gm, ' '), `.replace(/^ +/gm, ' '),
); );
if (this.localChatwoot.enabled) {
this.chatwootService.eventWhatsapp(
Events.CONNECTION_UPDATE,
{ instanceName: this.instance.name },
{
instance: this.instance.name,
status: 'open',
},
);
}
} }
} }
@ -741,6 +785,7 @@ export class WAStartupService {
version, version,
connectTimeoutMs: 60_000, connectTimeoutMs: 60_000,
qrTimeout: 40_000, qrTimeout: 40_000,
defaultQueryTimeoutMs: undefined,
emitOwnEvents: false, emitOwnEvents: false,
msgRetryCounterCache: this.msgRetryCounterCache, msgRetryCounterCache: this.msgRetryCounterCache,
getMessage: async (key) => getMessage: async (key) =>
@ -908,14 +953,6 @@ export class WAStartupService {
this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE'); this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE');
await this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw); await this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw);
if (this.localChatwoot.enabled) {
await this.chatwootService.eventWhatsapp(
Events.CONTACTS_UPDATE,
{ instanceName: this.instance.name },
contactsRaw,
);
}
this.logger.verbose('Updating contacts in database'); this.logger.verbose('Updating contacts in database');
await this.repository.contact.update( await this.repository.contact.update(
contactsRaw, contactsRaw,
@ -1126,11 +1163,7 @@ export class WAStartupService {
5: 'PLAYED', 5: 'PLAYED',
}; };
for await (const { key, update } of args) { for await (const { key, update } of args) {
if ( if (key.remoteJid !== 'status@broadcast' && !key?.remoteJid?.match(/(:\d+)/)) {
key.remoteJid !== 'status@broadcast' &&
!key?.remoteJid?.match(/(:\d+)/) &&
key.fromMe
) {
this.logger.verbose('Message update is valid'); this.logger.verbose('Message update is valid');
let pollUpdates: any; let pollUpdates: any;
@ -1150,6 +1183,16 @@ export class WAStartupService {
} }
} }
if (status[update.status] === 'READ' && !key.fromMe) return;
if (update.message === null && update.status === undefined) {
this.logger.verbose('Message deleted');
this.logger.verbose('Sending data to webhook in event MESSAGE_DELETE');
await this.sendDataWebhook(Events.MESSAGES_DELETE, key);
return;
}
const message: MessageUpdateRaw = { const message: MessageUpdateRaw = {
...key, ...key,
status: status[update.status], status: status[update.status],
@ -1294,16 +1337,12 @@ export class WAStartupService {
// Check if the number is MX or AR // Check if the number is MX or AR
private formatMXOrARNumber(jid: string): string { private formatMXOrARNumber(jid: string): string {
const regexp = new RegExp(/^(\d{2})(\d{2})\d{1}(\d{8})$/); const countryCode = jid.substring(0, 2);
if (regexp.test(jid)) {
const match = regexp.exec(jid); if (Number(countryCode) === 52 || Number(countryCode) === 54) {
if (match && (match[1] === '52' || match[1] === '54')) { if (jid.length === 13) {
const joker = Number.parseInt(match[3][0]); const number = countryCode + jid.substring(3);
const ddd = Number.parseInt(match[2]); return number;
if (joker < 7 || ddd < 11) {
return match[0];
}
return match[1] === '52' ? '52' + match[3] : '54' + match[3];
} }
return jid; return jid;
@ -1332,6 +1371,7 @@ export class WAStartupService {
private createJid(number: string): string { private createJid(number: string): string {
this.logger.verbose('Creating jid with number: ' + number); this.logger.verbose('Creating jid with number: ' + number);
if (number.includes('@g.us') || number.includes('@s.whatsapp.net')) { if (number.includes('@g.us') || number.includes('@s.whatsapp.net')) {
this.logger.verbose('Number already contains @g.us or @s.whatsapp.net'); this.logger.verbose('Number already contains @g.us or @s.whatsapp.net');
return number; return number;
@ -1342,22 +1382,31 @@ export class WAStartupService {
return number; return number;
} }
const formattedBRNumber = this.formatBRNumber(number); const countryCode = number.substring(0, 2);
if (formattedBRNumber !== number) {
this.logger.verbose( if (Number(countryCode) === 55) {
'Jid created is whatsapp in format BR: ' + `${formattedBRNumber}@s.whatsapp.net`, const formattedBRNumber = this.formatBRNumber(number);
); if (formattedBRNumber !== number) {
return `${formattedBRNumber}@s.whatsapp.net`; this.logger.verbose(
'Jid created is whatsapp in format BR: ' +
`${formattedBRNumber}@s.whatsapp.net`,
);
return `${formattedBRNumber}@s.whatsapp.net`;
}
} }
const formattedMXARNumber = this.formatMXOrARNumber(number); if (Number(countryCode) === 52 || Number(countryCode) === 54) {
console.log('numero mexicano');
if (formattedMXARNumber !== number) { const formattedMXARNumber = this.formatMXOrARNumber(number);
this.logger.verbose(
'Jid created is whatsapp in format MXAR: ' + if (formattedMXARNumber !== number) {
`${formattedMXARNumber}@s.whatsapp.net`, this.logger.verbose(
); 'Jid created is whatsapp in format MXAR: ' +
return `${formattedMXARNumber}@s.whatsapp.net`; `${formattedMXARNumber}@s.whatsapp.net`,
);
return `${formattedMXARNumber}@s.whatsapp.net`;
}
} }
if (number.includes('-')) { if (number.includes('-')) {
@ -1427,13 +1476,29 @@ export class WAStartupService {
let quoted: WAMessage; let quoted: WAMessage;
if (options?.quoted) { if (options?.quoted) {
quoted = options?.quoted; const m = options?.quoted;
const msg = m?.message
? m
: ((await this.getMessage(m.key, true)) as proto.IWebMessageInfo);
if (!msg) {
throw 'Message not found';
}
quoted = msg;
this.logger.verbose('Quoted message'); this.logger.verbose('Quoted message');
} }
let mentions: string[]; let mentions: string[];
if (isJidGroup(sender)) { if (isJidGroup(sender)) {
try { try {
const groupMetadata = await this.client.groupMetadata(sender);
if (!groupMetadata) {
throw new NotFoundException('Group not found');
}
if (options?.mentions) { if (options?.mentions) {
this.logger.verbose('Mentions defined'); this.logger.verbose('Mentions defined');
@ -1448,7 +1513,6 @@ export class WAStartupService {
this.logger.verbose('Mentions everyone'); this.logger.verbose('Mentions everyone');
this.logger.verbose('Getting group metadata'); this.logger.verbose('Getting group metadata');
const groupMetadata = await this.client.groupMetadata(sender);
mentions = groupMetadata.participants.map((participant) => participant.id); mentions = groupMetadata.participants.map((participant) => participant.id);
this.logger.verbose('Getting group metadata for mentions'); this.logger.verbose('Getting group metadata for mentions');
} else { } else {
@ -1475,9 +1539,9 @@ export class WAStartupService {
if ( if (
!message['audio'] && !message['audio'] &&
!message['poll'] && !message['poll'] &&
!message['linkPreview'] &&
!message['sticker'] && !message['sticker'] &&
!sender.includes('@broadcast') !message['conversation'] &&
sender !== 'status@broadcast'
) { ) {
if (!message['audio']) { if (!message['audio']) {
this.logger.verbose('Sending message'); this.logger.verbose('Sending message');
@ -1495,18 +1559,19 @@ export class WAStartupService {
} }
} }
if (message['linkPreview']) { if (message['conversation']) {
this.logger.verbose('Sending message'); this.logger.verbose('Sending message');
return await this.client.sendMessage( return await this.client.sendMessage(
sender, sender,
{ {
text: message['linkPreview'].text, text: message['conversation'],
mentions,
} as unknown as AnyMessageContent, } as unknown as AnyMessageContent,
option as unknown as MiscMessageGenerationOptions, option as unknown as MiscMessageGenerationOptions,
); );
} }
if (sender.includes('@broadcast')) { if (sender === 'status@broadcast') {
this.logger.verbose('Sending message'); this.logger.verbose('Sending message');
return await this.client.sendMessage( return await this.client.sendMessage(
sender, sender,
@ -1582,19 +1647,6 @@ export class WAStartupService {
); );
} }
public async linkPreview(data: SendLinkPreviewDto) {
this.logger.verbose('Sending link preview');
return await this.sendMessageWithTyping(
data.number,
{
linkPreview: {
text: data.linkPreview.text,
},
},
data?.options,
);
}
public async pollMessage(data: SendPollDto) { public async pollMessage(data: SendPollDto) {
this.logger.verbose('Sending poll message'); this.logger.verbose('Sending poll message');
return await this.sendMessageWithTyping( return await this.sendMessageWithTyping(
@ -1730,8 +1782,10 @@ export class WAStartupService {
public async statusMessage(data: SendStatusDto) { public async statusMessage(data: SendStatusDto) {
this.logger.verbose('Sending status message'); this.logger.verbose('Sending status message');
const status = await this.formatStatusMessage(data.statusMessage);
return await this.sendMessageWithTyping('status@broadcast', { return await this.sendMessageWithTyping('status@broadcast', {
status: await this.formatStatusMessage(data.statusMessage), status,
}); });
} }
@ -2110,6 +2164,7 @@ export class WAStartupService {
const onWhatsapp: OnWhatsAppDto[] = []; const onWhatsapp: OnWhatsAppDto[] = [];
for await (const number of data.numbers) { for await (const number of data.numbers) {
const jid = this.createJid(number); const jid = this.createJid(number);
// const jid = `${number}@s.whatsapp.net`;
if (isJidGroup(jid)) { if (isJidGroup(jid)) {
const group = await this.findGroup({ groupJid: jid }, 'inner'); const group = await this.findGroup({ groupJid: jid }, 'inner');
@ -2645,9 +2700,7 @@ export class WAStartupService {
const msg = `${description}\n\n${inviteUrl}`; const msg = `${description}\n\n${inviteUrl}`;
const message = { const message = {
linkPreview: { conversation: msg,
text: msg,
},
}; };
for await (const number of numbers) { for await (const number of numbers) {

View File

@ -9,6 +9,7 @@ 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', SEND_MESSAGE = 'send.message',
CONTACTS_SET = 'contacts.set', CONTACTS_SET = 'contacts.set',
CONTACTS_UPSERT = 'contacts.upsert', CONTACTS_UPSERT = 'contacts.upsert',

View File

@ -72,7 +72,7 @@ const webhookService = new WebhookService(waMonitor);
export const webhookController = new WebhookController(webhookService); export const webhookController = new WebhookController(webhookService);
const chatwootService = new ChatwootService(waMonitor); const chatwootService = new ChatwootService(waMonitor, configService);
export const chatwootController = new ChatwootController(chatwootService, configService); export const chatwootController = new ChatwootController(chatwootService, configService);

View File

@ -6,6 +6,7 @@ then
echo "DOCKER_ENV=$DOCKER_ENV" echo "DOCKER_ENV=$DOCKER_ENV"
echo echo
else else
mkdir -p ./dist/src
cp ./src/env.yml ./dist/src cp ./src/env.yml ./dist/src
fi fi
echo "> removing dist" echo "> removing dist"