diff --git a/src/apps/chatwoot/consumers/waha/base.ts b/src/apps/chatwoot/consumers/waha/base.ts index e288e172..523e4e2c 100644 --- a/src/apps/chatwoot/consumers/waha/base.ts +++ b/src/apps/chatwoot/consumers/waha/base.ts @@ -35,8 +35,8 @@ import { sleep } from '@waha/utils/promiseTimeout'; import { Job } from 'bullmq'; import { PinoLogger } from 'nestjs-pino'; -import { ChatWootAppConfig } from '../../dto/config.dto'; import { TKey } from '@waha/apps/chatwoot/i18n/templates'; +import { isJidBroadcast } from '@adiwajshing/baileys/lib/WABinary/jid-utils'; export function ListenEventsForChatWoot() { return [ @@ -285,7 +285,7 @@ export abstract class MessageBaseHandler { const chatId = payload.from; // Add participant name to group messages - const manyParticipants = isJidGroup(chatId) || isJidStatusBroadcast(chatId); + const manyParticipants = isJidGroup(chatId) || isJidBroadcast(chatId); if (!payload.fromMe && manyParticipants) { const key = parseMessageIdSerialized(payload.id, true); let participant = toCusFormat(key.participant); diff --git a/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts b/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts index b072b91e..cbeb4698 100644 --- a/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts +++ b/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts @@ -3,8 +3,14 @@ import { isJidNewsletter, isJidStatusBroadcast, } from '@adiwajshing/baileys'; -import { isLidUser } from '@adiwajshing/baileys/lib/WABinary/jid-utils'; -import { public_contact_create_update_payload as Contact } from '@figuro/chatwoot-sdk'; +import { + isJidBroadcast, + isLidUser, +} from '@adiwajshing/baileys/lib/WABinary/jid-utils'; +import { + public_contact_create_update_payload, + public_contact_create_update_payload as Contact, +} from '@figuro/chatwoot-sdk'; import { ContactInfo } from '@waha/apps/chatwoot/client/ContactConversationService'; import { AttributeKey } from '@waha/apps/chatwoot/const'; import { Locale } from '@waha/apps/chatwoot/i18n/locale'; @@ -221,6 +227,31 @@ class StatusContactInfo extends ChatContactInfo { } } +class BroadcastContactInfo extends ChatContactInfo { + async Attributes() { + return { + [AttributeKey.WA_CHAT_ID]: this.chatId, + }; + } + + @CacheAsync() + async AvatarUrl(): Promise { + return null; + } + + async PublicContactCreate(): Promise { + const name = this.locale + .key(TKey.WHATSAPP_CONTACT_BROADCAST_SUFFIX) + .render(); + + return { + identifier: this.chatId, + name: `${name} (${this.chatId})`, + custom_attributes: await this.Attributes(), + }; + } +} + /** * Factory function to get the appropriate ContactInfo implementation * based on the chat ID type @@ -236,6 +267,8 @@ export function WhatsAppContactInfo( return new ChannelContactInfo(session, chatId, locale); } else if (isJidStatusBroadcast(chatId)) { return new StatusContactInfo(session, chatId, locale); + } else if (isJidBroadcast(chatId)) { + return new BroadcastContactInfo(session, chatId, locale); } else if (isLidUser(chatId)) { return new LidContactInfo(session, chatId, locale); } diff --git a/src/apps/chatwoot/i18n/locales/ar-AE.yaml b/src/apps/chatwoot/i18n/locales/ar-AE.yaml index c9445496..3468b1c2 100644 --- a/src/apps/chatwoot/i18n/locales/ar-AE.yaml +++ b/src/apps/chatwoot/i18n/locales/ar-AE.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'مجموعة' whatsapp.contact.channel.suffix: 'قناة' +whatsapp.contact.broadcast.suffix: 'قائمة البث' # Aka Stories whatsapp.contact.status.name: 'الحالة' diff --git a/src/apps/chatwoot/i18n/locales/bn-BD.yaml b/src/apps/chatwoot/i18n/locales/bn-BD.yaml index 65747a4f..264cf6c1 100644 --- a/src/apps/chatwoot/i18n/locales/bn-BD.yaml +++ b/src/apps/chatwoot/i18n/locales/bn-BD.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'গ্রুপ' whatsapp.contact.channel.suffix: 'চ্যানেল' +whatsapp.contact.broadcast.suffix: 'প্রচার তালিকা' # Aka Stories whatsapp.contact.status.name: 'স্ট্যাটাস' diff --git a/src/apps/chatwoot/i18n/locales/de-DE.yaml b/src/apps/chatwoot/i18n/locales/de-DE.yaml index d7445451..7292a7ca 100644 --- a/src/apps/chatwoot/i18n/locales/de-DE.yaml +++ b/src/apps/chatwoot/i18n/locales/de-DE.yaml @@ -64,6 +64,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Gruppe' whatsapp.contact.channel.suffix: 'Kanal' +whatsapp.contact.broadcast.suffix: 'Broadcast-Liste' # Aka Stories whatsapp.contact.status.name: 'Status' diff --git a/src/apps/chatwoot/i18n/locales/en-US.yaml b/src/apps/chatwoot/i18n/locales/en-US.yaml index 273c9d86..8edc6117 100644 --- a/src/apps/chatwoot/i18n/locales/en-US.yaml +++ b/src/apps/chatwoot/i18n/locales/en-US.yaml @@ -62,6 +62,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Group' whatsapp.contact.channel.suffix: 'Channel' +whatsapp.contact.broadcast.suffix: 'Broadcast List' # Aka Stories whatsapp.contact.status.name: 'Status' diff --git a/src/apps/chatwoot/i18n/locales/es-ES.yaml b/src/apps/chatwoot/i18n/locales/es-ES.yaml index f51e65c4..8352d562 100644 --- a/src/apps/chatwoot/i18n/locales/es-ES.yaml +++ b/src/apps/chatwoot/i18n/locales/es-ES.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Grupo' whatsapp.contact.channel.suffix: 'Canal' +whatsapp.contact.broadcast.suffix: 'Lista de difusión' # Aka Stories whatsapp.contact.status.name: 'Estado' diff --git a/src/apps/chatwoot/i18n/locales/fa-IR.yaml b/src/apps/chatwoot/i18n/locales/fa-IR.yaml index c85699a0..a9fecc8c 100644 --- a/src/apps/chatwoot/i18n/locales/fa-IR.yaml +++ b/src/apps/chatwoot/i18n/locales/fa-IR.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'گروه' whatsapp.contact.channel.suffix: 'کانال' +whatsapp.contact.broadcast.suffix: 'فهرست انتشار' # Aka Stories whatsapp.contact.status.name: 'وضعیت' diff --git a/src/apps/chatwoot/i18n/locales/fr-FR.yaml b/src/apps/chatwoot/i18n/locales/fr-FR.yaml index 2f2c21b8..1ee8e591 100644 --- a/src/apps/chatwoot/i18n/locales/fr-FR.yaml +++ b/src/apps/chatwoot/i18n/locales/fr-FR.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Groupe' whatsapp.contact.channel.suffix: 'Canal' +whatsapp.contact.broadcast.suffix: 'Liste de diffusion' # Aka Stories whatsapp.contact.status.name: 'Statut' diff --git a/src/apps/chatwoot/i18n/locales/he-IL.yaml b/src/apps/chatwoot/i18n/locales/he-IL.yaml index 7006f1ac..ce4c76e8 100644 --- a/src/apps/chatwoot/i18n/locales/he-IL.yaml +++ b/src/apps/chatwoot/i18n/locales/he-IL.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'קבוצה' whatsapp.contact.channel.suffix: 'ערוץ' +whatsapp.contact.broadcast.suffix: 'רשימת שידור' # Aka Stories whatsapp.contact.status.name: 'סטטוס' diff --git a/src/apps/chatwoot/i18n/locales/hi-IN.yaml b/src/apps/chatwoot/i18n/locales/hi-IN.yaml index 78122c87..3e07376f 100644 --- a/src/apps/chatwoot/i18n/locales/hi-IN.yaml +++ b/src/apps/chatwoot/i18n/locales/hi-IN.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'समूह' whatsapp.contact.channel.suffix: 'चैनल' +whatsapp.contact.broadcast.suffix: 'प्रसारण सूची' # Aka Stories whatsapp.contact.status.name: 'स्थिति' diff --git a/src/apps/chatwoot/i18n/locales/id-ID.yaml b/src/apps/chatwoot/i18n/locales/id-ID.yaml index 3038758f..ec270cbd 100644 --- a/src/apps/chatwoot/i18n/locales/id-ID.yaml +++ b/src/apps/chatwoot/i18n/locales/id-ID.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Grup' whatsapp.contact.channel.suffix: 'Saluran' +whatsapp.contact.broadcast.suffix: 'Daftar Siaran' # Aka Stories whatsapp.contact.status.name: 'Status' diff --git a/src/apps/chatwoot/i18n/locales/pa-PK.yaml b/src/apps/chatwoot/i18n/locales/pa-PK.yaml index 4c6696d0..5d977d06 100644 --- a/src/apps/chatwoot/i18n/locales/pa-PK.yaml +++ b/src/apps/chatwoot/i18n/locales/pa-PK.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'ਗਰੁੱਪ' whatsapp.contact.channel.suffix: 'ਚੈਨਲ' +whatsapp.contact.broadcast.suffix: 'ਪ੍ਰਸਾਰਣ ਸੂਚੀ' # Aka Stories whatsapp.contact.status.name: 'ਸਥਿਤੀ' diff --git a/src/apps/chatwoot/i18n/locales/pt-BR.yaml b/src/apps/chatwoot/i18n/locales/pt-BR.yaml index c968538e..e47faa68 100644 --- a/src/apps/chatwoot/i18n/locales/pt-BR.yaml +++ b/src/apps/chatwoot/i18n/locales/pt-BR.yaml @@ -64,6 +64,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Grupo' whatsapp.contact.channel.suffix: 'Canal' +whatsapp.contact.broadcast.suffix: 'Lista de transmissão' # Aka Stories whatsapp.contact.status.name: 'Status' diff --git a/src/apps/chatwoot/i18n/locales/ru-RU.yaml b/src/apps/chatwoot/i18n/locales/ru-RU.yaml index 9232e99c..d10357ed 100644 --- a/src/apps/chatwoot/i18n/locales/ru-RU.yaml +++ b/src/apps/chatwoot/i18n/locales/ru-RU.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Группа' whatsapp.contact.channel.suffix: 'Канал' +whatsapp.contact.broadcast.suffix: 'Список рассылки' # Aka Stories whatsapp.contact.status.name: 'Статус' diff --git a/src/apps/chatwoot/i18n/locales/tr-TR.yaml b/src/apps/chatwoot/i18n/locales/tr-TR.yaml index 78628476..b63f5d81 100644 --- a/src/apps/chatwoot/i18n/locales/tr-TR.yaml +++ b/src/apps/chatwoot/i18n/locales/tr-TR.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Grup' whatsapp.contact.channel.suffix: 'Kanal' +whatsapp.contact.broadcast.suffix: 'Yayın Listesi' # Aka Stories whatsapp.contact.status.name: 'Durum' diff --git a/src/apps/chatwoot/i18n/locales/uk-UA.yaml b/src/apps/chatwoot/i18n/locales/uk-UA.yaml index 085c35c1..2d45d5d2 100644 --- a/src/apps/chatwoot/i18n/locales/uk-UA.yaml +++ b/src/apps/chatwoot/i18n/locales/uk-UA.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'Група' whatsapp.contact.channel.suffix: 'Канал' +whatsapp.contact.broadcast.suffix: 'Список розсилки' # Aka Stories whatsapp.contact.status.name: 'Статус' diff --git a/src/apps/chatwoot/i18n/locales/ur-PK.yaml b/src/apps/chatwoot/i18n/locales/ur-PK.yaml index 6d4fbd28..ee496da0 100644 --- a/src/apps/chatwoot/i18n/locales/ur-PK.yaml +++ b/src/apps/chatwoot/i18n/locales/ur-PK.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: 'گروپ' whatsapp.contact.channel.suffix: 'چینل' +whatsapp.contact.broadcast.suffix: 'براڈکاسٹ فہرست' # Aka Stories whatsapp.contact.status.name: 'سٹیٹس' diff --git a/src/apps/chatwoot/i18n/locales/zh-CN.yaml b/src/apps/chatwoot/i18n/locales/zh-CN.yaml index b447df3a..93e43ca8 100644 --- a/src/apps/chatwoot/i18n/locales/zh-CN.yaml +++ b/src/apps/chatwoot/i18n/locales/zh-CN.yaml @@ -61,6 +61,7 @@ whatsapp.reaction.removed: | whatsapp.contact.group.suffix: '群组' whatsapp.contact.channel.suffix: '频道' +whatsapp.contact.broadcast.suffix: '广播列表' # Aka Stories whatsapp.contact.status.name: '状态' diff --git a/src/apps/chatwoot/i18n/templates.ts b/src/apps/chatwoot/i18n/templates.ts index 5a8800a6..19c2c6ae 100644 --- a/src/apps/chatwoot/i18n/templates.ts +++ b/src/apps/chatwoot/i18n/templates.ts @@ -36,6 +36,7 @@ export enum TKey { // WHATSAPP_CONTACT_GROUP_SUFFIX = 'whatsapp.contact.group.suffix', WHATSAPP_CONTACT_CHANNEL_SUFFIX = 'whatsapp.contact.channel.suffix', + WHATSAPP_CONTACT_BROADCAST_SUFFIX = 'whatsapp.contact.broadcast.suffix', WHATSAPP_CONTACT_STATUS_NAME = 'whatsapp.contact.status.name', // @@ -114,6 +115,7 @@ export type TemplatePayloads = { [TKey.WHATSAPP_MESSAGE_REMOVING_ERROR]: void; [TKey.WHATSAPP_CONTACT_GROUP_SUFFIX]: void; [TKey.WHATSAPP_CONTACT_CHANNEL_SUFFIX]: void; + [TKey.WHATSAPP_CONTACT_BROADCAST_SUFFIX]: void; [TKey.WHATSAPP_CONTACT_STATUS_NAME]: void; [TKey.CW_TO_WA_MESSAGE_TEXT]: { content: string; diff --git a/src/core/engines/gows/session.gows.core.ts b/src/core/engines/gows/session.gows.core.ts index 57bb333c..f69ec3ce 100644 --- a/src/core/engines/gows/session.gows.core.ts +++ b/src/core/engines/gows/session.gows.core.ts @@ -1914,7 +1914,12 @@ export class WhatsappSessionGoWSCore extends WhatsappSession { if (message.Message.protocolMessage) return; const normalizedContent = normalizeMessageContent(message.Message); - const hasSomeContent = !!getContentType(normalizedContent); + const contentType = getContentType(normalizedContent); + // Ignore device sent message + if (contentType == 'deviceSentMessage') { + return; + } + const hasSomeContent = !!contentType; if (!hasSomeContent) { // Ignore key distribution messages if (message?.Message?.senderKeyDistributionMessage) return; diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index bc68688d..3212b98a 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -2211,7 +2211,12 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { return; const normalizedContent = normalizeMessageContent(message.message); - const hasSomeContent = !!getContentType(normalizedContent); + const contentType = getContentType(normalizedContent); + // Ignore device sent message + if (contentType == 'deviceSentMessage') { + return; + } + const hasSomeContent = !!contentType; if (!hasSomeContent) { // Ignore key distribution messages if (message?.message?.senderKeyDistributionMessage) return;