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

52 lines
1.6 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; media?: { data: string; mimetype: string; filename?: string } }) {
return this.whatsappService.sendMessage(body.to, body.message, body.media);
}
@Post('assign')
async assignChat(@Body() body: { chatId: string; userId: string; areaId?: string }) {
return this.assignmentService.assignChat(body.chatId, body.userId, body.areaId);
}
@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);
}
}