Skip to content

Commit

Permalink
fet: profile scene
Browse files Browse the repository at this point in the history
  • Loading branch information
dodyagung committed Apr 8, 2024
1 parent 5207e90 commit 881dc6b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/sale/sale.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { SaleScene } from './scene/sale.scene';
import { WelcomeScene } from './scene/welcome.scene';
import { AboutScene } from './scene/about.scene';
import { TutorialScene } from './scene/tutorial.scene';
import { ProfileScene } from './scene/profile.scene';

@Module({
providers: [
SaleUpdate,
SaleService,
SaleScene,
WelcomeScene,
ProfileScene,
AboutScene,
TutorialScene,
],
Expand Down
20 changes: 10 additions & 10 deletions src/sale/sale.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Logger, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { posts } from '@prisma/client';
import { posts, users } from '@prisma/client';
import { PrismaService } from 'src/prisma/prisma.service';

@Injectable()
export class SaleService {
private readonly logger = new Logger(SaleService.name);

constructor(private prismaService: PrismaService) {}

// @Cron('0 */4 * * * *') // every 4 minutes
Expand All @@ -15,10 +13,12 @@ export class SaleService {
// this.logger.log(`Database ping: ${JSON.stringify(ping)}`);
// }

// async mySale() {
// const a: posts | null = await this.prismaService.posts.findFirst({
// where: { id: Number(711) },
// });
// console.log(a?.post);
// }
async getUserPhone(id: string): Promise<{ phone: string | null } | null> {
return await this.prismaService.users.findFirst({
select: { phone: true },
where: {
id,
},
});
}
}
2 changes: 1 addition & 1 deletion src/sale/scene/about.scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AboutScene {
message += `If you are developer, open a [GitHub Pull Request](https://github.com/dodyagung/telegram-sale-bot/pulls)\\.\n\n`;

message += `*Creator*\n`;
message += `Hi, I am Dody\\. A backend enthusiast\\. Loves Golang and Typescript\\.\n`;
message += `Hi, I\\'m Dody\\. A backend enthusiast\\. Loves Golang and Typescript\\.\n`;
message += `Visit my website at [dodyagung\\.com](https://dodyagung.com)\\.\n\n`;

message += `*License*\n`;
Expand Down
35 changes: 35 additions & 0 deletions src/sale/scene/profile.scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Scene, SceneEnter, Ctx, Action } from 'nestjs-telegraf';
import { SceneContext } from 'telegraf/scenes';
import { Markup } from 'telegraf';
import { sendMessage } from '../sale.common';
import { SaleService } from '../sale.service';

@Scene('PROFILE_SCENE')
export class ProfileScene {
constructor(private saleService: SaleService) {}

@SceneEnter()
async onSceneEnter(@Ctx() ctx: SceneContext): Promise<void> {
const keyboard = [[Markup.button.callback('👈 Back', 'back')]];

let message = `*👤 My Profile*\n\n`;

message += `This is your account information\\. You can also edit, enable or disable your phone below\\.\n\n`;

message += `*Telegram Info*\n`;
message += `├ ID : \`${ctx.from!.id}\`\n`;
message += `├ Username : \`${ctx.from?.username ?? '<not set>'}\`\n`;
message += `├ First Name : \`${ctx.from!.first_name}\`\n`;
message += `└ Last Name : \`${ctx.from?.last_name ?? '<not set>'}\`\n\n`;

message += `*Additional Info*\n`;
message += `└ Phone : \`${(await this.saleService.getUserPhone(ctx.from!.id.toString()))?.phone ?? '<not set>'}\`\n\n`;

await sendMessage(ctx, message, keyboard);
}

@Action('back')
async onBack(@Ctx() ctx: SceneContext): Promise<void> {
await ctx.scene.enter('WELCOME_SCENE');
}
}
7 changes: 6 additions & 1 deletion src/sale/scene/welcome.scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class WelcomeScene {
(
await ctx.telegram.getChatMember(
this.configService.get<string>('TELEGRAM_GROUP_ID')!,
ctx.from?.id ?? 0,
ctx.from!.id,
)
).status,
);
Expand Down Expand Up @@ -60,6 +60,11 @@ export class WelcomeScene {
await ctx.scene.enter('SALE_SCENE');
}

@Action('profile')
async onProfileAction(@Ctx() ctx: SceneContext): Promise<void> {
await ctx.scene.enter('PROFILE_SCENE');
}

@Action('tutorial')
async onTutorialAction(@Ctx() ctx: SceneContext): Promise<void> {
await ctx.scene.enter('TUTORIAL_SCENE');
Expand Down

0 comments on commit 881dc6b

Please sign in to comment.