Skip to content

Commit 4b6d267

Browse files
Merge pull request #2047 from AletheiaFact/feature/m2m-chat-bot-hook
feat: M2M Authentication For Chatbot Hook
2 parents 4ee73fb + a5a1dcd commit 4b6d267

File tree

3 files changed

+6
-64
lines changed

3 files changed

+6
-64
lines changed

server/chat-bot/chat-bot.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Controller, Post, Req, Res } from "@nestjs/common";
22
import { ChatbotService } from "./chat-bot.service";
33
import type { Request, Response } from "express";
4+
import { AdminOnly } from "../auth/decorators/auth.decorator";
45

56
@Controller()
67
export class ChatbotController {
78
constructor(private readonly chatBotService: ChatbotService) {}
89

10+
@AdminOnly({ allowM2M: true })
911
@Post("api/chatbot/hook")
1012
handleHook(@Req() req: Request, @Res() res: Response) {
1113
const response = this.chatBotService.sendMessage(req.body.message);

server/chat-bot/chat-bot.module.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
import {
2-
MiddlewareConsumer,
3-
Module,
4-
NestModule,
5-
RequestMethod,
6-
} from "@nestjs/common";
1+
import { Module } from "@nestjs/common";
72
import { ChatbotService } from "./chat-bot.service";
83
import { ChatbotController } from "./chat-bot.controller";
94
import { HttpModule } from "@nestjs/axios";
105
import { VerificationRequestModule } from "../verification-request/verification-request.module";
116
import { ConfigModule } from "@nestjs/config";
12-
import { AuthZenviaWebHookMiddleware } from "../middleware/auth-zenvia-webhook.middleware";
137
import { ChatBotStateModule } from "../chat-bot-state/chat-bot-state.module";
148
import { VerificationRequestStateMachineService } from "../verification-request/state-machine/verification-request.state-machine.service";
9+
import { AbilityModule } from "../auth/ability/ability.module";
1510

1611
@Module({
1712
imports: [
1813
HttpModule,
1914
VerificationRequestModule,
2015
ConfigModule,
2116
ChatBotStateModule,
17+
AbilityModule,
2218
],
2319
providers: [ChatbotService, VerificationRequestStateMachineService],
2420
controllers: [ChatbotController],
2521
})
26-
export class ChatbotModule implements NestModule {
27-
configure(consumer: MiddlewareConsumer) {
28-
consumer.apply(AuthZenviaWebHookMiddleware).forRoutes({
29-
path: "api/chatbot/hook",
30-
method: RequestMethod.POST,
31-
});
32-
}
33-
}
22+
export class ChatbotModule {}

server/middleware/auth-zenvia-webhook.middleware.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)