From 7dc1cd64766b41f4fc9a3210777533e16fede94f Mon Sep 17 00:00:00 2001 From: aqulzz <75623219+zennn08@users.noreply.github.com> Date: Mon, 12 Jun 2023 19:34:50 +0700 Subject: [PATCH] feat: approve, reject, list request join (#117) --- README.md | 15 +++++++++++++++ src/Socket/groups.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/README.md b/README.md index c9aaa34..0268925 100644 --- a/README.md +++ b/README.md @@ -847,6 +847,21 @@ Of course, replace ``` xyz ``` with an actual ID. ``` Of course, replace ``` xxx ``` with invitation code. +- To get list request join + ``` ts + const response = await sock.groupRequestParticipantsList("abcd-xyz@g.us") + console.log(response) + ``` +- To approve/reject request join + ``` ts + const response = await sock.groupRequestParticipantsUpdate( + "abcd-xyz@g.us", // id group, + ["abcd@s.whatsapp.net", "efgh@s.whatsapp.net"], + "approve" // replace this parameter with "reject" + ) + console.log(response) + ``` + ## Privacy - To get the privacy settings ``` ts diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index 7eb5aa7..8a31159 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -130,6 +130,47 @@ export const makeGroupsSocket = (config: SocketConfig) => { ] ) }, + groupRequestParticipantsList: async(jid: string) => { + const result = await groupQuery( + jid, + 'get', + [ + { + tag: 'membership_approval_requests', + attrs: {} + } + ] + ) + const node = getBinaryNodeChild(result, 'membership_approval_requests') + const participants = getBinaryNodeChildren(node, 'membership_approval_request') + return participants.map(v => v.attrs) + }, + groupRequestParticipantsUpdate: async(jid: string, participants: string[], action: 'approve' | 'reject') => { + const result = await groupQuery( + jid, + 'set', + [{ + tag: 'membership_requests_action', + attrs: {}, + content: [ + { + tag: action, + attrs: { }, + content: participants.map(jid => ({ + tag: 'participant', + attrs: { jid } + })) + } + ] + }] + ) + const node = getBinaryNodeChild(result, 'membership_requests_action') + const nodeAction = getBinaryNodeChild(node!, action) + const participantsAffected = getBinaryNodeChildren(nodeAction!, 'participant') + return participantsAffected.map(p => { + return { status: p.attrs.error || '200', jid: p.attrs.jid } + }) + }, groupParticipantsUpdate: async( jid: string, participants: string[],