Skip to content

Commit

Permalink
fix: Fixed sendGroupInviteMessage by generated invite code (close wpp…
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Aug 26, 2024
1 parent f0a23ce commit 3a713f1
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions src/chat/functions/sendGroupInviteMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ export interface GroupInviteMessage extends SendMessageOptions {
* groupId: '789@g.us'
* }
* );
*
* // After a invite
* const result = await WPP.group.addParticipants('[email protected]', '[email protected]');
* const participant = result['[email protected]'];
* if (participant.invite_code) {
* WPP.chat.sendGroupInviteMessage(
* '123@c.us',
* {
* inviteCode: participant.invite_code,
* inviteCodeExpiration: participant.invite_code_exp,
* groupId: '789@g.us'
* }
* );
* }
* ```
*
* @category Message
Expand Down Expand Up @@ -75,21 +89,34 @@ export async function sendGroupInviteMessage(
}
}
const inviteLink = `https://chat.whatsapp.com/${options.inviteCode}`;
const rawMessage: RawMessage = {
type: 'chat',
subtype: 'url',
thumbnail: options.jpegThumbnail,
thumbnailHeight: options.jpegThumbnail ? 100 : undefined,
thumbnailWidth: options.jpegThumbnail ? 100 : undefined,
title: options.groupName,
inviteGrpType: 'DEFAULT',
canonicalUrl: `https://chat.whatsapp.com/${options.inviteCode}`,
description: options.caption
? `${options.caption}\n${inviteLink}`
: inviteLink,
body: options.caption ? `${options.caption}\n${inviteLink}` : inviteLink,
matchedText: `https://chat.whatsapp.com/${options.inviteCode}`,
richPreviewType: 0,
} as any;
let rawMessage: RawMessage = {};
if (options.inviteCodeExpiration) {
rawMessage = {
type: 'groups_v4_invite',
inviteGrpJpegThum: options.jpegThumbnail,
inviteCode: options.inviteCode,
inviteCodeExp: options.inviteCodeExpiration || '',
inviteGrp: options.groupId,
inviteGrpName: options.groupName,
comment: options.caption,
};
} else {
rawMessage = {
type: 'chat',
subtype: 'url',
thumbnail: options.jpegThumbnail,
thumbnailHeight: options.jpegThumbnail ? 100 : undefined,
thumbnailWidth: options.jpegThumbnail ? 100 : undefined,
title: options.groupName,
inviteGrpType: 'DEFAULT',
canonicalUrl: `https://chat.whatsapp.com/${options.inviteCode}`,
description: options.caption
? `${options.caption}\n${inviteLink}`
: inviteLink,
body: options.caption ? `${options.caption}\n${inviteLink}` : inviteLink,
matchedText: `https://chat.whatsapp.com/${options.inviteCode}`,
richPreviewType: 0,
} as any;
}
return await sendRawMessage(chatId, rawMessage, options);
}

0 comments on commit 3a713f1

Please sign in to comment.