Spaces:
Sleeping
Sleeping
Download src/modules/contact/contact.controller.ts from jinksQspider/openWa: direct link, hf CLI and curl.
- Browser
- Download file 4.67 kB
-
https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/contact/contact.controller.ts
- Command line
-
hf download hf://spaces/jinksQspider/openWa/src/modules/contact/contact.controller.ts
-
curl -L -o contact.controller.ts https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/contact/contact.controller.ts
4.67 kB
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Delete, | |
| Param, | |
| HttpCode, | |
| HttpStatus, | |
| BadRequestException, | |
| NotFoundException, | |
| } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger'; | |
| import { SessionService } from '../session/session.service'; | |
| ('contacts') | |
| ('sessions/:sessionId/contacts') | |
| export class ContactController { | |
| constructor(private readonly sessionService: SessionService) {} | |
| () | |
| ({ summary: 'Get all contacts for a session' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ | |
| status: 200, | |
| description: 'List of contacts', | |
| }) | |
| ({ status: 400, description: 'Session not ready' }) | |
| ({ status: 404, description: 'Session not found' }) | |
| async findAll(('sessionId') sessionId: string) { | |
| const engine = this.sessionService.getEngine(sessionId); | |
| if (!engine) { | |
| throw new BadRequestException('Session is not started'); | |
| } | |
| return engine.getContacts(); | |
| } | |
| (':contactId') | |
| ({ summary: 'Get a specific contact by ID' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'contactId', description: 'Contact ID (e.g., 628xxx@c.us)' }) | |
| ({ | |
| status: 200, | |
| description: 'Contact details', | |
| }) | |
| ({ status: 404, description: 'Contact not found' }) | |
| async findOne(('sessionId') sessionId: string, ('contactId') contactId: string) { | |
| const engine = this.sessionService.getEngine(sessionId); | |
| if (!engine) { | |
| throw new BadRequestException('Session is not started'); | |
| } | |
| const contact = await engine.getContactById(contactId); | |
| if (!contact) { | |
| throw new NotFoundException(`Contact ${contactId} not found`); | |
| } | |
| return contact; | |
| } | |
| ('check/:number') | |
| ({ summary: 'Check if a phone number exists on WhatsApp' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'number', description: 'Phone number to check (e.g., 628123456789)' }) | |
| ({ | |
| status: 200, | |
| description: 'Number existence check result', | |
| }) | |
| async checkNumber(('sessionId') sessionId: string, ('number') number: string) { | |
| const engine = this.sessionService.getEngine(sessionId); | |
| if (!engine) { | |
| throw new BadRequestException('Session is not started'); | |
| } | |
| const exists = await engine.checkNumberExists(number); | |
| return { | |
| number, | |
| exists, | |
| whatsappId: exists ? `${number}@c.us` : null, | |
| }; | |
| } | |
| // ========== Gap Quick Wins: Profile Picture, Block/Unblock ========== | |
| (':contactId/profile-picture') | |
| ({ summary: 'Get profile picture URL for a contact' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'contactId', description: 'Contact ID (e.g., 628xxx@c.us)' }) | |
| ({ | |
| status: 200, | |
| description: 'Profile picture URL', | |
| }) | |
| async getProfilePicture(('sessionId') sessionId: string, ('contactId') contactId: string) { | |
| const engine = this.sessionService.getEngine(sessionId); | |
| if (!engine) { | |
| throw new BadRequestException('Session is not started'); | |
| } | |
| const url = await engine.getProfilePicture(contactId); | |
| return { url }; | |
| } | |
| (':contactId/block') | |
| (HttpStatus.OK) | |
| ({ summary: 'Block a contact' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'contactId', description: 'Contact ID (e.g., 628xxx@c.us)' }) | |
| ({ | |
| status: 200, | |
| description: 'Contact blocked', | |
| }) | |
| async blockContact(('sessionId') sessionId: string, ('contactId') contactId: string) { | |
| const engine = this.sessionService.getEngine(sessionId); | |
| if (!engine) { | |
| throw new BadRequestException('Session is not started'); | |
| } | |
| await engine.blockContact(contactId); | |
| return { success: true, message: 'Contact blocked' }; | |
| } | |
| (':contactId/block') | |
| ({ summary: 'Unblock a contact' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'contactId', description: 'Contact ID (e.g., 628xxx@c.us)' }) | |
| ({ | |
| status: 200, | |
| description: 'Contact unblocked', | |
| }) | |
| async unblockContact(('sessionId') sessionId: string, ('contactId') contactId: string) { | |
| const engine = this.sessionService.getEngine(sessionId); | |
| if (!engine) { | |
| throw new BadRequestException('Session is not started'); | |
| } | |
| await engine.unblockContact(contactId); | |
| return { success: true, message: 'Contact unblocked' }; | |
| } | |
| } | |