Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ body:
value: |
- OS: [e.g. Ubuntu 20.04, Windows 10, macOS 12.0]
- Node.js version: [e.g. 18.17.0]
- Evolution API version: [e.g. 2.3.6]
- Evolution API version: [e.g. 2.3.7]
- Database: [e.g. PostgreSQL 14, MySQL 8.0]
- Connection type: [e.g. Baileys, WhatsApp Business API]
validations:
Expand Down
2 changes: 1 addition & 1 deletion Docker/swarm/evolution_api_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"

services:
evolution_v2:
image: evoapicloud/evolution-api:v2.3.6
image: evoapicloud/evolution-api:v2.3.7
volumes:
- evolution_instances:/evolution/instances
networks:
Expand Down
913 changes: 457 additions & 456 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evolution-api",
"version": "2.3.6",
"version": "2.3.7",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/main.js",
"type": "commonjs",
Expand Down Expand Up @@ -96,6 +96,7 @@
"jsonschema": "^1.4.1",
"jsonwebtoken": "^9.0.2",
"kafkajs": "^2.2.4",
"libphonenumber-js": "^1.12.25",
"link-preview-js": "^3.0.13",
"long": "^5.2.3",
"mediainfo.js": "^0.3.4",
Expand Down
60 changes: 46 additions & 14 deletions src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ export class InstanceController {
instanceId: instanceId,
});

const instanceDto: InstanceDto = {
instanceName: instance.instanceName,
instanceId: instance.instanceId,
connectionStatus:
typeof instance.connectionStatus === 'string'
? instance.connectionStatus
: instance.connectionStatus?.state || 'unknown',
};

