Skip to content

Commit aa2739f

Browse files
authored
Merge pull request #37 from TogetherCrew/refactor
Refactor
2 parents 298502c + e55792c commit aa2739f

File tree

5 files changed

+8
-64
lines changed

5 files changed

+8
-64
lines changed

apps/bot/src/bot.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ import { HandlersModule } from './handlers/handlers.module';
3333
controllers: [BotController],
3434
providers: [BotService],
3535
})
36-
export class BotModule { }
36+
export class BotModule {}

apps/bot/src/bot.service.ts

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class BotService implements OnModuleInit {
4343
Object.values(UpdateEvent).map((event) => {
4444
this.bot.on(event, (ctx: Context) => {
4545
this.logger.log(`Received ${event} from ${ctx.chat.id}`);
46-
this.updateHandler.handle(ctx);
46+
this.updateHandler.handle(ctx, event);
4747
this.questionHandler.handle(ctx);
4848
return;
4949
});
@@ -119,60 +119,4 @@ export class BotService implements OnModuleInit {
119119

120120
await ctx.reply(text, { parse_mode: 'HTML' });
121121
};
122-
123-
// protected getSummary = async (ctx: Context) => {
124-
// try {
125-
// const community = await this.temporalClient.execute(
126-
// 'TelegramGetCommunityWorkflow',
127-
// {
128-
// taskQueue: 'TEMPORAL_QUEUE_LIGHT',
129-
// args: [{ chatId: ctx.chat.id }],
130-
// workflowId: `telegram:getcommunity:${ctx.update.update_id}`,
131-
// },
132-
// );
133-
// if (!community) {
134-
// console.log('No community found for', ctx.chat.id);
135-
// return;
136-
// }
137-
138-
// const platform = await this.temporalClient.execute(
139-
// 'TelegramGetPlatformWorkflow',
140-
// {
141-
// taskQueue: 'TEMPORAL_QUEUE_LIGHT',
142-
// args: [{ chatId: ctx.chat.id }],
143-
// workflowId: `telegram:getplatform:${ctx.update.update_id}`,
144-
// },
145-
// );
146-
// if (!platform) {
147-
// console.log('No platform found for', ctx.chat.id);
148-
// return;
149-
// }
150-
151-
// const summary = await this.temporalClient.execute(
152-
// 'PlatformSummariesWorkflow',
153-
// {
154-
// taskQueue: 'TEMPORAL_QUEUE_PYTHON_LIGHT',
155-
// args: [
156-
// {
157-
// platform_id: platform.id,
158-
// community_id: community.id,
159-
// start_date: null,
160-
// end_date: null,
161-
// extract_text_only: true,
162-
// },
163-
// ],
164-
// workflowId: `telegram:summaries:${ctx.update.update_id}`,
165-
// },
166-
// );
167-
168-
// if (!summary || summary.length === 0) {
169-
// console.log('No summary found for', ctx.chat.id);
170-
// return;
171-
// }
172-
173-
// await ctx.reply(summary);
174-
// } catch (error) {
175-
// console.error(error);
176-
// }
177-
// };
178122
}

apps/bot/src/handlers/base.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export abstract class BaseHandler {
1111
@InjectTemporalClient()
1212
protected readonly temporalClient: WorkflowClient,
1313
protected readonly configService: ConfigService,
14-
) { }
14+
) {}
1515
abstract handle(ctx: Context, event?: FilterQuery): Promise<void>;
1616
}

apps/bot/src/handlers/handlers.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ import { SummaryHandler } from './summary.handler';
1111
providers: [QuestionHandler, UpdateHandler, VerifyHandler, SummaryHandler],
1212
exports: [QuestionHandler, UpdateHandler, VerifyHandler, SummaryHandler],
1313
})
14-
export class HandlersModule { }
14+
export class HandlersModule {}

apps/bot/src/handlers/update.handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { Context } from 'grammy';
1+
import { Context, FilterQuery } from 'grammy';
22
import { BaseHandler } from './base.handler';
33

44
export class UpdateHandler extends BaseHandler {
5-
async handle(ctx: Context): Promise<void> {
5+
async handle(ctx: Context, event: FilterQuery): Promise<void> {
66
try {
77
const update = ctx.update;
8-
await this.temporalClient.start('TelegramUpdateWorkflow', {
8+
await this.temporalClient.start('TelegramEventWorkflow', {
99
taskQueue: 'TEMPORAL_QUEUE_LIGHT',
10-
args: [{ update }],
10+
args: [{ update, event }],
1111
workflowId: `telegram:update:${update.update_id}`,
1212
});
1313
} catch (error) {

0 commit comments

Comments
 (0)