-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
119 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Controller, Logger, UseInterceptors } from '@nestjs/common'; | ||
import { MessagePattern, Payload } from '@nestjs/microservices'; | ||
import { BotService } from './bot.service'; | ||
import { TelegramAction } from '@app/common'; | ||
import { EventsInterceptor } from '@app/common/rmq/interceptors/events.interceptor'; | ||
|
||
interface MessagePayload { | ||
chat_id: number | string; | ||
text: string; | ||
other: any; | ||
} | ||
|
||
@Controller() | ||
@UseInterceptors(EventsInterceptor) | ||
export class BotController { | ||
private readonly logger = new Logger(BotController.name); | ||
constructor(private readonly botService: BotService) { } | ||
|
||
@MessagePattern(TelegramAction.SEND_MESSAGE) | ||
async sendMessage(@Payload() payload: MessagePayload): Promise<void> { | ||
const { chat_id, text, other } = payload; | ||
await this.botService.sendMessage(chat_id, text, other); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,47 @@ | ||
import { Controller, Logger } from '@nestjs/common'; | ||
import { Controller, Inject, Logger } from '@nestjs/common'; | ||
import { QuestionServiceService } from './question-service.service'; | ||
import { MessagePattern, Payload } from '@nestjs/microservices'; | ||
import { UpdateEvent } from '@app/common'; | ||
import { ClientProxy, MessagePattern, Payload } from '@nestjs/microservices'; | ||
import { Services, TelegramAction, UpdateEvent } from '@app/common'; | ||
import { Context } from 'grammy'; | ||
import { ReplyParameters } from 'grammy/types'; | ||
import { UseInterceptors } from '@nestjs/common'; | ||
import { EventsInterceptor } from '@app/common/rmq/interceptors/events.interceptor'; | ||
|
||
@Controller() | ||
@UseInterceptors(EventsInterceptor) | ||
export class QuestionServiceController { | ||
private readonly logger = new Logger(QuestionServiceController.name); | ||
constructor( | ||
private readonly questionServiceService: QuestionServiceService, | ||
@Inject(Services.TelegramBot.name) | ||
private readonly telegramClient: ClientProxy, | ||
) { } | ||
|
||
@MessagePattern(UpdateEvent.MESSAGE) | ||
async message(@Payload() payload): Promise<void> { | ||
const { update } = payload; | ||
const { message } = update; | ||
const { data } = await this.questionServiceService.test(message.text); | ||
this.logger.log('Result', data); | ||
async message(@Payload() ctx: Context): Promise<void> { | ||
const { | ||
message_id, | ||
text: msg, | ||
chat: { id: chat_id }, | ||
} = ctx.update?.message; | ||
const { | ||
data: { label, score }, | ||
} = await this.questionServiceService.test(msg); | ||
|
||
const text = `${label}: ${score}`; | ||
|
||
const reply_parameters: ReplyParameters = { | ||
message_id, | ||
}; | ||
|
||
const data = { | ||
chat_id, | ||
text, | ||
other: { | ||
reply_parameters, | ||
}, | ||
}; | ||
|
||
this.telegramClient.emit(TelegramAction.SEND_MESSAGE, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.