Skip to content

Commit

Permalink
feat: Added WPP.newsletter.getSubscribers function (#1861) (close #1746)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelo386 committed Apr 25, 2024
1 parent 8ccbf06 commit 31bdbb5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/newsletter/functions/getSubscribers.ts
@@ -0,0 +1,41 @@
/*!
* Copyright 2024 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 { WPPError } from '../../util';
import { getNewsletterSubscribers } from '../../whatsapp/functions';

/**
* Get subscribers of a newsletters
*
* @example
* ```javascript
* const code = WPP.newsletter.getSubscribers('[newsletter-id]@newsletter');
* ```
*
* @category Newsletter
*/
export async function getSubscribers(id: string): Promise<any> {
if (!id || !id.includes('newsletter'))
throw new WPPError(
'send_correctly_newsletter_id',
'Please, send the correct newsletter ID.'
);
try {
return (await getNewsletterSubscribers(id, 9, 'LIMITED')).subscribers;
} catch (error) {
return false;
}
}
1 change: 1 addition & 0 deletions src/newsletter/functions/index.ts
Expand Up @@ -17,4 +17,5 @@
export { create } from './create';
export { destroy } from './destroy';
export { edit } from './edit';
export { getSubscribers } from './getSubscribers';
export { mute } from './mute';
49 changes: 49 additions & 0 deletions src/whatsapp/functions/getNewsletterSubscribers.ts
@@ -0,0 +1,49 @@
/*!
* Copyright 2024 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 276084
*/
export declare function getNewsletterSubscribers(
jid: string,
param2: number,
view: 'LIMITED'
): Promise<{
subscribers: {
id: Wid;
isContact?: boolean;
isGroup?: boolean;
isOnline?: boolean;
isUser?: boolean;
shortname?: string;
state?: string;
displayName?: string;
phoneNumber?: string;
subscribeTime?: number;
t: number;
}[];
}>;

exportModule(
exports,
{
getNewsletterSubscribers: 'getNewsletterSubscribers',
},
(m) => m.getNewsletterSubscribers
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -59,6 +59,7 @@ export * from './getGroupSenderKeyList';
export * from './getGroupSizeLimit';
export * from './getHistorySyncProgress';
export * from './getMembershipApprovalRequests';
export * from './getNewsletterSubscribers';
export * from './getNextLabelId';
export * from './getNumChatsPinned';
export * from './getOrderInfo';
Expand Down

0 comments on commit 31bdbb5

Please sign in to comment.