fix+feat: addParticipants + createGroup (#2344)

* added required modules

* added sendGroupV4Invite implementation

* docs updated accordingly

* bug fixed

* added usage example

* ESLint fix

* extended resulting object

* docs updated accordingly

* added required modules

* updated comments

* bug fixed

* added usage example

* fixed to catch unexpected errors

* removed unnecessary module

* updated usage example

* minor fixes

* changed to return a string if an error is occupied

* fixed usage example

* removed unneccessary module

* added getAddParticipantsRpcResult

* updated addParticipants

- added AddParticipnatsOptions to provide values for sleep, autoSendInviteV4, comment
- combined addParticipants with sendGroupInviteMessage

* removed unneccessary sendGroupV4Invite

* docs updated

* fixed statement fot autoSendInviteV4

* minor fixes

- the returned value of addParticipants is no longer wrapped in an array
- docs updated
- fixed bug with the returned code value when the code is '200'

* added logic of retrieving the group profile picture

this allows to send an invitation with a profile picture thumbnail of the group

* minor fixes

* added fix for the inviteV4 to be sent

* updated usage example

* minor fix

* ESLint fix

* fix for code 419

* function name getProfilePictureThumb changed to be more clear

* refactor: modules moved to window.Store.GroupParticipants

* refactor: edited link of usage examples

* refactor: LidManipulations changed to LidUtils

* refactor: modules regrouping

To keep the modules in order were made some changes:
- JoinInviteV4 renamed to GroupInviteV4 and grouped with module sendGroupInviteMessage
- GroupParticipants grouped with module sendAddParticipantsRPC

* fix: injectToFunction fixed to work properly

* revert docs changes for Chat

* Merge branch 'main' into fix-add-participants

* docs fixed

* minor fix in injectToFunction

* removed data stringifying/parsing

* added random sleep time logic

* code refactoring

* docs updated

* addParticipants method refactored

* createGroup method extended

- added functionality to send private invitations automatically to missing participants
- added ability to provide value for message timer
- added ability to link a group to the community parent group at the stage of creating a group
- extended the returned data after the method call

* docs updated + typo fixed

* added ability to create group with myself only

* example updated

* docs clarified

* small code refactoring

* window.Store.Invite and window.Store.InviteInfo grouped

* window.compareWwebVersions fixed

* small update to improve the performance of findImpl fix

* gid as wid structure

* docs + example updated

* parenthesis

* avoid sleep after the last iteration

* fixed compatibility issue for sendGroupInviteMessage

* fixed issue with stale groupmetadata

in some cases after the participant has left the group, that participant is still stored in groupmetadata

* fixed compatibility issue for sendAddParticipantsRPC

* minor fix

* jsdocs fixed

* fixed issue with group creation

* fixed createGroup method

- added check for unregistered phone number
- extended returning data from method call: added title
- code refactored
- jsdocs fixed

* fixed addParticipants method

- added check for unregistered number
- code refactored

* docs fixed

* usage example fixed

* removed unnecessary method call

* jsdocs fixed

* check for group admin fixed
This commit is contained in:
alechkos 2023-10-11 16:10:26 +03:00 • committed by GitHub
commit c0705a2216
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 508 additions and 82 deletions

View file

@ -91,6 +91,78 @@ client.on('message', async msg => {
} catch (e) {
msg.reply('That invite code seems to be invalid.');
}
} else if (msg.body.startsWith('!addmembers')) {
const group = await msg.getChat();
const result = await group.addParticipants(['number1@c.us', 'number2@c.us', 'number3@c.us']);
/**
* The example of the {@link result} output:
*
* {
* 'number1@c.us': {
* code: 200,
* message: 'The participant was added successfully',
* isInviteV4Sent: false
* },
* 'number2@c.us': {
* code: 403,
* message: 'The participant can be added by sending private invitation only',
* isInviteV4Sent: true
* },
* 'number3@c.us': {
* code: 404,
* message: 'The phone number is not registered on WhatsApp',
* isInviteV4Sent: false
* }
* }
*
* For more usage examples:
* @see https://github.com/pedroslopez/whatsapp-web.js/pull/2344#usage-example1
*/
console.log(result);
} else if (msg.body === '!creategroup') {
const partitipantsToAdd = ['number1@c.us', 'number2@c.us', 'number3@c.us'];
const result = await client.createGroup('Group Title', partitipantsToAdd);
/**
* The example of the {@link result} output:
* {
* title: 'Group Title',
* gid: {
* server: 'g.us',
* user: '1111111111',
* _serialized: '1111111111@g.us'
* },
* participants: {
* 'botNumber@c.us': {
* statusCode: 200,
* message: 'The participant was added successfully',
* isGroupCreator: true,
* isInviteV4Sent: false
* },
* 'number1@c.us': {
* statusCode: 200,
* message: 'The participant was added successfully',
* isGroupCreator: false,
* isInviteV4Sent: false
* },
* 'number2@c.us': {
* statusCode: 403,
* message: 'The participant can be added by sending private invitation only',
* isGroupCreator: false,
* isInviteV4Sent: true
* },
* 'number3@c.us': {
* statusCode: 404,
* message: 'The phone number is not registered on WhatsApp',
* isGroupCreator: false,
* isInviteV4Sent: false
* }
* }
* }
*
* For more usage examples:
* @see https://github.com/pedroslopez/whatsapp-web.js/pull/2344#usage-example2
*/
console.log(result);
} else if (msg.body === '!groupinfo') {
let chat = await msg.getChat();
if (chat.isGroup) {