Skip to content

Commit

Permalink
feat: edit message
Browse files Browse the repository at this point in the history
  • Loading branch information
dodyagung committed Mar 31, 2024
1 parent 1d35cb8 commit 58cbf77
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
38 changes: 31 additions & 7 deletions src/sale/sale.update.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Hears, Start, Update, Ctx, Sender, Command } from 'nestjs-telegraf';
import { Context, Markup } from 'telegraf';
import { Markup, type Context as TContext } from 'telegraf';
import { SaleService } from './sale.service';
import { RESET_DAY, SALE_DAY, TIMEZONE, TODAY } from './sale.constant';
import { ConfigService } from '@nestjs/config';
import { SceneContext, WizardContext } from 'telegraf/scenes';
import type { Update as TUpdate } from 'telegraf/types';

interface Context<U extends TUpdate = TUpdate> extends TContext<U> {
session: {
last_message_id: number;
};
}

@Update()
export class SaleUpdate {
Expand Down Expand Up @@ -70,11 +77,28 @@ export class SaleUpdate {
message += `├ Joined : \`${user_joined ? 'Yes' : 'No'}\`\n`;
message += `└ Link : [Click Here](${this.configService.get<string>('TELEGRAM_GROUP_LINK')})`;

await ctx.replyWithMarkdownV2(message, {
link_preview_options: {
is_disabled: true,
},
reply_markup: keyboard.reply_markup,
});
const last_message_id = ctx.session.last_message_id;

if (last_message_id) {
console.log(ctx);

const edit = await ctx.telegram.editMessageText(
ctx.chat?.id,
last_message_id,
undefined,
new Date().toString(),
);

console.log(edit);
} else {
const { message_id } = await ctx.replyWithMarkdownV2(message, {
link_preview_options: {
is_disabled: true,
},
reply_markup: keyboard.reply_markup,
});

ctx.session.last_message_id = message_id;
}
}
}
6 changes: 3 additions & 3 deletions src/sale/sale.wizard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Ctx, Message, On, Wizard, WizardStep } from 'nestjs-telegraf';
import { WizardContext } from 'telegraf/scenes';

interface SaleScene {
interface State {
name: string;
}

Expand All @@ -21,7 +21,7 @@ export class SaleWizard {
@Message() msg: { text: string },
): Promise<string> {
console.log('Enter to step 1');
(ctx.wizard.state as SaleScene).name = msg.text;
(ctx.wizard.state as State).name = msg.text;
await ctx.wizard.next();
return 'Send me where are you from';
}
Expand All @@ -34,6 +34,6 @@ export class SaleWizard {
): Promise<string> {
console.log('Enter to step 3');
await ctx.scene.leave();
return `Hello ${(ctx.wizard.state as SaleScene).name} from ${msg.text}. I'm Greater bot from 127.0.0.1 👋`;
return `Hello ${(ctx.wizard.state as State).name} from ${msg.text}. I'm Greater bot from 127.0.0.1 👋`;
}
}

0 comments on commit 58cbf77

Please sign in to comment.