if (instanceData.proxyHost && instanceData.proxyPort && instanceData.proxyProtocol) {
const testProxy = await this.proxyService.testProxy({
host: instanceData.proxyHost,
Expand All @@ -103,8 +112,7 @@ export class InstanceController {
if (!testProxy) {
throw new BadRequestException('Invalid proxy');
}

await this.proxyService.createProxy(instance, {
await this.proxyService.createProxy(instanceDto, {
enabled: true,
host: instanceData.proxyHost,
port: instanceData.proxyPort,
Expand All @@ -125,7 +133,7 @@ export class InstanceController {
wavoipToken: instanceData.wavoipToken || '',
};

await this.settingsService.create(instance, settings);
await this.settingsService.create(instanceDto, settings);

let webhookWaBusiness = null,
accessTokenWaBusiness = '';
Expand Down Expand Up @@ -155,7 +163,10 @@ export class InstanceController {
integration: instanceData.integration,
webhookWaBusiness,
accessTokenWaBusiness,
status: instance.connectionStatus.state,
status:
typeof instance.connectionStatus === 'string'
? instance.connectionStatus
: instance.connectionStatus?.state || 'unknown',
},
hash,
webhook: {
Expand Down Expand Up @@ -217,7 +228,7 @@ export class InstanceController {
const urlServer = this.configService.get<HttpServer>('SERVER').URL;

try {
this.chatwootService.create(instance, {
this.chatwootService.create(instanceDto, {
enabled: true,
accountId: instanceData.chatwootAccountId,
token: instanceData.chatwootToken,
Expand Down Expand Up @@ -246,7 +257,10 @@ export class InstanceController {
integration: instanceData.integration,
webhookWaBusiness,
accessTokenWaBusiness,
status: instance.connectionStatus.state,
status:
typeof instance.connectionStatus === 'string'
? instance.connectionStatus
: instance.connectionStatus?.state || 'unknown',
},
hash,
webhook: {
Expand Down Expand Up @@ -338,20 +352,38 @@ export class InstanceController {
throw new BadRequestException('The "' + instanceName + '" instance does not exist');
}

if (state == 'close') {
if (state === 'close') {
throw new BadRequestException('The "' + instanceName + '" instance is not connected');
} else if (state == 'open') {
}
this.logger.info(`Restarting instance: ${instanceName}`);

if (typeof instance.restart === 'function') {
await instance.restart();
// Wait a bit for the reconnection to be established
await new Promise((r) => setTimeout(r, 2000));
return {
instance: {
instanceName: instanceName,
status: instance.connectionStatus?.state || 'connecting',
},
};
}

// Fallback for Baileys (uses different mechanism)
if (state === 'open' || state === 'connecting') {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) instance.clearCacheChatwoot();
this.logger.info('restarting instance' + instanceName);

instance.client?.ws?.close();
instance.client?.end(new Error('restart'));
return await this.connectToWhatsapp({ instanceName });
} else if (state == 'connecting') {
instance.client?.ws?.close();
instance.client?.end(new Error('restart'));
return await this.connectToWhatsapp({ instanceName });
}

return {
instance: {
instanceName: instanceName,
status: state,
},
};
} catch (error) {
this.logger.error(error);
return { error: true, message: error.toString() };
Expand Down Expand Up @@ -409,7 +441,7 @@ export class InstanceController {
}

try {
this.waMonitor.waInstances[instanceName]?.logoutInstance();
await this.waMonitor.waInstances[instanceName]?.logoutInstance();

return { status: 'SUCCESS', error: false, response: { message: 'Instance logged out' } };
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions src/api/dto/instance.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class InstanceDto extends IntegrationDto {
token?: string;
status?: string;
ownerJid?: string;
connectionStatus?: string;
profileName?: string;
profilePicUrl?: string;
// settings
Expand Down
23 changes: 2 additions & 21 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import { createId as cuid } from '@paralleldrive/cuid2';
import { Instance, Message } from '@prisma/client';
import { createJid } from '@utils/createJid';
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
import {makeProxyAgent, makeProxyAgentUndici} from '@utils/makeProxyAgent';
import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent';
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
import { status } from '@utils/renderStatus';
import { sendTelemetry } from '@utils/sendTelemetry';
Expand Down Expand Up @@ -569,15 +569,6 @@ export class BaileysStartupService extends ChannelStartupService {
const version = baileysVersion.version;
const log = `Baileys version: ${version.join('.')}`;

// if (session.VERSION) {
// version = session.VERSION.split('.');
// log = `Baileys version env: ${version}`;
// } else {
// const baileysVersion = await fetchLatestWaWebVersion({});
// version = baileysVersion.version;
// log = `Baileys version: ${version}`;
// }

this.logger.info(log);

this.logger.info(`Group Ignore: ${this.localSettings.groupsIgnore}`);
Expand Down Expand Up @@ -1130,16 +1121,6 @@ export class BaileysStartupService extends ChannelStartupService {
}
}

const messageKey = `${this.instance.id}_${received.key.id}`;
const cached = await this.baileysCache.get(messageKey);

if (cached && !editedMessage && !requestId) {
this.logger.info(`Message duplicated ignored: ${received.key.id}`);
continue;
}

await this.baileysCache.set(messageKey, true, this.MESSAGE_CACHE_TTL_SECONDS);

if (
(type !== 'notify' && type !== 'append') ||
editedMessage ||
Expand Down Expand Up @@ -1442,7 +1423,7 @@ export class BaileysStartupService extends ChannelStartupService {
const cached = await this.baileysCache.get(updateKey);

if (cached) {
this.logger.info(`Message duplicated ignored [avoid deadlock]: ${updateKey}`);
this.logger.info(`Update Message duplicated ignored [avoid deadlock]: ${updateKey}`);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { InstanceDto } from '@api/dto/instance.dto';
import { ChatwootDto } from '@api/integrations/chatbot/chatwoot/dto/chatwoot.dto';
import { ChatwootService } from '@api/integrations/chatbot/chatwoot/services/chatwoot.service';
import { PrismaRepository } from '@api/repository/repository.service';
import { waMonitor } from '@api/server.module';
import { CacheService } from '@api/services/cache.service';
import { CacheEngine } from '@cache/cacheengine';
import { Chatwoot, ConfigService, HttpServer } from '@config/env.config';
import { BadRequestException } from '@exceptions';
import { isURL } from 'class-validator';
Expand All @@ -13,7 +9,6 @@ export class ChatwootController {
constructor(
private readonly chatwootService: ChatwootService,
private readonly configService: ConfigService,
private readonly prismaRepository: PrismaRepository,
) {}

public async createChatwoot(instance: InstanceDto, data: ChatwootDto) {
Expand Down Expand Up @@ -84,9 +79,6 @@ export class ChatwootController {
public async receiveWebhook(instance: InstanceDto, data: any) {
if (!this.configService.get<Chatwoot>('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is disabled');

const chatwootCache = new CacheService(new CacheEngine(this.configService, ChatwootService.name).getEngine());
const chatwootService = new ChatwootService(waMonitor, this.configService, this.prismaRepository, chatwootCache);

return chatwootService.receiveWebhook(instance, data);
return this.chatwootService.receiveWebhook(instance, data);
}
}
Loading
Loading