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
22 changes: 17 additions & 5 deletions src/api/integrations/channel/meta/whatsapp.business.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,18 @@ export class BusinessStartupService extends ChannelStartupService {
if (received.messages) {
const message = received.messages[0]; // Añadir esta línea para definir message

let bsuid = null;
let parentBsuid = null;

if (message?.from_user_id) bsuid = message?.from_user_id;
if (message?.from_parent_user_id) parentBsuid = message?.from_parent_user_id;

const key = {
id: message.id,
remoteJid: this.phoneNumber,
remoteJid: this.phoneNumber || bsuid,
fromMe: message.from === received.metadata.phone_number_id,
bsuid, // Business Scoped User ID
parentBsuid, // Parent Business Scoped User ID
};

if (message.type === 'sticker') {
Expand Down Expand Up @@ -701,11 +709,14 @@ export class BusinessStartupService extends ChannelStartupService {
where: { instanceId: this.instanceId, remoteJid: key.remoteJid },
});

const contactRemoteJid = received.contacts[0].profile?.phone || this.phoneNumber || bsuid;

const contactRaw: any = {
remoteJid: received.contacts[0].profile.phone,
remoteJid: contactRemoteJid,
pushName,
// profilePicUrl: '',
instanceId: this.instanceId,
bsuid,
parentBsuid,
};

if (contactRaw.remoteJid === 'status@broadcast') {
Expand All @@ -714,10 +725,11 @@ export class BusinessStartupService extends ChannelStartupService {

if (contact) {
const contactRaw: any = {
remoteJid: received.contacts[0].profile.phone,
remoteJid: contactRemoteJid,
pushName,
// profilePicUrl: '',
instanceId: this.instanceId,
bsuid, // Business Scoped User ID
parentBsuid, // Parent Business Scoped User ID
};

this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/createJid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function formatBRNumber(jid: string) {
}

export function createJid(number: string): string {
if (!number) return null;

number = number.replace(/:\d+/, '');

if (
Expand Down
Loading