Skip to content

Commit

Permalink
feat: extract participant
Browse files Browse the repository at this point in the history
  • Loading branch information
binsarjr committed Aug 16, 2024
1 parent e059401 commit 8afe59e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions libs/whatsapp-action/src/group/extract-phoneNumber.action.ts
Original file line number Diff line number Diff line change
@@ -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 },
);
}
}
3 changes: 3 additions & 0 deletions libs/whatsapp-action/src/whatsapp-action.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -41,6 +42,8 @@ import { InstagramDownloaderAction } from './downloader/instagram-downloader.act
PromoteMemberAction,
DemoteMemberAction,

ExtractPhoneNumber,

AntiViewOnceAction,
SaveMessageAction,
AntiDeletedMessageAction,
Expand Down

0 comments on commit 8afe59e

Please sign in to comment.