omnichannel-backend/src/modules/whatsapp/whatsapp.controller.ts

97 lines
3.5 KiB
TypeScript
Raw Normal View History

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')
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);
}
@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);
}
@Post('assign')
async assignChat(@Body() body: { chatId: string; userId: string; areaId?: string }) {
return this.assignmentService.assignChat(body.chatId, body.userId, body.areaId);
}
@Post('transfer')
async transferChat(@Body() body: { chatId: string; areaId: number; userId?: number | null; note?: string | null }) {
return this.assignmentService.transferChat(body);
}
@Delete('release/:chatId')
async releaseChat(@Param('chatId') chatId: string) {
return this.assignmentService.releaseChat(chatId);
}
@Post('close')
async closeChat(@Body() body: { chatId: string; userId?: string | number | null }) {
return this.assignmentService.closeChat(body.chatId, body.userId);
}
@Get('assignment/:chatId')
async getAssignment(@Param('chatId') chatId: string) {
return this.assignmentService.getAssignment(chatId);
}
@Get('templates')
async getTemplates() {
return this.whatsappService.getTemplates();
}
@Post('templates')
async saveTemplate(@Body() body: { name: string; content: string; areaId?: number | null; requestedByRole?: string; category?: string }) {
return this.whatsappService.saveTemplate(body.name, body.content, body.areaId, body.requestedByRole, body.category);
}
@Post('templates/update/:id')
async updateTemplate(@Param('id') id: string, @Body() body: { name: string; content: string; areaId?: number | null; category?: string }) {
return this.whatsappService.updateTemplate(Number(id), body.name, body.content, body.areaId, body.category);
2026-05-22 10:51:44 -03:00
}
@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));
}
}