forked from wppconnect-team/wa-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed sendGroupInviteMessage by generated invite code (close wpp…
- Loading branch information
1 parent
f0a23ce
commit 3a713f1
Showing
1 changed file
with
43 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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); | ||
} |