diff --git a/src/chat/functions/sendRawMessage.ts b/src/chat/functions/sendRawMessage.ts index c41ecb0279..96134a0a16 100644 --- a/src/chat/functions/sendRawMessage.ts +++ b/src/chat/functions/sendRawMessage.ts @@ -17,8 +17,9 @@ import Debug from 'debug'; import { assertFindChat, assertGetChat } from '../../assert'; +import { getAnnouncementGroup } from '../../community'; import { WPPError } from '../../util'; -import { MsgModel } from '../../whatsapp'; +import { GroupMetadataStore, MsgModel } from '../../whatsapp'; import { ACK } from '../../whatsapp/enums'; import { addAndSendMessageEdit, @@ -57,6 +58,21 @@ export async function sendRawMessage( ? await assertFindChat(chatId) : assertGetChat(chatId); + /** + * When the group is groupType 'COMMUNITY', its a instance of a group created, you can + * not send message for this grouptype. You only can send message for linked announcement groups + */ + if (chat.isGroup && chat.isParentGroup) { + const groupData = GroupMetadataStore.get(chat.id?.toString()); + if (groupData?.groupType == 'COMMUNITY') { + const announceGroup = getAnnouncementGroup(groupData.id); + throw new WPPError( + 'can_not_send_message_to_this_groupType', + `You can not send message to this groupType 'COMMUNITY', send for Announcement Group. Correct announcement groupId: ${announceGroup?.toString()}` + ); + } + } + rawMessage = await prepareRawMessage(chat, rawMessage, options); if (options.markIsRead) { diff --git a/src/whatsapp/models/ChatModel.ts b/src/whatsapp/models/ChatModel.ts index df6b38709b..774782f61b 100644 --- a/src/whatsapp/models/ChatModel.ts +++ b/src/whatsapp/models/ChatModel.ts @@ -89,6 +89,7 @@ interface Derived { isUser: boolean; isPSA: boolean; isGroup: boolean; + isParentGroup: boolean; isBroadcast: boolean; isNewsletter: boolean; canUnread: boolean;