From 687627dfbd28249819fd4d401fee024901f26ae6 Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Sat, 29 Apr 2023 10:50:59 -0300 Subject: [PATCH] feat: Added WPP.group.reject function (close #1058) --- src/group/functions/reject.ts | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/group/functions/reject.ts diff --git a/src/group/functions/reject.ts b/src/group/functions/reject.ts new file mode 100644 index 0000000000..3a641f8f2a --- /dev/null +++ b/src/group/functions/reject.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'; + +/** + * Reject a membership request to group + * + * @example + * ```javascript + * await WPP.group.reject(12345645@g.us, 5554999999999@c.us); + * ``` + * + * @category Group + */ +export async function reject( + 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, 'Reject'); + } catch (error) { + throw new WPPError( + 'error_on_reject_membership_request', + `Error on reject member on group ${groupId.toString()}` + ); + } +}