feat: Implement real-time message delivery for conversations via WebSocket integration and update admin seed email.
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
ApiParam,
|
||||
} from '@nestjs/swagger';
|
||||
import { MessagesService } from './messages.service';
|
||||
import { MessagesGateway } from './messages.gateway';
|
||||
import { CreateMessageDto, StartConversationDto } from './dto';
|
||||
import { JwtAuthGuard } from '../auth/guards';
|
||||
import { CurrentUser } from '../auth/decorators';
|
||||
@@ -30,7 +31,10 @@ import { UserRole } from '@prisma/client';
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth('JWT-auth')
|
||||
export class MessagesController {
|
||||
constructor(private readonly messagesService: MessagesService) {}
|
||||
constructor(
|
||||
private readonly messagesService: MessagesService,
|
||||
private readonly messagesGateway: MessagesGateway,
|
||||
) {}
|
||||
|
||||
// ==========================================
|
||||
// GET CONVERSATIONS LIST
|
||||
@@ -177,7 +181,23 @@ export class MessagesController {
|
||||
@CurrentUser('id') userId: string,
|
||||
@Body() dto: CreateMessageDto,
|
||||
) {
|
||||
return this.messagesService.createMessage(conversationId, userId, dto);
|
||||
const message = await this.messagesService.createMessage(conversationId, userId, dto);
|
||||
|
||||
// Broadcast via WebSocket so the other party gets real-time delivery
|
||||
try {
|
||||
const participants = await this.messagesService.getConversationParticipants(conversationId);
|
||||
if (participants) {
|
||||
const otherUserId = userId === participants.userId
|
||||
? participants.agentUserId
|
||||
: participants.userId;
|
||||
// Send to the other participant's socket(s)
|
||||
this.messagesGateway.sendToUser(otherUserId, 'new_message', message);
|
||||
}
|
||||
} catch {
|
||||
// Socket broadcast failure shouldn't fail the REST response
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
|
||||
Reference in New Issue
Block a user