2026-05-18 11:14:17 -03:00
|
|
|
import { Controller, Get, Post, Body, Delete, Param } from '@nestjs/common';
|
|
|
|
|
import { WhatsappService } from './whatsapp.service';
|
|
|
|
|
import { WhatsappAssignmentService } from './whatsapp-assignment.service';
|
|
|
|
|
|
|
|
|
|
@Controller('whatsapp')
|
|
|
|
|
export class WhatsappController {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly whatsappService: WhatsappService,
|
|
|
|
|
private readonly assignmentService: WhatsappAssignmentService
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
@Get('status')
|
|
|
|
|
getStatus() {
|
|
|
|
|
return { status: this.whatsappService.getStatus() };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('chats')
|
|
|
|
|
async getChats() {
|
|
|
|
|
return this.whatsappService.getChats();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('messages/:chatId')
|
|
|
|
|
async getChatMessages(@Param('chatId') chatId: string) {
|
|
|
|
|
return this.whatsappService.getChatMessages(chatId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('media/:chatId/:messageId')
|
|
|
|
|
async getMessageMedia(@Param('chatId') chatId: string, @Param('messageId') messageId: string) {
|
|
|
|
|
return this.whatsappService.getMessageMedia(chatId, messageId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('send')
|
2026-05-19 15:28:23 -03:00
|
|
|
async sendMessage(@Body() body: { to: string; message: string; senderName?: string; media?: { data: string; mimetype: string; filename?: string } }) {
|
|
|
|
|
return this.whatsappService.sendMessage(body.to, body.message, body.media, body.senderName);
|
2026-05-18 11:14:17 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-20 13:56:23 -03:00
|
|
|
@Post('start-attendance')
|
|
|
|
|
async startAttendance(@Body() body: { to: string; templateId: number; userId: number; areaId?: number | null; variables?: Record<string, string | null | undefined> }) {
|
|
|
|
|
return this.whatsappService.startAttendance(body.to, body.templateId, body.userId, body.areaId, body.variables);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 11:14:17 -03:00
|
|
|
@Post('assign')
|
|
|
|
|
async assignChat(@Body() body: { chatId: string; userId: string; areaId?: string }) {
|
|
|
|
|
return this.assignmentService.assignChat(body.chatId, body.userId, body.areaId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-19 15:28:23 -03:00
|
|
|
@Post('transfer')
|
|
|
|
|
async transferChat(@Body() body: { chatId: string; areaId: number; userId?: number | null; note?: string | null }) {
|
|
|
|
|
return this.assignmentService.transferChat(body);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 11:14:17 -03:00
|
|
|
@Delete('release/:chatId')
|
|
|
|
|
async releaseChat(@Param('chatId') chatId: string) {
|
|
|
|
|
return this.assignmentService.releaseChat(chatId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('assignment/:chatId')
|
|
|
|
|
async getAssignment(@Param('chatId') chatId: string) {
|
|
|
|
|
return this.assignmentService.getAssignment(chatId);
|
|
|
|
|
}
|
2026-05-18 13:28:17 -03:00
|
|
|
|
|
|
|
|
@Get('templates')
|
|
|
|
|
async getTemplates() {
|
|
|
|
|
return this.whatsappService.getTemplates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('templates')
|
2026-05-22 10:51:44 -03:00
|
|
|
async saveTemplate(@Body() body: { name: string; content: string; areaId?: number | null; requestedByRole?: string }) {
|
|
|
|
|
return this.whatsappService.saveTemplate(body.name, body.content, body.areaId, body.requestedByRole);
|
2026-05-18 13:28:17 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('templates/update/:id')
|
2026-05-22 10:51:44 -03:00
|
|
|
async updateTemplate(@Param('id') id: string, @Body() body: { name: string; content: string; areaId?: number | null }) {
|
|
|
|
|
return this.whatsappService.updateTemplate(Number(id), body.name, body.content, body.areaId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('templates/approve-admin/:id')
|
|
|
|
|
async approveTemplateByAdmin(@Param('id') id: string) {
|
|
|
|
|
return this.whatsappService.approveTemplateByAdmin(Number(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('templates/reject-admin/:id')
|
|
|
|
|
async rejectTemplateByAdmin(@Param('id') id: string) {
|
|
|
|
|
return this.whatsappService.rejectTemplateByAdmin(Number(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete('templates/:id')
|
|
|
|
|
async deleteTemplate(@Param('id') id: string) {
|
|
|
|
|
return this.whatsappService.deleteTemplate(Number(id));
|
2026-05-18 13:28:17 -03:00
|
|
|
}
|
2026-05-18 11:14:17 -03:00
|
|
|
}
|