Spaces:
Runtime error
Runtime error
| import { Controller, Get, Post, Delete, Param, Body } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; | |
| import { StatusService } from './status.service'; | |
| import { SendTextStatusDto } from './dto/send-text-status.dto'; | |
| import { SendImageStatusDto, SendVideoStatusDto } from './dto/send-media-status.dto'; | |
| import { RequireRole } from '../auth/decorators/auth.decorators'; | |
| import { ApiKeyRole } from '../auth/entities/api-key.entity'; | |
| ('status') | |
| ('sessions/:sessionId/status') | |
| export class StatusController { | |
| constructor(private readonly statusService: StatusService) {} | |
| () | |
| ({ summary: 'Get all contact status updates' }) | |
| ({ status: 200, description: 'Status updates visible to the session, grouped by contact.' }) | |
| async getStatuses(('sessionId') sessionId: string) { | |
| return { statuses: await this.statusService.getStatuses(sessionId) }; | |
| } | |
| (':contactId') | |
| ({ summary: 'Get status updates from a specific contact' }) | |
| ({ status: 200, description: 'Status updates from the requested contact.' }) | |
| async getContactStatus(('sessionId') sessionId: string, ('contactId') contactId: string) { | |
| return { statuses: await this.statusService.getContactStatus(sessionId, contactId) }; | |
| } | |
| ('send-text') | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Post a text status' }) | |
| ({ | |
| status: 201, | |
| description: | |
| 'Text status posted. The recipients allow-list is honored on Baileys only; whatsapp-web.js broadcasts ' + | |
| "to the account's status-privacy audience.", | |
| }) | |
| ({ status: 400, description: 'Invalid request, or the post was blocked by a plugin.' }) | |
| async sendTextStatus(('sessionId') sessionId: string, () dto: SendTextStatusDto) { | |
| return this.statusService.postTextStatus(sessionId, dto.text, { | |
| recipients: dto.recipients, | |
| backgroundColor: dto.backgroundColor, | |
| font: dto.font, | |
| }); | |
| } | |
| ('send-image') | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Post an image status' }) | |
| ({ | |
| status: 201, | |
| description: | |
| 'Image status posted. The recipients allow-list is honored on Baileys only; whatsapp-web.js broadcasts ' + | |
| "to the account's status-privacy audience.", | |
| }) | |
| ({ | |
| status: 400, | |
| description: 'Neither url nor base64 provided, or the post was blocked by a plugin.', | |
| }) | |
| ({ status: 413, description: 'Base64 media exceeds MEDIA_DOWNLOAD_MAX_BYTES.' }) | |
| async sendImageStatus(('sessionId') sessionId: string, () dto: SendImageStatusDto) { | |
| return this.statusService.postImageStatus(sessionId, dto.image, { | |
| recipients: dto.recipients, | |
| caption: dto.caption, | |
| }); | |
| } | |
| ('send-video') | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Post a video status' }) | |
| ({ | |
| status: 201, | |
| description: | |
| 'Video status posted. The recipients allow-list is honored on Baileys only; whatsapp-web.js broadcasts ' + | |
| "to the account's status-privacy audience.", | |
| }) | |
| ({ | |
| status: 400, | |
| description: 'Neither url nor base64 provided, or the post was blocked by a plugin.', | |
| }) | |
| ({ status: 413, description: 'Base64 media exceeds MEDIA_DOWNLOAD_MAX_BYTES.' }) | |
| async sendVideoStatus(('sessionId') sessionId: string, () dto: SendVideoStatusDto) { | |
| return this.statusService.postVideoStatus(sessionId, dto.video, { | |
| recipients: dto.recipients, | |
| caption: dto.caption, | |
| }); | |
| } | |
| (':statusId') | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Delete own status' }) | |
| ({ status: 200, description: 'Status deleted.' }) | |
| async deleteStatus(('sessionId') sessionId: string, ('statusId') statusId: string) { | |
| await this.statusService.deleteStatus(sessionId, statusId); | |
| return { message: 'Status deleted successfully' }; | |
| } | |
| } | |