Spaces:
Runtime error
Runtime error
| import { | |
| Body, | |
| Controller, | |
| Get, | |
| Post, | |
| Query, | |
| UsePipes, | |
| ValidationPipe, | |
| } from '@nestjs/common'; | |
| import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger'; | |
| import { SessionManager } from '../core/abc/manager.abc'; | |
| import { SessionQuery } from '../structures/base.dto'; | |
| import { | |
| CheckNumberStatusQuery, | |
| WANumberExistResult, | |
| } from '../structures/chatting.dto'; | |
| import { | |
| ContactProfilePictureQuery, | |
| ContactQuery, | |
| ContactRequest, | |
| ContactsPaginationParams, | |
| } from '../structures/contacts.dto'; | |
| ('api_key') | |
| ('api/contacts') | |
| ('👤 Contacts') | |
| export class ContactsController { | |
| constructor(private manager: SessionManager) {} | |
| ('/all') | |
| ({ summary: 'Get all contacts' }) | |
| (new ValidationPipe({ transform: true, whitelist: true })) | |
| async getAll( | |
| () query: SessionQuery, | |
| () pagination: ContactsPaginationParams, | |
| ) { | |
| const whatsapp = await this.manager.getWorkingSession(query.session); | |
| return whatsapp.getContacts(pagination); | |
| } | |
| ('/') | |
| ({ | |
| summary: 'Get contact basic info', | |
| description: | |
| 'The method always return result, even if the phone number is not registered in WhatsApp. For that - use /contacts/check-exists endpoint below.', | |
| }) | |
| async get(() query: ContactQuery) { | |
| const whatsapp = await this.manager.getWorkingSession(query.session); | |
| return whatsapp.getContact(query); | |
| } | |
| ('/check-exists') | |
| ({ summary: 'Check phone number is registered in WhatsApp.' }) | |
| async checkExists( | |
| () request: CheckNumberStatusQuery, | |
| ): Promise<WANumberExistResult> { | |
| const whatsapp = await this.manager.getWorkingSession(request.session); | |
| return whatsapp.checkNumberStatus(request); | |
| } | |
| ('/about') | |
| ({ | |
| summary: 'Gets the Contact\'s "about" info', | |
| description: | |
| 'Returns null if you do not have permission to read their status.', | |
| }) | |
| async getAbout(() query: ContactQuery) { | |
| const whatsapp = await this.manager.getWorkingSession(query.session); | |
| return whatsapp.getContactAbout(query); | |
| } | |
| ('/profile-picture') | |
| ({ | |
| summary: "Get contact's profile picture URL", | |
| description: | |
| 'If privacy settings do not allow to get the picture, the method will return null.', | |
| }) | |
| (new ValidationPipe({ transform: true, whitelist: true })) | |
| async getProfilePicture(() query: ContactProfilePictureQuery) { | |
| const whatsapp = await this.manager.getWorkingSession(query.session); | |
| const url = await whatsapp.getContactProfilePicture( | |
| query.contactId, | |
| query.refresh, | |
| ); | |
| return { profilePictureURL: url }; | |
| } | |
| ('/block') | |
| ({ summary: 'Block contact' }) | |
| async block(() request: ContactRequest) { | |
| const whatsapp = await this.manager.getWorkingSession(request.session); | |
| return whatsapp.blockContact(request); | |
| } | |
| ('/unblock') | |
| ({ summary: 'Unblock contact' }) | |
| async unblock(() request: ContactRequest) { | |
| const whatsapp = await this.manager.getWorkingSession(request.session); | |
| return whatsapp.unblockContact(request); | |
| } | |
| } | |