src/chatbot/chatbot.controller.ts
chat
Methods |
|
| Async askBot | |||||||||
askBot(req, userMessage: UserMessage)
|
|||||||||
Decorators :
@Post('ask')
|
|||||||||
|
Defined in src/chatbot/chatbot.controller.ts:33
|
|||||||||
|
Parameters :
Returns :
unknown
|
| findOne | ||||||
findOne(id: string)
|
||||||
Decorators :
@Get(':id')
|
||||||
|
Defined in src/chatbot/chatbot.controller.ts:70
|
||||||
|
Parameters :
Returns :
Promise<Chat | null>
|
| Async getChatsForUser | |||||||||
getChatsForUser(req, queryOptions: literal type)
|
|||||||||
Decorators :
@Get()
|
|||||||||
|
Defined in src/chatbot/chatbot.controller.ts:76
|
|||||||||
|
Parameters :
Returns :
Promise<Chat[]>
|
| Async getMessagesForChat | |||||||||
getMessagesForChat(chatId: string, queryOptions: literal type)
|
|||||||||
Decorators :
@Get('/:id/messages')
|
|||||||||
|
Defined in src/chatbot/chatbot.controller.ts:40
|
|||||||||
|
Parameters :
Returns :
Promise<Message[]>
|
| Async update | |||||||||
update(id: string, updateChatDto: UpdateChatDto)
|
|||||||||
Decorators :
@Patch(':id')
|
|||||||||
|
Defined in src/chatbot/chatbot.controller.ts:60
|
|||||||||
|
Parameters :
Returns :
Promise<Chat>
|
import {
Body,
Controller,
Get,
Param,
Patch,
Post,
Query,
Request,
UsePipes,
ValidationPipe,
} from "@nestjs/common";
import { ChatBotService } from "./chatbot.service";
import { UserMessage } from "./dto/userMessage.dto";
import { ChatService } from "./chat.service";
import { MessageService } from "./message.service";
import { UpdateChatDto } from "./dto/chat.dto";
import { Chat, ChatStatus } from "./entities/chat.entity";
import { Message } from "./entities/message.entity";
import { ApiBearerAuth, ApiOkResponse } from "@nestjs/swagger";
@ApiBearerAuth("access-token") // adds auth token with request in swagger
@Controller("chat")
export class ChatBotController {
constructor(
private readonly chatBotService: ChatBotService,
private readonly chatService: ChatService,
private readonly messageService: MessageService,
) {}
@Post("ask")
@UsePipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true }))
async askBot(@Request() req, @Body() userMessage: UserMessage) {
const userId = req.user.id;
return await this.chatBotService.ingestUserMessage(userMessage, userId);
}
@Get("/:id/messages")
@ApiOkResponse({ type: [Message] })
async getMessagesForChat(
@Param("id") chatId: string,
@Query()
queryOptions: {
pageSize?: number;
pageOffset?: number;
startId?: number;
},
): Promise<Message[]> {
try {
return await this.chatService.findMessagesForChat(+chatId, queryOptions);
} catch (error) {
console.error(error);
return [];
}
}
@Patch(":id")
@ApiOkResponse({ type: Chat })
@UsePipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true }))
async update(
@Param("id") id: string,
@Body() updateChatDto: UpdateChatDto,
): Promise<Chat> {
return await this.chatService.update(+id, updateChatDto);
}
@Get(":id")
@ApiOkResponse({ type: Chat })
@UsePipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true }))
findOne(@Param("id") id: string): Promise<Chat | null> {
return this.chatService.findOne(+id);
}
@Get()
@ApiOkResponse({ type: [Chat] })
async getChatsForUser(
@Request() req,
@Query()
queryOptions: {
pageSize?: number;
pageOffset?: number;
startId?: number;
status?: ChatStatus;
},
): Promise<Chat[]> {
const userId = req.user.id;
const chats = await this.chatService.findForUser(userId, queryOptions);
return chats;
}
}