Skip to content

πŸ“ˆ Open source, privacy-first web analytics β€” a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

1.2 KB
Raw Blame
import { Injectable } from '@nestjs/common'
import { Markup } from 'telegraf'
import { UserService } from '../../../user/user.service'
import { Context } from '../interface/context.interface'
import { UNLINK_ACCOUNT_SCENE_ID, START_SCENE_ID } from '../telegram.constants'

@Injectable()
export class SettingsScene {
  constructor(private readonly userService: UserService) {}

  async onSceneEnter(context: Context) {
    const user = await this.userService.getUserByTelegramId(context.from.id)

    if (!user) {
      await context.scene.enter(START_SCENE_ID)
      return
    }

    await context.reply(
      'Settings',
      Markup.keyboard(['πŸ”“ Unlink account', 'πŸ”™ Back']).oneTime().resize(),
    )
  }

  async onUnlinkAccount(context: Context) {
    const user = await this.userService.getUserByTelegramId(context.from.id)

    if (!user) {
      await context.scene.enter(START_SCENE_ID)
      return
    }

    await context.scene.enter(UNLINK_ACCOUNT_SCENE_ID)
  }

  async onBack(context: Context) {
    const user = await this.userService.getUserByTelegramId(context.from.id)

    if (!user) {
      await context.scene.enter(START_SCENE_ID)
      return
    }

    await context.scene.enter(START_SCENE_ID)
  }
}