From 31bdbb5ea4aa94183b03ab0f636700d0f677aa08 Mon Sep 17 00:00:00 2001 From: MARCELO DOS SANTOS DE OLIVEIRA <69150213+marcelo386@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:15:48 -0300 Subject: [PATCH] feat: Added WPP.newsletter.getSubscribers function (#1861) (close #1746) --- src/newsletter/functions/getSubscribers.ts | 41 ++++++++++++++++ src/newsletter/functions/index.ts | 1 + .../functions/getNewsletterSubscribers.ts | 49 +++++++++++++++++++ src/whatsapp/functions/index.ts | 1 + 4 files changed, 92 insertions(+) create mode 100644 src/newsletter/functions/getSubscribers.ts create mode 100644 src/whatsapp/functions/getNewsletterSubscribers.ts diff --git a/src/newsletter/functions/getSubscribers.ts b/src/newsletter/functions/getSubscribers.ts new file mode 100644 index 0000000000..1e8eae682f --- /dev/null +++ b/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 { + 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; + } +} diff --git a/src/newsletter/functions/index.ts b/src/newsletter/functions/index.ts index dd48ce6cf0..34cf289326 100644 --- a/src/newsletter/functions/index.ts +++ b/src/newsletter/functions/index.ts @@ -17,4 +17,5 @@ export { create } from './create'; export { destroy } from './destroy'; export { edit } from './edit'; +export { getSubscribers } from './getSubscribers'; export { mute } from './mute'; diff --git a/src/whatsapp/functions/getNewsletterSubscribers.ts b/src/whatsapp/functions/getNewsletterSubscribers.ts new file mode 100644 index 0000000000..2c551e6591 --- /dev/null +++ b/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 +); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index e5267d03c2..741d33f02d 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -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';