Skip to content

Commit

Permalink
feat: Added WPP.group.approve function
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Apr 29, 2023
1 parent 5ef0836 commit 0661f02
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
55 changes: 55 additions & 0 deletions 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()}`
);
}
}
39 changes: 39 additions & 0 deletions 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
);

0 comments on commit 0661f02

Please sign in to comment.