Skip to content

Commit

Permalink
fix: Fixed send message to community groups when is no announce group
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Oct 27, 2024
1 parent 2ccf181 commit 10f29ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/chat/functions/sendRawMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/whatsapp/models/ChatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ interface Derived {
isUser: boolean;
isPSA: boolean;
isGroup: boolean;
isParentGroup: boolean;
isBroadcast: boolean;
isNewsletter: boolean;
canUnread: boolean;
Expand Down

0 comments on commit 10f29ee

Please sign in to comment.