From 0661f0290e547d0104b6c062da8d87a41cde4dfa Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Sat, 29 Apr 2023 10:50:32 -0300 Subject: [PATCH] feat: Added WPP.group.approve function --- src/group/functions/approve.ts | 55 +++++++++++++++++++ .../membershipApprovalRequestAction.ts | 39 +++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/group/functions/approve.ts create mode 100644 src/whatsapp/functions/membershipApprovalRequestAction.ts diff --git a/src/group/functions/approve.ts b/src/group/functions/approve.ts new file mode 100644 index 0000000000..2321c062d3 --- /dev/null +++ b/src/group/functions/approve.ts @@ -0,0 +1,55 @@ +/*! + * Copyright 2023 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { assertWid } from '../../assert'; +import { WPPError } from '../../util'; +import { Wid } from '../../whatsapp'; +import { membershipApprovalRequestAction } from '../../whatsapp/functions'; + +/** + * Approve a membership request to group + * + * @example + * ```javascript + * await WPP.group.approve(12345645@g.us, 5554999999999@c.us); + * ``` + * + * @category Group + */ +export async function approve( + groupId: string | Wid, + membershipIds: (string | Wid) | (string | Wid)[] +): Promise< + { + error: any; + wid: Wid; + }[] +> { + groupId = assertWid(groupId); + if (!Array.isArray(membershipIds)) { + membershipIds = [membershipIds]; + } + const wids = membershipIds.map(assertWid); + + try { + return await membershipApprovalRequestAction(groupId, wids, 'Approve'); + } catch (error) { + throw new WPPError( + 'error_on_accept_membership_request', + `Error on accept member on group ${groupId.toString()}` + ); + } +} diff --git a/src/whatsapp/functions/membershipApprovalRequestAction.ts b/src/whatsapp/functions/membershipApprovalRequestAction.ts new file mode 100644 index 0000000000..55d422c93a --- /dev/null +++ b/src/whatsapp/functions/membershipApprovalRequestAction.ts @@ -0,0 +1,39 @@ +/*! + * Copyright 2023 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { exportModule } from '../exportModule'; +import { Wid } from '../misc'; + +/** @whatsapp 290542 + */ +export declare function membershipApprovalRequestAction( + groupId: Wid, + requestedMembersId: Wid[], + type: 'Approve' | 'Reject' +): Promise< + { + error: any; + wid: Wid; + }[] +>; + +exportModule( + exports, + { + membershipApprovalRequestAction: 'membershipApprovalRequestAction', + }, + (m) => m.membershipApprovalRequestAction +);