mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
Review integration with official WhatsApp API
This commit is contained in:
parent
585bf84af4
commit
9e25904dc9
13
README.md
13
README.md
@ -155,3 +155,16 @@ This code was produced based on the baileys library and it is still under develo
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
|
# Content Creator Partners
|
||||||
|
|
||||||
|
We are proud to collaborate with the following content creators who have contributed valuable insights and tutorials about Evolution API:
|
||||||
|
|
||||||
|
- [Promovaweb](https://www.youtube.com/@promovaweb)
|
||||||
|
- [Comunidade ZDG](https://www.youtube.com/@ComunidadeZDG)
|
||||||
|
- [Francis MNO](https://www.youtube.com/@FrancisMNO)
|
||||||
|
- [Pablo Cabral](https://youtube.com/@pablocabral)
|
||||||
|
- [XPop Digital](https://www.youtube.com/@xpopdigital)
|
||||||
|
- [Costar Wagner Dev](https://www.youtube.com/@costarwagnerdev)
|
||||||
|
- [Dante Testa](https://youtube.com/@dantetesta_)
|
||||||
|
- [Rubén Salazar](https://youtube.com/channel/UCnYGZIE2riiLqaN9sI6riig)
|
@ -1,6 +1,6 @@
|
|||||||
import { JsonValue } from '@prisma/client/runtime/library';
|
import { JsonValue } from '@prisma/client/runtime/library';
|
||||||
import { delay } from '@whiskeysockets/baileys';
|
import { delay } from '@whiskeysockets/baileys';
|
||||||
import { isURL } from 'class-validator';
|
import { isArray, isURL } from 'class-validator';
|
||||||
import EventEmitter2 from 'eventemitter2';
|
import EventEmitter2 from 'eventemitter2';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
@ -215,8 +215,6 @@ export class InstanceController {
|
|||||||
const rabbitmqEventsJson: JsonValue = (await this.rabbitmqService.find(instance)).events;
|
const rabbitmqEventsJson: JsonValue = (await this.rabbitmqService.find(instance)).events;
|
||||||
|
|
||||||
getRabbitmqEvents = Array.isArray(rabbitmqEventsJson) ? rabbitmqEventsJson.map((event) => String(event)) : [];
|
getRabbitmqEvents = Array.isArray(rabbitmqEventsJson) ? rabbitmqEventsJson.map((event) => String(event)) : [];
|
||||||
|
|
||||||
// rabbitmqEvents = (await this.rabbitmqService.find(instance)).events;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.log(error);
|
this.logger.log(error);
|
||||||
}
|
}
|
||||||
@ -279,7 +277,7 @@ export class InstanceController {
|
|||||||
syncFullHistory: syncFullHistory ?? false,
|
syncFullHistory: syncFullHistory ?? false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.settingsService.create(instance, settings);
|
await this.settingsService.create(instance, settings);
|
||||||
|
|
||||||
let webhookWaBusiness = null,
|
let webhookWaBusiness = null,
|
||||||
accessTokenWaBusiness = '';
|
accessTokenWaBusiness = '';
|
||||||
@ -296,7 +294,7 @@ export class InstanceController {
|
|||||||
if (!chatwootAccountId || !chatwootToken || !chatwootUrl) {
|
if (!chatwootAccountId || !chatwootToken || !chatwootUrl) {
|
||||||
let getQrcode: wa.QrCode;
|
let getQrcode: wa.QrCode;
|
||||||
|
|
||||||
if (qrcode) {
|
if (qrcode && integration === Integration.WHATSAPP_BAILEYS) {
|
||||||
await instance.connectToWhatsapp(number);
|
await instance.connectToWhatsapp(number);
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
getQrcode = instance.qrCode;
|
getQrcode = instance.qrCode;
|
||||||
@ -334,6 +332,8 @@ export class InstanceController {
|
|||||||
qrcode: getQrcode,
|
qrcode: getQrcode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('log13', result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,8 +438,8 @@ export class InstanceController {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error.message[0]);
|
this.logger.error(isArray(error.message) ? error.message[0] : error.message);
|
||||||
throw new BadRequestException(error.message[0]);
|
throw new BadRequestException(isArray(error.message) ? error.message[0] : error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,6 +721,8 @@ export class ChatwootService {
|
|||||||
|
|
||||||
const sourceReplyId = quotedMsg?.chatwootMessageId || null;
|
const sourceReplyId = quotedMsg?.chatwootMessageId || null;
|
||||||
|
|
||||||
|
console.log('sourceReplyId', sourceReplyId);
|
||||||
|
|
||||||
const message = await client.messages.create({
|
const message = await client.messages.create({
|
||||||
accountId: this.provider.accountId,
|
accountId: this.provider.accountId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
@ -1734,6 +1736,8 @@ export class ChatwootService {
|
|||||||
|
|
||||||
const quotedId = body.contextInfo?.stanzaId || body.message?.contextInfo?.stanzaId;
|
const quotedId = body.contextInfo?.stanzaId || body.message?.contextInfo?.stanzaId;
|
||||||
|
|
||||||
|
console.log('quotedId', quotedId);
|
||||||
|
|
||||||
let quotedMsg = null;
|
let quotedMsg = null;
|
||||||
|
|
||||||
if (quotedId)
|
if (quotedId)
|
||||||
@ -1746,6 +1750,8 @@ export class ChatwootService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('quotedMsg', quotedMsg);
|
||||||
|
|
||||||
const isMedia = this.isMediaMessage(body.message);
|
const isMedia = this.isMediaMessage(body.message);
|
||||||
|
|
||||||
const adsMessage = this.getAdsMessage(body.message);
|
const adsMessage = this.getAdsMessage(body.message);
|
||||||
@ -1968,8 +1974,6 @@ export class ChatwootService {
|
|||||||
if (event === Events.MESSAGES_DELETE) {
|
if (event === Events.MESSAGES_DELETE) {
|
||||||
const chatwootDelete = this.configService.get<Chatwoot>('CHATWOOT').MESSAGE_DELETE;
|
const chatwootDelete = this.configService.get<Chatwoot>('CHATWOOT').MESSAGE_DELETE;
|
||||||
|
|
||||||
console.log('chatwootDelete', chatwootDelete);
|
|
||||||
|
|
||||||
if (chatwootDelete === true) {
|
if (chatwootDelete === true) {
|
||||||
if (!body?.key?.id) {
|
if (!body?.key?.id) {
|
||||||
this.logger.warn('message id not found');
|
this.logger.warn('message id not found');
|
||||||
@ -1977,7 +1981,6 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const message = await this.getMessageByKeyId(instance, body.key.id);
|
const message = await this.getMessageByKeyId(instance, body.key.id);
|
||||||
console.log('message', message);
|
|
||||||
|
|
||||||
if (message?.chatwootMessageId && message?.chatwootConversationId) {
|
if (message?.chatwootMessageId && message?.chatwootConversationId) {
|
||||||
await this.prismaRepository.message.deleteMany({
|
await this.prismaRepository.message.deleteMany({
|
||||||
|
@ -268,7 +268,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.QRCODE_UPDATED,
|
Events.QRCODE_UPDATED,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
{
|
{
|
||||||
message: 'QR code limit reached, please login again',
|
message: 'QR code limit reached, please login again',
|
||||||
statusCode: DisconnectReason.badSession,
|
statusCode: DisconnectReason.badSession,
|
||||||
@ -326,7 +326,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.QRCODE_UPDATED,
|
Events.QRCODE_UPDATED,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
{
|
{
|
||||||
qrcode: {
|
qrcode: {
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
@ -381,7 +381,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.STATUS_INSTANCE,
|
Events.STATUS_INSTANCE,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
{
|
{
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
status: 'closed',
|
status: 'closed',
|
||||||
@ -427,7 +427,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.CONNECTION_UPDATE,
|
Events.CONNECTION_UPDATE,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
{
|
{
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
status: 'open',
|
status: 'open',
|
||||||
@ -835,8 +835,14 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
this.localChatwoot.importContacts &&
|
this.localChatwoot.importContacts &&
|
||||||
contactsRaw.length
|
contactsRaw.length
|
||||||
) {
|
) {
|
||||||
this.chatwootService.addHistoryContacts({ instanceName: this.instance.name }, contactsRaw);
|
this.chatwootService.addHistoryContacts(
|
||||||
chatwootImport.importHistoryContacts({ instanceName: this.instance.name }, this.localChatwoot);
|
{ instanceName: this.instance.name, instanceId: this.instance.id },
|
||||||
|
contactsRaw,
|
||||||
|
);
|
||||||
|
chatwootImport.importHistoryContacts(
|
||||||
|
{ instanceName: this.instance.name, instanceId: this.instance.id },
|
||||||
|
this.localChatwoot,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedContacts = await Promise.all(
|
const updatedContacts = await Promise.all(
|
||||||
@ -1061,7 +1067,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled)
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled)
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
'messages.edit',
|
'messages.edit',
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instance.id },
|
||||||
editedMessage,
|
editedMessage,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1167,7 +1173,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
) {
|
) {
|
||||||
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
|
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
|
||||||
Events.MESSAGES_UPSERT,
|
Events.MESSAGES_UPSERT,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instance.id },
|
||||||
messageRaw,
|
messageRaw,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1221,7 +1227,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
await this.chatwootService.eventWhatsapp(
|
await this.chatwootService.eventWhatsapp(
|
||||||
Events.CONTACTS_UPDATE,
|
Events.CONTACTS_UPDATE,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
contactRaw,
|
contactRaw,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1260,7 +1266,11 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
if (status[update.status] === 'READ' && key.fromMe) {
|
if (status[update.status] === 'READ' && key.fromMe) {
|
||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp('messages.read', { instanceName: this.instance.name }, { key: key });
|
this.chatwootService.eventWhatsapp(
|
||||||
|
'messages.read',
|
||||||
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
|
{ key: key },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1313,7 +1323,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.MESSAGES_DELETE,
|
Events.MESSAGES_DELETE,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
{ key: key },
|
{ key: key },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1680,7 +1690,11 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
key: { remoteJid: isWA.jid },
|
key: { remoteJid: isWA.jid },
|
||||||
};
|
};
|
||||||
|
|
||||||
this.chatwootService.eventWhatsapp('contact.is_not_in_wpp', { instanceName: this.instance.name }, body);
|
this.chatwootService.eventWhatsapp(
|
||||||
|
'contact.is_not_in_wpp',
|
||||||
|
{ instanceName: this.instance.name, instanceId: this.instance.id },
|
||||||
|
body,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
throw new BadRequestException(isWA);
|
throw new BadRequestException(isWA);
|
||||||
}
|
}
|
||||||
@ -1889,7 +1903,11 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
|
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
|
||||||
|
|
||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isIntegration) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isIntegration) {
|
||||||
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
|
this.chatwootService.eventWhatsapp(
|
||||||
|
Events.SEND_MESSAGE,
|
||||||
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
|
messageRaw,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.configService.get<Typebot>('TYPEBOT').ENABLED && !isIntegration) {
|
if (this.configService.get<Typebot>('TYPEBOT').ENABLED && !isIntegration) {
|
||||||
|
@ -126,6 +126,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
public async connectToWhatsapp(data?: any): Promise<any> {
|
public async connectToWhatsapp(data?: any): Promise<any> {
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
const content = data.entry[0].changes[0].value;
|
const content = data.entry[0].changes[0].value;
|
||||||
try {
|
try {
|
||||||
this.loadWebhook();
|
this.loadWebhook();
|
||||||
@ -316,10 +317,11 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
...this.messageMediaJson(received),
|
...this.messageMediaJson(received),
|
||||||
base64: buffer ? buffer.toString('base64') : undefined,
|
base64: buffer ? buffer.toString('base64') : undefined,
|
||||||
},
|
},
|
||||||
|
contextInfo: this.messageTextJson(received)?.contextInfo,
|
||||||
messageType: this.renderMessageType(received.messages[0].type),
|
messageType: this.renderMessageType(received.messages[0].type),
|
||||||
messageTimestamp: received.messages[0].timestamp as number,
|
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
|
||||||
owner: this.instance.name,
|
source: 'unknown',
|
||||||
// source: getDevice(received.key.id),
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
} else if (received?.messages[0].interactive) {
|
} else if (received?.messages[0].interactive) {
|
||||||
messageRaw = {
|
messageRaw = {
|
||||||
@ -328,10 +330,11 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
message: {
|
message: {
|
||||||
...this.messageInteractiveJson(received),
|
...this.messageInteractiveJson(received),
|
||||||
},
|
},
|
||||||
|
contextInfo: this.messageTextJson(received)?.contextInfo,
|
||||||
messageType: 'conversation',
|
messageType: 'conversation',
|
||||||
messageTimestamp: received.messages[0].timestamp as number,
|
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
|
||||||
owner: this.instance.name,
|
source: 'unknown',
|
||||||
// source: getDevice(received.key.id),
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
} else if (received?.messages[0].reaction) {
|
} else if (received?.messages[0].reaction) {
|
||||||
messageRaw = {
|
messageRaw = {
|
||||||
@ -340,10 +343,11 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
message: {
|
message: {
|
||||||
...this.messageReactionJson(received),
|
...this.messageReactionJson(received),
|
||||||
},
|
},
|
||||||
|
contextInfo: this.messageTextJson(received)?.contextInfo,
|
||||||
messageType: 'reactionMessage',
|
messageType: 'reactionMessage',
|
||||||
messageTimestamp: received.messages[0].timestamp as number,
|
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
|
||||||
owner: this.instance.name,
|
source: 'unknown',
|
||||||
// source: getDevice(received.key.id),
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
} else if (received?.messages[0].contacts) {
|
} else if (received?.messages[0].contacts) {
|
||||||
messageRaw = {
|
messageRaw = {
|
||||||
@ -352,20 +356,22 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
message: {
|
message: {
|
||||||
...this.messageContactsJson(received),
|
...this.messageContactsJson(received),
|
||||||
},
|
},
|
||||||
|
contextInfo: this.messageTextJson(received)?.contextInfo,
|
||||||
messageType: 'conversation',
|
messageType: 'conversation',
|
||||||
messageTimestamp: received.messages[0].timestamp as number,
|
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
|
||||||
owner: this.instance.name,
|
source: 'unknown',
|
||||||
// source: getDevice(received.key.id),
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
messageRaw = {
|
messageRaw = {
|
||||||
key,
|
key,
|
||||||
pushName,
|
pushName,
|
||||||
message: this.messageTextJson(received),
|
message: this.messageTextJson(received),
|
||||||
|
contextInfo: this.messageTextJson(received)?.contextInfo,
|
||||||
messageType: this.renderMessageType(received.messages[0].type),
|
messageType: this.renderMessageType(received.messages[0].type),
|
||||||
messageTimestamp: received.messages[0].timestamp as number,
|
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
|
||||||
owner: this.instance.name,
|
source: 'unknown',
|
||||||
//source: getDevice(received.key.id),
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,23 +390,21 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
|
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
|
||||||
Events.MESSAGES_UPSERT,
|
Events.MESSAGES_UPSERT,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
messageRaw,
|
messageRaw,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (chatwootSentMessage?.id) {
|
if (chatwootSentMessage?.id) {
|
||||||
messageRaw.chatwoot = {
|
messageRaw.chatwootMessageId = chatwootSentMessage.id;
|
||||||
messageId: chatwootSentMessage.id,
|
messageRaw.chatwootInboxId = chatwootSentMessage.id;
|
||||||
inboxId: chatwootSentMessage.inbox_id,
|
messageRaw.chatwootConversationId = chatwootSentMessage.id;
|
||||||
conversationId: chatwootSentMessage.conversation_id,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.configService.get<Typebot>('TYPEBOT').ENABLED) {
|
if (this.configService.get<Typebot>('TYPEBOT').ENABLED) {
|
||||||
if (messageRaw.messageType !== 'reactionMessage')
|
if (messageRaw.messageType !== 'reactionMessage')
|
||||||
await this.typebotService.sendTypebot(
|
await this.typebotService.sendTypebot(
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
messageRaw.key.remoteJid,
|
messageRaw.key.remoteJid,
|
||||||
messageRaw,
|
messageRaw,
|
||||||
);
|
);
|
||||||
@ -438,7 +442,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
await this.chatwootService.eventWhatsapp(
|
await this.chatwootService.eventWhatsapp(
|
||||||
Events.CONTACTS_UPDATE,
|
Events.CONTACTS_UPDATE,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
contactRaw,
|
contactRaw,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -479,6 +483,10 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!findMessage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (item.message === null && item.status === undefined) {
|
if (item.message === null && item.status === undefined) {
|
||||||
this.sendDataWebhook(Events.MESSAGES_DELETE, key);
|
this.sendDataWebhook(Events.MESSAGES_DELETE, key);
|
||||||
|
|
||||||
@ -489,7 +497,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
fromMe: key.fromMe,
|
fromMe: key.fromMe,
|
||||||
participant: key?.remoteJid,
|
participant: key?.remoteJid,
|
||||||
status: 'DELETED',
|
status: 'DELETED',
|
||||||
dateTime: Date.now(),
|
|
||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -500,7 +507,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.MESSAGES_DELETE,
|
Events.MESSAGES_DELETE,
|
||||||
{ instanceName: this.instance.name },
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
{ key: key },
|
{ key: key },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -515,7 +522,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
fromMe: key.fromMe,
|
fromMe: key.fromMe,
|
||||||
participant: key?.remoteJid,
|
participant: key?.remoteJid,
|
||||||
status: item.status.toUpperCase(),
|
status: item.status.toUpperCase(),
|
||||||
dateTime: Date.now(),
|
|
||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -607,7 +613,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
this.messageHandle(content, database, settings);
|
this.messageHandle(content, database, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async sendMessageWithTyping(number: string, message: any, options?: Options, isChatwoot = false) {
|
protected async sendMessageWithTyping(number: string, message: any, options?: Options, isIntegration = false) {
|
||||||
try {
|
try {
|
||||||
let quoted: any;
|
let quoted: any;
|
||||||
const linkPreview = options?.linkPreview != false ? undefined : false;
|
const linkPreview = options?.linkPreview != false ? undefined : false;
|
||||||
@ -793,8 +799,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
throw messageSent.error.message.toString();
|
throw messageSent.error.message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(content);
|
|
||||||
|
|
||||||
const messageRaw: any = {
|
const messageRaw: any = {
|
||||||
key: { fromMe: true, id: messageSent?.messages[0]?.id, remoteJid: this.createJid(number) },
|
key: { fromMe: true, id: messageSent?.messages[0]?.id, remoteJid: this.createJid(number) },
|
||||||
//pushName: messageSent.pushName,
|
//pushName: messageSent.pushName,
|
||||||
@ -802,15 +806,28 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
messageType: this.renderMessageType(content.type),
|
messageType: this.renderMessageType(content.type),
|
||||||
messageTimestamp: (messageSent?.messages[0]?.timestamp as number) || Math.round(new Date().getTime() / 1000),
|
messageTimestamp: (messageSent?.messages[0]?.timestamp as number) || Math.round(new Date().getTime() / 1000),
|
||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
//ource: getDevice(messageSent.key.id),
|
source: 'unknown',
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logger.log(messageRaw);
|
this.logger.log(messageRaw);
|
||||||
|
|
||||||
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
|
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
|
||||||
|
|
||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isChatwoot) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isIntegration) {
|
||||||
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
|
this.chatwootService.eventWhatsapp(
|
||||||
|
Events.SEND_MESSAGE,
|
||||||
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
|
messageRaw,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.configService.get<Typebot>('TYPEBOT').ENABLED && !isIntegration) {
|
||||||
|
if (messageRaw.messageType !== 'reactionMessage')
|
||||||
|
await this.typebotService.sendTypebot(
|
||||||
|
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||||
|
messageRaw.key.remoteJid,
|
||||||
|
messageRaw,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.prismaRepository.message.create({
|
await this.prismaRepository.message.create({
|
||||||
@ -819,13 +836,14 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
return messageRaw;
|
return messageRaw;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error.response.data);
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
throw new BadRequestException(error.toString());
|
throw new BadRequestException(error.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send Message Controller
|
// Send Message Controller
|
||||||
public async textMessage(data: SendTextDto, isChatwoot = false) {
|
public async textMessage(data: SendTextDto, isIntegration = false) {
|
||||||
const res = await this.sendMessageWithTyping(
|
const res = await this.sendMessageWithTyping(
|
||||||
data.number,
|
data.number,
|
||||||
{
|
{
|
||||||
@ -841,7 +859,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
mentioned: data?.mentioned,
|
mentioned: data?.mentioned,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isChatwoot,
|
isIntegration,
|
||||||
);
|
);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -890,9 +908,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
gifPlayback: false,
|
gifPlayback: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mediaMessage.mimetype) {
|
|
||||||
mimetype = mediaMessage.mimetype;
|
|
||||||
} else {
|
|
||||||
if (isURL(mediaMessage.media)) {
|
if (isURL(mediaMessage.media)) {
|
||||||
mimetype = getMIMEType(mediaMessage.media);
|
mimetype = getMIMEType(mediaMessage.media);
|
||||||
prepareMedia.id = mediaMessage.media;
|
prepareMedia.id = mediaMessage.media;
|
||||||
@ -903,7 +918,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
prepareMedia.id = id;
|
prepareMedia.id = id;
|
||||||
prepareMedia.type = 'id';
|
prepareMedia.type = 'id';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
prepareMedia.mimetype = mimetype;
|
prepareMedia.mimetype = mimetype;
|
||||||
|
|
||||||
@ -914,7 +928,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async mediaMessage(data: SendMediaDto, isChatwoot = false) {
|
public async mediaMessage(data: SendMediaDto, isIntegration = false) {
|
||||||
const message = await this.prepareMediaMessage(data);
|
const message = await this.prepareMediaMessage(data);
|
||||||
|
|
||||||
return await this.sendMessageWithTyping(
|
return await this.sendMessageWithTyping(
|
||||||
@ -930,7 +944,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
mentioned: data?.mentioned,
|
mentioned: data?.mentioned,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isChatwoot,
|
isIntegration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -962,7 +976,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
return prepareMedia;
|
return prepareMedia;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async audioWhatsapp(data: SendAudioDto, isChatwoot = false) {
|
public async audioWhatsapp(data: SendAudioDto, isIntegration = false) {
|
||||||
const message = await this.processAudio(data.audio, data.number);
|
const message = await this.processAudio(data.audio, data.number);
|
||||||
|
|
||||||
return await this.sendMessageWithTyping(
|
return await this.sendMessageWithTyping(
|
||||||
@ -978,7 +992,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
mentioned: data?.mentioned,
|
mentioned: data?.mentioned,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isChatwoot,
|
isIntegration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,7 +1102,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async templateMessage(data: SendTemplateDto, isChatwoot = false) {
|
public async templateMessage(data: SendTemplateDto, isIntegration = false) {
|
||||||
const res = await this.sendMessageWithTyping(
|
const res = await this.sendMessageWithTyping(
|
||||||
data.number,
|
data.number,
|
||||||
{
|
{
|
||||||
@ -1108,7 +1122,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
mentioned: data?.mentioned,
|
mentioned: data?.mentioned,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isChatwoot,
|
isIntegration,
|
||||||
);
|
);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ export class SettingsService {
|
|||||||
|
|
||||||
private readonly logger = new Logger(SettingsService.name);
|
private readonly logger = new Logger(SettingsService.name);
|
||||||
|
|
||||||
public create(instance: InstanceDto, data: SettingsDto) {
|
public async create(instance: InstanceDto, data: SettingsDto) {
|
||||||
this.waMonitor.waInstances[instance.instanceName].setSettings(data);
|
await this.waMonitor.waInstances[instance.instanceName].setSettings(data);
|
||||||
|
|
||||||
return { settings: { ...instance, settings: data } };
|
return { settings: { ...instance, settings: data } };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user