Skip to content

Commit

Permalink
Merge branch 'release/1.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Apr 12, 2024
2 parents 5975117 + 96ae976 commit 8caf3a0
Show file tree
Hide file tree
Showing 134 changed files with 1,061 additions and 603 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# 1.7.2 (2024-04-12 17:31)

### Feature

* Mobile connection via sms (test)

### Fixed

* Adjusts in redis
* Send global event in websocket
* Adjusts in proxy
* Fix audio encoding
* Fix conversation read on chatwoot version 3.7
* Fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled
* Changed returned sessions on typebot status change
* Reorganization of files and folders

# 1.7.1 (2024-04-03 10:19)

### Fixed
Expand Down
1 change: 1 addition & 0 deletions Docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ RABBITMQ_EXCHANGE_NAME=evolution_exchange
RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672

WEBSOCKET_ENABLED=false
WEBSOCKET_GLOBAL_EVENTS=false

WA_BUSINESS_TOKEN_WEBHOOK=evolution
WA_BUSINESS_URL=https://graph.facebook.com
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:20.7.0-alpine AS builder

LABEL version="1.7.1" description="Api to control whatsapp features through http requests."
LABEL version="1.7.2" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
LABEL contact="[email protected]"

Expand Down Expand Up @@ -68,6 +68,7 @@ ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672

ENV WEBSOCKET_ENABLED=false
ENV WEBSOCKET_GLOBAL_EVENTS=false

