Spaces:
Runtime error
Runtime error
| import { | |
| Body, | |
| Controller, | |
| Delete, | |
| Get, | |
| Put, | |
| UnprocessableEntityException, | |
| UsePipes, | |
| } from '@nestjs/common'; | |
| import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger'; | |
| import { SessionManager } from '@waha/core/abc/manager.abc'; | |
| import { WhatsappSession } from '@waha/core/abc/session.abc'; | |
| import { | |
| SessionApiParam, | |
| WorkingSessionParam, | |
| } from '@waha/nestjs/params/SessionApiParam'; | |
| import { WAHAValidationPipe } from '@waha/nestjs/pipes/WAHAValidationPipe'; | |
| import { Result } from '@waha/structures/base.dto'; | |
| import { | |
| MyProfile, | |
| ProfileNameRequest, | |
| ProfilePictureRequest, | |
| ProfileStatusRequest, | |
| } from '@waha/structures/profile.dto'; | |
| ('api_key') | |
| ('api/:session/profile') | |
| ('๐ Profile') | |
| export class ProfileController { | |
| constructor(private manager: SessionManager) {} | |
| ('') | |
| ({ summary: 'Get my profile' }) | |
| async getMyProfile( | |
| session: WhatsappSession, | |
| ): Promise<MyProfile> { | |
| const me = session.getSessionMeInfo(); | |
| if (!me) { | |
| throw new UnprocessableEntityException('No profile found'); | |
| } | |
| const picture = await session.getContactProfilePicture(me.id, false); | |
| return { | |
| id: me.id, | |
| name: me.pushName, | |
| picture: picture || null, | |
| }; | |
| } | |
| ('/name') | |
| (new WAHAValidationPipe()) | |
| ({ summary: 'Set my profile name' }) | |
| async setProfileName( | |
| session: WhatsappSession, | |
| () request: ProfileNameRequest, | |
| ): Promise<Result> { | |
| const success = await session.setProfileName(request.name); | |
| return { success: success ?? true }; | |
| } | |
| ('/status') | |
| (new WAHAValidationPipe()) | |
| ({ summary: 'Set profile status (About)' }) | |
| async setProfileStatus( | |
| session: WhatsappSession, | |
| () request: ProfileStatusRequest, | |
| ): Promise<Result> { | |
| const success = await session.setProfileStatus(request.status); | |
| return { success: success ?? true }; | |
| } | |
| ('/picture') | |
| ({ summary: 'Set profile picture' }) | |
| async setProfilePicture( | |
| session: WhatsappSession, | |
| () request: ProfilePictureRequest, | |
| ): Promise<Result> { | |
| const success = await session.updateProfilePicture(request.file); | |
| return { success: success ?? true }; | |
| } | |
| ('/picture') | |
| ({ summary: 'Delete profile picture' }) | |
| async deleteProfilePicture( | |
| session: WhatsappSession, | |
| ): Promise<Result> { | |
| const success = await session.updateProfilePicture(null); | |
| return { success: success || true }; | |
| } | |
| } | |