From 8afe59ee0d9e14e870cafd93eb090d9173003227 Mon Sep 17 00:00:00 2001 From: binsarjr Date: Fri, 16 Aug 2024 15:13:44 +0700 Subject: [PATCH] feat: extract participant --- .../src/group/extract-phoneNumber.action.ts | 31 +++++++++++++++++++ .../src/whatsapp-action.module.ts | 3 ++ 2 files changed, 34 insertions(+) create mode 100644 libs/whatsapp-action/src/group/extract-phoneNumber.action.ts diff --git a/libs/whatsapp-action/src/group/extract-phoneNumber.action.ts b/libs/whatsapp-action/src/group/extract-phoneNumber.action.ts new file mode 100644 index 0000000..85447c4 --- /dev/null +++ b/libs/whatsapp-action/src/group/extract-phoneNumber.action.ts @@ -0,0 +1,31 @@ +import { IsEligible } from '@app/whatsapp/decorators/is-eligible.decorator'; +import { WhatsappMessage } from '@app/whatsapp/decorators/whatsapp-message.decorator'; +import { WhatsappGroupAction } from '@app/whatsapp/interfaces/whatsapp.group.interface'; +import { withSign } from '@app/whatsapp/supports/flag.support'; +import { WAMessage, WASocket, jidDecode } from '@whiskeysockets/baileys'; + +@WhatsappMessage({ + flags: [withSign('phoneNumberList')], +}) +export class ExtractPhoneNumber extends WhatsappGroupAction { + @IsEligible() + async onlyMe(socket: WASocket, message: WAMessage) { + return !!message.key.fromMe; + } + + async execute(socket: WASocket, message: WAMessage) { + const metadata = await socket.groupMetadata(message.key.remoteJid); + const participants = metadata.participants; + const phones = participants.map( + (participant) => jidDecode(participant.id).user, + ); + + await socket.sendMessage( + message.key.remoteJid, + { + text: phones.join('\n'), + }, + { quoted: message }, + ); + } +} diff --git a/libs/whatsapp-action/src/whatsapp-action.module.ts b/libs/whatsapp-action/src/whatsapp-action.module.ts index 5e11841..23bf279 100644 --- a/libs/whatsapp-action/src/whatsapp-action.module.ts +++ b/libs/whatsapp-action/src/whatsapp-action.module.ts @@ -23,6 +23,7 @@ import { GeminiToolsModule } from '@app/gemini-tools'; import { AiLearnGeminiAction } from './ai/ai-learn-gemini.action'; import { TiktokDownloaderAction } from './downloader/tiktok-downloader.action'; import { InstagramDownloaderAction } from './downloader/instagram-downloader.action'; +import { ExtractPhoneNumber } from './group/extract-phoneNumber.action'; @Module({ providers: [ @@ -41,6 +42,8 @@ import { InstagramDownloaderAction } from './downloader/instagram-downloader.act PromoteMemberAction, DemoteMemberAction, + ExtractPhoneNumber, + AntiViewOnceAction, SaveMessageAction, AntiDeletedMessageAction,