feat: group membership requests (#2516)
* added event for group membership request * small update to improve the performance of findImpl fix * window.compareWwebVersions fixed * added getGroupMembershipRequests method * added approveGroupMembershipRequest method * correct module for getGroupMembershipRequests * membershipRequestAction separated to Injected.js * docs clarification for approveGroupMembershipRequest * added rejectGroupMembershipRequest method * module fixed * methods extension * docs clarification * force to update group membership requests * docs fixed * added usage example * avoid sleep after the last iteration * fix: added missing modules * improve forcing to update group membership requests * usage example clarification * module refactored * optional parameters * usage example modified * remove default values for membershipRequestAction * added error description for memb req action * usage example fixed * return result even if ServerStatusCodeError * default error message was missing * removed line break
This commit is contained in:
parent
ecf19eb9a5
commit
56320c88f8
6 changed files with 373 additions and 16 deletions
72
example.js
72
example.js
|
|
@ -239,6 +239,52 @@ client.on('message', async msg => {
|
|||
} else if (msg.body === '!removelabels') {
|
||||
const chat = await msg.getChat();
|
||||
await chat.changeLabels([]);
|
||||
} else if (msg.body === '!approverequest') {
|
||||
/**
|
||||
* Presented an example for membership request approvals, the same examples are for the request rejections.
|
||||
* To approve the membership request from a specific user:
|
||||
*/
|
||||
await client.approveGroupMembershipRequests(msg.from, { requesterIds: 'number@c.us' });
|
||||
/** The same for execution on group object (no need to provide the group ID): */
|
||||
const group = await msg.getChat();
|
||||
await group.approveGroupMembershipRequests({ requesterIds: 'number@c.us' });
|
||||
/** To approve several membership requests: */
|
||||
const approval = await client.approveGroupMembershipRequests(msg.from, {
|
||||
requesterIds: ['number1@c.us', 'number2@c.us']
|
||||
});
|
||||
/**
|
||||
* The example of the {@link approval} output:
|
||||
* [
|
||||
* {
|
||||
* requesterId: 'number1@c.us',
|
||||
* message: 'Rejected successfully'
|
||||
* },
|
||||
* {
|
||||
* requesterId: 'number2@c.us',
|
||||
* error: 404,
|
||||
* message: 'ParticipantRequestNotFoundError'
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
*/
|
||||
console.log(approval);
|
||||
/** To approve all the existing membership requests (simply don't provide any user IDs): */
|
||||
await client.approveGroupMembershipRequests(msg.from);
|
||||
/** To change the sleep value to 300 ms: */
|
||||
await client.approveGroupMembershipRequests(msg.from, {
|
||||
requesterIds: ['number1@c.us', 'number2@c.us'],
|
||||
sleep: 300
|
||||
});
|
||||
/** To change the sleep value to random value between 100 and 300 ms: */
|
||||
await client.approveGroupMembershipRequests(msg.from, {
|
||||
requesterIds: ['number1@c.us', 'number2@c.us'],
|
||||
sleep: [100, 300]
|
||||
});
|
||||
/** To explicitly disable the sleep: */
|
||||
await client.approveGroupMembershipRequests(msg.from, {
|
||||
requesterIds: ['number1@c.us', 'number2@c.us'],
|
||||
sleep: null
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -360,3 +406,29 @@ client.on('group_admin_changed', (notification) => {
|
|||
/** Emitted when a current user is demoted to a regular user. */
|
||||
console.log(`You were demoted by ${notification.author}`);
|
||||
});
|
||||
|
||||
client.on('group_membership_request', async (notification) => {
|
||||
/**
|
||||
* The example of the {@link notification} output:
|
||||
* {
|
||||
* id: {
|
||||
* fromMe: false,
|
||||
* remote: 'groupId@g.us',
|
||||
* id: '123123123132132132',
|
||||
* participant: 'number@c.us',
|
||||
* _serialized: 'false_groupId@g.us_123123123132132132_number@c.us'
|
||||
* },
|
||||
* body: '',
|
||||
* type: 'created_membership_requests',
|
||||
* timestamp: 1694456538,
|
||||
* chatId: 'groupId@g.us',
|
||||
* author: 'number@c.us',
|
||||
* recipientIds: []
|
||||
* }
|
||||
*
|
||||
*/
|
||||
console.log(notification);
|
||||
/** You can approve or reject the newly appeared membership request: */
|
||||
await client.approveGroupMembershipRequestss(notification.chatId, notification.author);
|
||||
await client.rejectGroupMembershipRequests(notification.chatId, notification.author);
|
||||
});
|
||||
Loading…
Reference in a new issue