Merge branch 'release/1.7.4'

This commit is contained in:
Davidson Gomes 2024-04-28 09:47:19 -03:00
commit 824642d42d
25 changed files with 127 additions and 212 deletions

View File

@ -1,9 +1,12 @@
# 1.7.4 (develop) # 1.7.4 (2024-04-28 09:46)
### Fixed ### Fixed
* Adjusts in proxy on fetchAgent * Adjusts in proxy on fetchAgent
* Recovering messages lost with redis cache * Recovering messages lost with redis cache
* Log when init redis cache service * Log when init redis cache service
* Recovering messages lost with redis cache
* Chatwoot inbox name
* Update Baileys version
# 1.7.3 (2024-04-18 12:07) # 1.7.3 (2024-04-18 12:07)

View File

@ -1,6 +1,6 @@
FROM node:20.7.0-alpine AS builder FROM node:20.7.0-alpine AS builder
LABEL version="1.7.3" description="Api to control whatsapp features through http requests." LABEL version="1.7.4" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
LABEL contact="contato@agenciadgcode.com" LABEL contact="contato@agenciadgcode.com"

View File

@ -1,6 +1,6 @@
{ {
"name": "evolution-api", "name": "evolution-api",
"version": "1.7.3", "version": "1.7.4",
"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": {
@ -46,10 +46,10 @@
"@figuro/chatwoot-sdk": "^1.1.16", "@figuro/chatwoot-sdk": "^1.1.16",
"@hapi/boom": "^10.0.1", "@hapi/boom": "^10.0.1",
"@sentry/node": "^7.59.2", "@sentry/node": "^7.59.2",
"@whiskeysockets/baileys": "github:AtendAI/Baileys",
"amqplib": "^0.10.3", "amqplib": "^0.10.3",
"aws-sdk": "^2.1499.0", "aws-sdk": "^2.1499.0",
"axios": "^1.6.5", "axios": "^1.6.5",
"baileys": "^6.7.0",
"class-validator": "^0.14.1", "class-validator": "^0.14.1",
"compression": "^1.7.4", "compression": "^1.7.4",
"cors": "^2.8.5", "cors": "^2.8.5",

View File

@ -1,4 +1,4 @@
import { delay } from '@whiskeysockets/baileys'; import { delay } from 'baileys';
import { isURL } from 'class-validator'; import { isURL } from 'class-validator';
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from 'eventemitter2';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
@ -15,12 +15,12 @@ import { WebsocketService } from '../integrations/websocket/services/websocket.s
import { RepositoryBroker } from '../repository/repository.manager'; import { RepositoryBroker } from '../repository/repository.manager';
import { AuthService, OldToken } from '../services/auth.service'; import { AuthService, OldToken } from '../services/auth.service';
import { CacheService } from '../services/cache.service'; import { CacheService } from '../services/cache.service';
import { BaileysStartupService } from '../services/channels/whatsapp.baileys.service';
import { BusinessStartupService } from '../services/channels/whatsapp.business.service';
import { IntegrationService } from '../services/integration.service'; import { IntegrationService } from '../services/integration.service';
import { WAMonitoringService } from '../services/monitor.service'; import { WAMonitoringService } from '../services/monitor.service';
import { SettingsService } from '../services/settings.service'; import { SettingsService } from '../services/settings.service';
import { WebhookService } from '../services/webhook.service'; import { WebhookService } from '../services/webhook.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 { Events, Integration, wa } from '../types/wa.types';
import { ProxyController } from './proxy.controller'; import { ProxyController } from './proxy.controller';
@ -65,6 +65,7 @@ export class InstanceController {
chatwoot_reopen_conversation, chatwoot_reopen_conversation,
chatwoot_conversation_pending, chatwoot_conversation_pending,
chatwoot_import_contacts, chatwoot_import_contacts,
chatwoot_name_inbox,
chatwoot_import_messages, chatwoot_import_messages,
chatwoot_days_limit_import_messages, chatwoot_days_limit_import_messages,
reject_call, reject_call,
@ -513,7 +514,7 @@ export class InstanceController {
token: chatwoot_token, token: chatwoot_token,
url: chatwoot_url, url: chatwoot_url,
sign_msg: chatwoot_sign_msg || false, sign_msg: chatwoot_sign_msg || false,
name_inbox: instance.instanceName.split('-cwId-')[0], name_inbox: chatwoot_name_inbox ?? instance.instanceName.split('-cwId-')[0],
number, number,
reopen_conversation: chatwoot_reopen_conversation || false, reopen_conversation: chatwoot_reopen_conversation || false,
conversation_pending: chatwoot_conversation_pending || false, conversation_pending: chatwoot_conversation_pending || false,
@ -577,7 +578,7 @@ export class InstanceController {
import_messages: chatwoot_import_messages ?? true, import_messages: chatwoot_import_messages ?? true,
days_limit_import_messages: chatwoot_days_limit_import_messages || 60, days_limit_import_messages: chatwoot_days_limit_import_messages || 60,
number, number,
name_inbox: instance.instanceName, name_inbox: chatwoot_name_inbox ?? instance.instanceName,
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
}, },
}; };

View File

@ -1,4 +1,4 @@
import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '@whiskeysockets/baileys'; import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from 'baileys';
export class OnWhatsAppDto { export class OnWhatsAppDto {
constructor( constructor(

View File

@ -1,4 +1,4 @@
import { WAPresence } from '@whiskeysockets/baileys'; import { WAPresence } from 'baileys';
import { ProxyDto } from './proxy.dto'; import { ProxyDto } from './proxy.dto';
@ -30,6 +30,7 @@ export class InstanceDto {
chatwoot_import_contacts?: boolean; chatwoot_import_contacts?: boolean;
chatwoot_import_messages?: boolean; chatwoot_import_messages?: boolean;
chatwoot_days_limit_import_messages?: number; chatwoot_days_limit_import_messages?: number;
chatwoot_name_inbox?: string;
websocket_enabled?: boolean; websocket_enabled?: boolean;
websocket_events?: string[]; websocket_events?: string[];
rabbitmq_enabled?: boolean; rabbitmq_enabled?: boolean;

View File

@ -1,4 +1,4 @@
import { proto, WAPresence } from '@whiskeysockets/baileys'; import { proto, WAPresence } from 'baileys';
export class Quoted { export class Quoted {
key: proto.IMessageKey; key: proto.IMessageKey;

View File

@ -55,9 +55,12 @@ export class ChatwootController {
data.import_messages = false; data.import_messages = false;
data.days_limit_import_messages = 0; data.days_limit_import_messages = 0;
data.auto_create = false; data.auto_create = false;
data.name_inbox = '';
} }
data.name_inbox = instance.instanceName; if (!data.name_inbox || data.name_inbox === '') {
data.name_inbox = instance.instanceName;
}
const result = await this.chatwootService.create(instance, data); const result = await this.chatwootService.create(instance, data);

View File

@ -9,6 +9,7 @@ import ChatwootClient, {
} from '@figuro/chatwoot-sdk'; } from '@figuro/chatwoot-sdk';
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request'; import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
import axios from 'axios'; import axios from 'axios';
import { proto } from 'baileys';
import FormData from 'form-data'; import FormData from 'form-data';
import { createReadStream, unlinkSync, writeFileSync } from 'fs'; import { createReadStream, unlinkSync, writeFileSync } from 'fs';
import Jimp from 'jimp'; import Jimp from 'jimp';
@ -85,12 +86,13 @@ export class ChatwootService {
return client; return client;
} }
public getClientCwConfig(): ChatwootAPIConfig { public getClientCwConfig(): ChatwootAPIConfig & { name_inbox: string } {
return { return {
basePath: this.provider.url, basePath: this.provider.url,
with_credentials: true, with_credentials: true,
credentials: 'include', credentials: 'include',
token: this.provider.token, token: this.provider.token,
name_inbox: this.provider.name_inbox,
}; };
} }
@ -110,7 +112,7 @@ export class ChatwootService {
await this.initInstanceChatwoot( await this.initInstanceChatwoot(
instance, instance,
instance.instanceName.split('-cwId-')[0], data.name_inbox ?? instance.instanceName.split('-cwId-')[0],
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
true, true,
data.number, data.number,
@ -628,7 +630,7 @@ export class ChatwootService {
id: contactId, id: contactId,
})) as any; })) as any;
if (contactConversations) { if (contactConversations?.payload?.length) {
let conversation: any; let conversation: any;
if (this.provider.reopen_conversation) { if (this.provider.reopen_conversation) {
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id); conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
@ -710,7 +712,7 @@ export class ChatwootService {
} }
this.logger.verbose('find inbox by name'); this.logger.verbose('find inbox by name');
const findByName = inbox.payload.find((inbox) => inbox.name === instance.instanceName.split('-cwId-')[0]); const findByName = inbox.payload.find((inbox) => inbox.name === this.getClientCwConfig().name_inbox);
if (!findByName) { if (!findByName) {
this.logger.warn('inbox not found'); this.logger.warn('inbox not found');
@ -1106,6 +1108,26 @@ export class ChatwootService {
} }
} }
public async onSendMessageError(instance: InstanceDto, conversation: number, error?: string) {
const client = await this.clientCw(instance);
if (!client) {
return;
}
client.messages.create({
accountId: this.provider.account_id,
conversationId: conversation,
data: {
content: i18next.t('cw.message.notsent', {
error: error?.length > 0 ? `_${error}_` : '',
}),
message_type: 'outgoing',
private: true,
},
});
}
public async receiveWebhook(instance: InstanceDto, body: any) { public async receiveWebhook(instance: InstanceDto, body: any) {
try { try {
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
@ -1274,6 +1296,11 @@ export class ChatwootService {
return { message: 'bot' }; return { message: 'bot' };
} }
if (!waInstance && body.conversation?.id) {
this.onSendMessageError(instance, body.conversation?.id, 'Instance not found');
return { message: 'bot' };
}
this.logger.verbose('Format message to send'); this.logger.verbose('Format message to send');
let formatText: string; let formatText: string;
if (senderName === null || senderName === undefined) { if (senderName === null || senderName === undefined) {
@ -1310,6 +1337,9 @@ export class ChatwootService {
formatText, formatText,
options, options,
); );
if (!messageSent && body.conversation?.id) {
this.onSendMessageError(instance, body.conversation?.id);
}
this.updateChatwootMessageId( this.updateChatwootMessageId(
{ {
@ -1343,23 +1373,34 @@ export class ChatwootService {
}, },
}; };
const messageSent = await waInstance?.textMessage(data, true); let messageSent: MessageRaw | proto.WebMessageInfo;
try {
messageSent = await waInstance?.textMessage(data, true);
if (!messageSent) {
throw new Error('Message not sent');
}
this.updateChatwootMessageId( this.updateChatwootMessageId(
{ {
...messageSent, ...messageSent,
owner: instance.instanceName, owner: instance.instanceName,
},
{
messageId: body.id,
inboxId: body.inbox?.id,
conversationId: body.conversation?.id,
contactInbox: {
sourceId: body.conversation?.contact_inbox?.source_id,
}, },
}, {
instance, messageId: body.id,
); inboxId: body.inbox?.id,
conversationId: body.conversation?.id,
contactInbox: {
sourceId: body.conversation?.contact_inbox?.source_id,
},
},
instance,
);
} catch (error) {
if (!messageSent && body.conversation?.id) {
this.onSendMessageError(instance, body.conversation?.id, error.toString());
}
throw error;
}
} }
} }

View File

@ -1,5 +1,5 @@
import { inbox } from '@figuro/chatwoot-sdk'; import { inbox } from '@figuro/chatwoot-sdk';
import { proto } from '@whiskeysockets/baileys'; import { proto } from 'baileys';
import { InstanceDto } from '../../../../api/dto/instance.dto'; import { InstanceDto } from '../../../../api/dto/instance.dto';
import { ChatwootRaw, ContactRaw, MessageRaw } from '../../../../api/models'; import { ChatwootRaw, ContactRaw, MessageRaw } from '../../../../api/models';

View File

@ -30,6 +30,7 @@ export const chatwootSchema: JSONSchema7 = {
url: { type: 'string' }, url: { type: 'string' },
sign_msg: { type: 'boolean', enum: [true, false] }, sign_msg: { type: 'boolean', enum: [true, false] },
sign_delimiter: { type: ['string', 'null'] }, sign_delimiter: { type: ['string', 'null'] },
name_inbox: { type: ['string', 'null'] },
reopen_conversation: { type: 'boolean', enum: [true, false] }, reopen_conversation: { type: 'boolean', enum: [true, false] },
conversation_pending: { type: 'boolean', enum: [true, false] }, conversation_pending: { type: 'boolean', enum: [true, false] },
auto_create: { type: 'boolean', enum: [true, false] }, auto_create: { type: 'boolean', enum: [true, false] },

View File

@ -1,4 +1,4 @@
import { BufferJSON } from '@whiskeysockets/baileys'; import { BufferJSON } from 'baileys';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../config/logger.config';
import { ICache } from '../abstract/abstract.cache'; import { ICache } from '../abstract/abstract.cache';

View File

@ -1,5 +1,5 @@
import { WASocket } from '@whiskeysockets/baileys';
import axios from 'axios'; import axios from 'axios';
import { WASocket } from 'baileys';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { isURL } from 'class-validator'; import { isURL } from 'class-validator';
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from 'eventemitter2';
@ -38,17 +38,17 @@ import { waMonitor } from '../server.module';
import { Events, wa } from '../types/wa.types'; import { Events, wa } from '../types/wa.types';
import { CacheService } from './cache.service'; import { CacheService } from './cache.service';
export class WAStartupService { export class ChannelStartupService {
constructor( constructor(
public readonly configService: ConfigService, public readonly configService: ConfigService,
public readonly eventEmitter: EventEmitter2, public readonly eventEmitter: EventEmitter2,
public readonly repository: RepositoryBroker, public readonly repository: RepositoryBroker,
public readonly chatwootCache: CacheService, public readonly chatwootCache: CacheService,
) { ) {
this.logger.verbose('WAStartupService initialized'); this.logger.verbose('ChannelStartupService initialized');
} }
public readonly logger = new Logger(WAStartupService.name); public readonly logger = new Logger(ChannelStartupService.name);
public client: WASocket; public client: WASocket;
public readonly instance: wa.Instance = {}; public readonly instance: wa.Instance = {};
@ -136,11 +136,13 @@ export class WAStartupService {
public async findIntegration() { public async findIntegration() {
this.logger.verbose('Finding integration'); this.logger.verbose('Finding integration');
const data = await this.repository.integration.find(this.instanceName); let data: any;
data = await this.repository.integration.find(this.instanceName);
if (!data) { if (!data) {
this.logger.verbose('Integration not found'); this.repository.integration.create({ integration: 'WHATSAPP-BAILEYS', number: '', token: '' }, this.instanceName);
throw new NotFoundException('Integration not found'); data = { integration: 'WHATSAPP-BAILEYS', number: '', token: '' };
} }
this.logger.verbose(`Integration: ${data.integration}`); this.logger.verbose(`Integration: ${data.integration}`);
@ -740,7 +742,7 @@ export class WAStartupService {
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = { const logData = {
local: WAStartupService.name + '.sendData-RabbitMQ', local: ChannelStartupService.name + '.sendData-RabbitMQ',
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
@ -796,7 +798,7 @@ export class WAStartupService {
sqs.sendMessage(params, (err, data) => { sqs.sendMessage(params, (err, data) => {
if (err) { if (err) {
this.logger.error({ this.logger.error({
local: WAStartupService.name + '.sendData-SQS', local: ChannelStartupService.name + '.sendData-SQS',
message: err?.message, message: err?.message,
hostName: err?.hostname, hostName: err?.hostname,
code: err?.code, code: err?.code,
@ -808,7 +810,7 @@ export class WAStartupService {
} else { } else {
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = { const logData = {
local: WAStartupService.name + '.sendData-SQS', local: ChannelStartupService.name + '.sendData-SQS',
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
@ -852,7 +854,7 @@ export class WAStartupService {
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = { const logData = {
local: WAStartupService.name + '.sendData-WebsocketGlobal', local: ChannelStartupService.name + '.sendData-WebsocketGlobal',
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
@ -882,7 +884,7 @@ export class WAStartupService {
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = { const logData = {
local: WAStartupService.name + '.sendData-Websocket', local: ChannelStartupService.name + '.sendData-Websocket',
event, event,
instance: this.instance.name, instance: this.instance.name,
data, data,
@ -916,7 +918,7 @@ export class WAStartupService {
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = { const logData = {
local: WAStartupService.name + '.sendDataWebhook-local', local: ChannelStartupService.name + '.sendDataWebhook-local',
url: baseURL, url: baseURL,
event, event,
instance: this.instance.name, instance: this.instance.name,
@ -956,7 +958,7 @@ export class WAStartupService {
} }
} catch (error) { } catch (error) {
this.logger.error({ this.logger.error({
local: WAStartupService.name + '.sendDataWebhook-local', local: ChannelStartupService.name + '.sendDataWebhook-local',
message: error?.message, message: error?.message,
hostName: error?.hostname, hostName: error?.hostname,
syscall: error?.syscall, syscall: error?.syscall,
@ -988,7 +990,7 @@ export class WAStartupService {
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) { if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = { const logData = {
local: WAStartupService.name + '.sendDataWebhook-global', local: ChannelStartupService.name + '.sendDataWebhook-global',
url: globalURL, url: globalURL,
event, event,
instance: this.instance.name, instance: this.instance.name,
@ -1027,7 +1029,7 @@ export class WAStartupService {
} }
} catch (error) { } catch (error) {
this.logger.error({ this.logger.error({
local: WAStartupService.name + '.sendDataWebhook-global', local: ChannelStartupService.name + '.sendDataWebhook-global',
message: error?.message, message: error?.message,
hostName: error?.hostname, hostName: error?.hostname,
syscall: error?.syscall, syscall: error?.syscall,

View File

@ -1,5 +1,6 @@
import ffmpegPath from '@ffmpeg-installer/ffmpeg'; import ffmpegPath from '@ffmpeg-installer/ffmpeg';
import { Boom } from '@hapi/boom'; import { Boom } from '@hapi/boom';
import axios from 'axios';
import makeWASocket, { import makeWASocket, {
AnyMessageContent, AnyMessageContent,
BufferedEventData, BufferedEventData,
@ -35,12 +36,11 @@ import makeWASocket, {
WAMessageUpdate, WAMessageUpdate,
WAPresence, WAPresence,
WASocket, WASocket,
} from '@whiskeysockets/baileys'; } from 'baileys';
import { Label } from '@whiskeysockets/baileys/lib/Types/Label'; import { Label } from 'baileys/lib/Types/Label';
import { LabelAssociation } from '@whiskeysockets/baileys/lib/Types/LabelAssociation'; import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
import axios from 'axios';
import { exec } from 'child_process'; import { exec } from 'child_process';
import { arrayUnique, isBase64, isURL } from 'class-validator'; import { isBase64, isURL } from 'class-validator';
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from 'eventemitter2';
// import ffmpeg from 'fluent-ffmpeg'; // import ffmpeg from 'fluent-ffmpeg';
import fs, { existsSync, readFileSync } from 'fs'; import fs, { existsSync, readFileSync } from 'fs';
@ -97,7 +97,6 @@ import {
MediaMessage, MediaMessage,
Options, Options,
SendAudioDto, SendAudioDto,
SendButtonDto,
SendContactDto, SendContactDto,
SendListDto, SendListDto,
SendLocationDto, SendLocationDto,
@ -118,9 +117,9 @@ import { RepositoryBroker } from '../../repository/repository.manager';
import { waMonitor } from '../../server.module'; import { waMonitor } from '../../server.module';
import { Events, MessageSubtype, TypeMediaMessage, wa } from '../../types/wa.types'; import { Events, MessageSubtype, TypeMediaMessage, wa } from '../../types/wa.types';
import { CacheService } from './../cache.service'; import { CacheService } from './../cache.service';
import { WAStartupService } from './../whatsapp.service'; import { ChannelStartupService } from './../channel.service';
export class BaileysStartupService extends WAStartupService { export class BaileysStartupService extends ChannelStartupService {
constructor( constructor(
public readonly configService: ConfigService, public readonly configService: ConfigService,
public readonly eventEmitter: EventEmitter2, public readonly eventEmitter: EventEmitter2,
@ -148,17 +147,17 @@ export class BaileysStartupService extends WAStartupService {
public mobile: boolean; public mobile: boolean;
private async recoveringMessages() { private async recoveringMessages() {
this.logger.info('Recovering messages lost');
const cacheConf = this.configService.get<CacheConf>('CACHE'); const cacheConf = this.configService.get<CacheConf>('CACHE');
if ((cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') || cacheConf?.LOCAL?.ENABLED) { if ((cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') || cacheConf?.LOCAL?.ENABLED) {
setInterval(async () => { setInterval(async () => {
this.logger.info('Recovering messages');
this.messagesLostCache.keys().then((keys) => { this.messagesLostCache.keys().then((keys) => {
keys.forEach(async (key) => { keys.forEach(async (key) => {
const message = await this.messagesLostCache.get(key.split(':')[2]); const message = await this.messagesLostCache.get(key.split(':')[2]);
if (message.messageStubParameters && message.messageStubParameters[0] === 'Message absent from node') { if (message.messageStubParameters && message.messageStubParameters[0] === 'Message absent from node') {
this.logger.verbose('Message absent from node, retrying to send, key: ' + key.split(':')[2]); this.logger.info('Message absent from node, retrying to send, key: ' + key.split(':')[2]);
await this.client.sendMessageAck(JSON.parse(message.messageStubParameters[1], BufferJSON.reviver)); await this.client.sendMessageAck(JSON.parse(message.messageStubParameters[1], BufferJSON.reviver));
} }
}); });
@ -2207,15 +2206,6 @@ export class BaileysStartupService extends WAStartupService {
mimetype = response.headers['content-type']; mimetype = response.headers['content-type'];
} }
// if (isURL(mediaMessage.media)) {
// const response = await axios.get(mediaMessage.media, { responseType: 'arraybuffer' });
// mimetype = response.headers['content-type'];
// console.log('mediaMessage.mimetype2', mimetype);
// } else {
// mimetype = getMIMEType(mediaMessage.fileName);
// console.log('mediaMessage.mimetype3', mimetype);
// }
} }
this.logger.verbose('Mimetype: ' + mimetype); this.logger.verbose('Mimetype: ' + mimetype);
@ -2330,82 +2320,6 @@ export class BaileysStartupService extends WAStartupService {
return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot); return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot);
} }
// public async processAudio(audio: string, number: string) {
// this.logger.verbose('Processing audio');
// let tempAudioPath: string;
// let outputAudio: string;
// number = number.replace(/\D/g, '');
// const hash = `${number}-${new Date().getTime()}`;
// this.logger.verbose('Hash to audio name: ' + hash);
// if (isURL(audio)) {
// this.logger.verbose('Audio is url');
// outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
// tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
// this.logger.verbose('Output audio path: ' + outputAudio);
// this.logger.verbose('Temp audio path: ' + tempAudioPath);
// const timestamp = new Date().getTime();
// const url = `${audio}?timestamp=${timestamp}`;
// this.logger.verbose('Including timestamp in url: ' + url);
// let config: any = {
// responseType: 'arraybuffer',
// };
// if (this.localProxy.enabled) {
// config = {
// ...config,
// httpsAgent: makeProxyAgent(this.localProxy.proxy),
// };
// }
// const response = await axios.get(url, config);
// this.logger.verbose('Getting audio from url');
// fs.writeFileSync(tempAudioPath, response.data);
// } else {
// this.logger.verbose('Audio is base64');
// outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
// tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
// this.logger.verbose('Output audio path: ' + outputAudio);
// this.logger.verbose('Temp audio path: ' + tempAudioPath);
// const audioBuffer = Buffer.from(audio, 'base64');
// fs.writeFileSync(tempAudioPath, audioBuffer);
// this.logger.verbose('Temp audio created');
// }
// this.logger.verbose('Converting audio to mp4');
// return new Promise((resolve, reject) => {
// // This fix was suggested by @PurpShell
// ffmpeg.setFfmpegPath(ffmpegPath.path);
// ffmpeg()
// .input(tempAudioPath)
// .outputFormat('ogg')
// .noVideo()
// .audioCodec('libopus')
// .save(outputAudio)
// .on('error', function (error) {
// console.log('error', error);
// fs.unlinkSync(tempAudioPath);
// if (error) reject(error);
// })
// .on('end', async function () {
// fs.unlinkSync(tempAudioPath);
// resolve(outputAudio);
// })
// .run();
// });
// }
public async processAudio(audio: string, number: string) { public async processAudio(audio: string, number: string) {
this.logger.verbose('Processing audio'); this.logger.verbose('Processing audio');
let tempAudioPath: string; let tempAudioPath: string;
@ -2506,50 +2420,8 @@ export class BaileysStartupService extends WAStartupService {
); );
} }
public async buttonMessage(data: SendButtonDto) { public async buttonMessage() {
this.logger.verbose('Sending button message'); throw new BadRequestException('Method not available on WhatsApp Baileys');
const embeddedMedia: any = {};
let mediatype = 'TEXT';
if (data.buttonMessage?.mediaMessage) {
mediatype = data.buttonMessage.mediaMessage?.mediatype.toUpperCase() ?? 'TEXT';
embeddedMedia.mediaKey = mediatype.toLowerCase() + 'Message';
const generate = await this.prepareMediaMessage(data.buttonMessage.mediaMessage);
embeddedMedia.message = generate.message[embeddedMedia.mediaKey];
embeddedMedia.contentText = `*${data.buttonMessage.title}*\n\n${data.buttonMessage.description}`;
}
const btnItems = {
text: data.buttonMessage.buttons.map((btn) => btn.buttonText),
ids: data.buttonMessage.buttons.map((btn) => btn.buttonId),
};
if (!arrayUnique(btnItems.text) || !arrayUnique(btnItems.ids)) {
throw new BadRequestException('Button texts cannot be repeated', 'Button IDs cannot be repeated.');
}
return await this.sendMessageWithTyping(
data.number,
{
buttonsMessage: {
text: !embeddedMedia?.mediaKey ? data.buttonMessage.title : undefined,
contentText: embeddedMedia?.contentText ?? data.buttonMessage.description,
footerText: data.buttonMessage?.footerText,
buttons: data.buttonMessage.buttons.map((button) => {
return {
buttonText: {
displayText: button.buttonText,
},
buttonId: button.buttonId,
type: 1,
};
}),
headerType: proto.Message.ButtonsMessage.HeaderType[mediatype],
[embeddedMedia?.mediaKey]: embeddedMedia?.message,
},
},
data?.options,
);
} }
public async locationMessage(data: SendLocationDto) { public async locationMessage(data: SendLocationDto) {

View File

@ -26,9 +26,9 @@ import { ContactRaw, MessageRaw, MessageUpdateRaw, SettingsRaw } from '../../mod
import { RepositoryBroker } from '../../repository/repository.manager'; import { RepositoryBroker } from '../../repository/repository.manager';
import { Events, wa } from '../../types/wa.types'; import { Events, wa } from '../../types/wa.types';
import { CacheService } from './../cache.service'; import { CacheService } from './../cache.service';
import { WAStartupService } from './../whatsapp.service'; import { ChannelStartupService } from './../channel.service';
export class BusinessStartupService extends WAStartupService { export class BusinessStartupService extends ChannelStartupService {
constructor( constructor(
public readonly configService: ConfigService, public readonly configService: ConfigService,
public readonly eventEmitter: EventEmitter2, public readonly eventEmitter: EventEmitter2,

View File

@ -22,7 +22,8 @@ export class IntegrationService {
const result = await this.waMonitor.waInstances[instance.instanceName].findIntegration(); const result = await this.waMonitor.waInstances[instance.instanceName].findIntegration();
if (Object.keys(result).length === 0) { if (Object.keys(result).length === 0) {
throw new Error('Integration not found'); this.create(instance, { integration: 'WHATSAPP-BAILEYS', number: '', token: '' });
return { integration: 'WHATSAPP-BAILEYS', number: '', token: '' };
} }
return result; return result;

View File

@ -25,8 +25,8 @@ import {
import { RepositoryBroker } from '../repository/repository.manager'; import { RepositoryBroker } from '../repository/repository.manager';
import { Integration } from '../types/wa.types'; import { Integration } from '../types/wa.types';
import { CacheService } from './cache.service'; import { CacheService } from './cache.service';
import { BaileysStartupService } from './whatsapp/whatsapp.baileys.service'; import { BaileysStartupService } from './channels/whatsapp.baileys.service';
import { BusinessStartupService } from './whatsapp/whatsapp.business.service'; import { BusinessStartupService } from './channels/whatsapp.business.service';
export class WAMonitoringService { export class WAMonitoringService {
constructor( constructor(

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-namespace */ /* eslint-disable @typescript-eslint/no-namespace */
import { AuthenticationState, WAConnectionState } from '@whiskeysockets/baileys'; import { AuthenticationState, WAConnectionState } from 'baileys';
export enum Events { export enum Events {
APPLICATION_STARTUP = 'application.startup', APPLICATION_STARTUP = 'application.startup',

View File

@ -1,4 +1,4 @@
import { BufferJSON } from '@whiskeysockets/baileys'; import { BufferJSON } from 'baileys';
import { RedisClientType } from 'redis'; import { RedisClientType } from 'redis';
import { ICache } from '../api/abstract/abstract.cache'; import { ICache } from '../api/abstract/abstract.cache';

View File

@ -25,7 +25,7 @@ info:
</font> </font>
[![Run in Postman](https://run.pstmn.io/button.svg)](https://god.gw.postman.com/run-collection/26869335-5546d063-156b-4529-915f-909dd628c090?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D26869335-5546d063-156b-4529-915f-909dd628c090%26entityType%3Dcollection%26workspaceId%3D339a4ee7-378b-45c9-b5b8-fd2c0a9c2442) [![Run in Postman](https://run.pstmn.io/button.svg)](https://god.gw.postman.com/run-collection/26869335-5546d063-156b-4529-915f-909dd628c090?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D26869335-5546d063-156b-4529-915f-909dd628c090%26entityType%3Dcollection%26workspaceId%3D339a4ee7-378b-45c9-b5b8-fd2c0a9c2442)
version: 1.7.3 version: 1.7.4
contact: contact:
name: DavidsonGomes name: DavidsonGomes
email: contato@agenciadgcode.com email: contato@agenciadgcode.com

View File

@ -22,5 +22,6 @@
"cw.contactMessage.contact": "Contact", "cw.contactMessage.contact": "Contact",
"cw.contactMessage.name": "Name", "cw.contactMessage.name": "Name",
"cw.contactMessage.number": "Number", "cw.contactMessage.number": "Number",
"cw.message.notsent": "🚨 The message could not be sent. Please check your connection. {{error}}",
"cw.message.edited": "Edited Message" "cw.message.edited": "Edited Message"
} }

View File

@ -22,5 +22,6 @@
"cw.contactMessage.contact": "Contacto", "cw.contactMessage.contact": "Contacto",
"cw.contactMessage.name": "Nombre", "cw.contactMessage.name": "Nombre",
"cw.contactMessage.number": "Numero", "cw.contactMessage.number": "Numero",
"cw.message.notsent": "🚨 El mensaje no se pudo enviar. Comprueba tu conexión. {{error}}",
"cw.message.edited": "Mensaje editado" "cw.message.edited": "Mensaje editado"
} }

View File

@ -22,5 +22,6 @@
"cw.contactMessage.contact": "Contato", "cw.contactMessage.contact": "Contato",
"cw.contactMessage.name": "Nome", "cw.contactMessage.name": "Nome",
"cw.contactMessage.number": "Número", "cw.contactMessage.number": "Número",
"cw.message.notsent": "🚨 Não foi possível enviar a mensagem. Verifique sua conexão. {{error}}",
"cw.message.edited": "Mensagem editada" "cw.message.edited": "Mensagem editada"
} }

View File

@ -1,11 +1,4 @@
import { import { AuthenticationCreds, AuthenticationState, BufferJSON, initAuthCreds, proto, SignalDataTypeMap } from 'baileys';
AuthenticationCreds,
AuthenticationState,
BufferJSON,
initAuthCreds,
proto,
SignalDataTypeMap,
} from '@whiskeysockets/baileys';
import { configService, Database } from '../config/env.config'; import { configService, Database } from '../config/env.config';
import { Logger } from '../config/logger.config'; import { Logger } from '../config/logger.config';

View File

@ -1,10 +1,4 @@
import { import { AuthenticationCreds, AuthenticationState, initAuthCreds, proto, SignalDataTypeMap } from 'baileys';
AuthenticationCreds,
AuthenticationState,
initAuthCreds,
proto,
SignalDataTypeMap,
} from '@whiskeysockets/baileys';
import { CacheService } from '../api/services/cache.service'; import { CacheService } from '../api/services/cache.service';
import { Logger } from '../config/logger.config'; import { Logger } from '../config/logger.config';