ENV WA_BUSINESS_TOKEN_WEBHOOK=evolution
ENV WA_BUSINESS_URL=https://graph.facebook.com
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evolution-api",
"version": "1.7.1",
"version": "1.7.2",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js",
"scripts": {
Expand Down Expand Up @@ -46,7 +46,7 @@
"@figuro/chatwoot-sdk": "^1.1.16",
"@hapi/boom": "^10.0.1",
"@sentry/node": "^7.59.2",
"@whiskeysockets/baileys": "6.6.0",
"@whiskeysockets/baileys": "github:AtendAI/Baileys",
"amqplib": "^0.10.3",
"aws-sdk": "^2.1499.0",
"axios": "^1.6.5",
Expand All @@ -60,6 +60,7 @@
"exiftool-vendored": "^22.0.0",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"fluent-ffmpeg": "^2.1.2",
"form-data": "^4.0.0",
"hbs": "^4.2.0",
"https-proxy-agent": "^7.0.2",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import { Logger } from '../../config/logger.config';
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
import { RedisCache } from '../../libs/redis.client';
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service';
import { SqsService } from '../integrations/sqs/services/sqs.service';
import { TypebotService } from '../integrations/typebot/services/typebot.service';
import { WebsocketService } from '../integrations/websocket/services/websocket.service';
import { RepositoryBroker } from '../repository/repository.manager';
import { AuthService, OldToken } from '../services/auth.service';
import { CacheService } from '../services/cache.service';
import { ChatwootService } from '../services/chatwoot.service';
import { IntegrationService } from '../services/integration.service';
import { WAMonitoringService } from '../services/monitor.service';
import { RabbitmqService } from '../services/rabbitmq.service';
import { SettingsService } from '../services/settings.service';
import { SqsService } from '../services/sqs.service';
import { TypebotService } from '../services/typebot.service';
import { WebhookService } from '../services/webhook.service';
import { WebsocketService } from '../services/websocket.service';
import { BaileysStartupService } from '../services/whatsapp.baileys.service';
import { BusinessStartupService } from '../services/whatsapp.business.service';
import { BaileysStartupService } from '../services/whatsapp/whatsapp.baileys.service';
import { BusinessStartupService } from '../services/whatsapp/whatsapp.business.service';
import { Events, Integration, wa } from '../types/wa.types';
import { ProxyController } from './proxy.controller';

export class InstanceController {
constructor(
Expand All @@ -39,6 +40,7 @@ export class InstanceController {
private readonly sqsService: SqsService,
private readonly typebotService: TypebotService,
private readonly integrationService: IntegrationService,
private readonly proxyService: ProxyController,
private readonly cache: RedisCache,
private readonly chatwootCache: CacheService,
) {}
Expand All @@ -53,6 +55,7 @@ export class InstanceController {
events,
qrcode,
number,
mobile,
integration,
token,
chatwoot_account_id,
Expand Down Expand Up @@ -84,6 +87,7 @@ export class InstanceController {
typebot_delay_message,
typebot_unknown_message,
typebot_listening_from_me,
proxy,
}: InstanceDto) {
try {
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
Expand Down Expand Up @@ -115,7 +119,7 @@ export class InstanceController {
);
}

await this.waMonitor.saveInstance({ integration, instanceName, token, number });
await this.waMonitor.saveInstance({ integration, instanceName, token, number, mobile });

instance.instanceName = instanceName;

Expand Down Expand Up @@ -345,6 +349,18 @@ export class InstanceController {
}
}

if (proxy) {
const testProxy = await this.proxyService.testProxy(proxy);
if (!testProxy) {
throw new BadRequestException('Invalid proxy');
}

await this.proxyService.createProxy(instance, {
enabled: true,
proxy,
});
}

if (typebot_url) {
try {
if (!isURL(typebot_url, { require_tld: false })) {
Expand Down Expand Up @@ -405,7 +421,7 @@ export class InstanceController {

if (qrcode) {
this.logger.verbose('creating qrcode');
await instance.connectToWhatsapp(number);
await instance.connectToWhatsapp(number, mobile);
await delay(5000);
getQrcode = instance.qrCode;
}
Expand Down Expand Up @@ -569,7 +585,7 @@ export class InstanceController {
}
}

public async connectToWhatsapp({ instanceName, number = null }: InstanceDto) {
public async connectToWhatsapp({ instanceName, number = null, mobile = null }: InstanceDto) {
try {
this.logger.verbose('requested connectToWhatsapp from ' + instanceName + ' instance');

Expand All @@ -592,7 +608,7 @@ export class InstanceController {

if (state == 'close') {
this.logger.verbose('connecting');
await instance.connectToWhatsapp(number);
await instance.connectToWhatsapp(number, mobile);

await delay(5000);
return instance.qrCode;
Expand Down Expand Up @@ -633,6 +649,20 @@ export class InstanceController {
}
}

public async registerMobileCode({ instanceName }: InstanceDto, { mobileCode }: any) {
try {
this.logger.verbose('requested registerMobileCode from ' + instanceName + ' instance');

const instance = this.waMonitor.waInstances[instanceName];

console.log('mobileCode', mobileCode);
await instance.receiveMobileCode(mobileCode);
return { status: 'SUCCESS', error: false, response: { message: 'Mobile code registered' } };
} catch (error) {
this.logger.error(error);
}
}

public async connectionState({ instanceName }: InstanceDto) {
this.logger.verbose('requested connectionState from ' + instanceName + ' instance');
return {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ProxyController {
return this.proxyService.find(instance);
}

private async testProxy(proxy: ProxyDto['proxy']) {
public async testProxy(proxy: ProxyDto['proxy']) {
logger.verbose('requested testProxy');
try {
const serverIp = await axios.get('https://icanhazip.com/');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { WAPresence } from "@whiskeysockets/baileys";
import { WAPresence } from '@whiskeysockets/baileys';

import { ProxyDto } from './proxy.dto';

export class InstanceDto {
instanceName: string;
instanceId?: string;
qrcode?: boolean;
number?: string;
mobile?: boolean;
integration?: string;
token?: string;
webhook?: string;
Expand Down Expand Up @@ -40,7 +43,7 @@ export class InstanceDto {
typebot_delay_message?: number;
typebot_unknown_message?: string;
typebot_listening_from_me?: boolean;
proxy?: string;
proxy?: ProxyDto['proxy'];
}

export class SetPresenceDto {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Auth, configService } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { ForbiddenException, UnauthorizedException } from '../../exceptions';
import { InstanceDto } from '../dto/instance.dto';
import { repository } from '../server.module';
import { JwtPayload } from '../services/auth.service';
import { repository } from '../whatsapp.module';

const logger = new Logger('GUARD');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../exceptions';
import { dbserver } from '../../libs/db.connect';
import { InstanceDto } from '../dto/instance.dto';
import { cache, waMonitor } from '../whatsapp.module';
import { cache, waMonitor } from '../server.module';

async function getInstance(instanceName: string) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '../../config/logger.config';
import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { ChamaaiService } from '../services/chamaai.service';

const logger = new Logger('ChamaaiController');
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema } from 'mongoose';

import { dbserver } from '../../libs/db.connect';
import { dbserver } from '../../../../libs/db.connect';

export class ChamaaiRaw {
_id?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFileSync } from 'fs';
import { join } from 'path';

import { ConfigService } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository';
import { ChamaaiRaw, IChamaaiModel } from '../models';
import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { ChamaaiRaw, IChamaaiModel } from '../../../models';

export class ChamaaiRepository extends Repository {
constructor(private readonly chamaaiModel: IChamaaiModel, private readonly configService: ConfigService) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RequestHandler, Router } from 'express';

import { Logger } from '../../config/logger.config';
import { chamaaiSchema, instanceNameSchema } from '../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router';
import { Logger } from '../../../../config/logger.config';
import { chamaaiSchema, instanceNameSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { chamaaiController } from '../../../server.module';
import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { chamaaiController } from '../whatsapp.module';
import { HttpStatus } from './index.router';

const logger = new Logger('ChamaaiRouter');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import axios from 'axios';
import { writeFileSync } from 'fs';
import path from 'path';

import { ConfigService, HttpServer } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { ConfigService, HttpServer } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { ChamaaiRaw } from '../../../models';
import { WAMonitoringService } from '../../../services/monitor.service';
import { Events } from '../../../types/wa.types';
import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { ChamaaiRaw } from '../models';
import { Events } from '../types/wa.types';
import { WAMonitoringService } from './monitor.service';

export class ChamaaiService {
constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {}
Expand Down
35 changes: 35 additions & 0 deletions src/api/integrations/chamaai/validate/chamaai.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';

const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};

export const chamaaiSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
url: { type: 'string' },
token: { type: 'string' },
waNumber: { type: 'string' },
answerByAudio: { type: 'boolean', enum: [true, false] },
},
required: ['enabled', 'url', 'token', 'waNumber', 'answerByAudio'],
...isNotEmpty('enabled', 'url', 'token', 'waNumber', 'answerByAudio'),
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CacheConf, ConfigService } from '../config/env.config';
import { ICache } from '../whatsapp/abstract/abstract.cache';
import { CacheConf, ConfigService } from '../../../../config/env.config';
import { ICache } from '../../../abstract/abstract.cache';
import { LocalCache } from './localcache';
import { RedisCache } from './rediscache';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import NodeCache from 'node-cache';

import { CacheConf, CacheConfLocal, ConfigService } from '../config/env.config';
import { ICache } from '../whatsapp/abstract/abstract.cache';
import { CacheConf, CacheConfLocal, ConfigService } from '../../../../config/env.config';
import { ICache } from '../../../abstract/abstract.cache';

export class LocalCache implements ICache {
private conf: CacheConfLocal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClient, RedisClientType } from 'redis';

import { CacheConf, CacheConfRedis, configService } from '../config/env.config';
import { Logger } from '../config/logger.config';
import { CacheConf, CacheConfRedis, configService } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';

class Redis {
private logger = new Logger(Redis.name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RedisClientType } from 'redis';

import { CacheConf, CacheConfRedis, ConfigService } from '../config/env.config';
import { Logger } from '../config/logger.config';
import { ICache } from '../whatsapp/abstract/abstract.cache';
import { CacheConf, CacheConfRedis, ConfigService } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { ICache } from '../../../abstract/abstract.cache';
import { redisClient } from './rediscache.client';

export class RedisCache implements ICache {
Expand Down
Loading

0 comments on commit 8caf3a0

Please sign in to comment.