Skip to content

Commit 1e0c982

Browse files
authored
chore: wasabi vista bot renamed (#70)
* chore: wasabi vista bot renamed * chore: update * chore: rename
1 parent 52d2433 commit 1e0c982

10 files changed

Lines changed: 55 additions & 60 deletions

File tree

apps/web-app/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ NUXT_AI_SERVICE_TOKEN=
2222

2323
# Telegram
2424
NUXT_TELEGRAM_ADMIN_ID=
25-
NUXT_TELEGRAM_WASABI_VISTA_TOKEN=
25+
NUXT_TELEGRAM_WASABI_TOKEN=
2626

2727
# App version
2828
VERSION=

apps/web-app/app/layouts/default.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<template>
22
<div class="fixed inset-0 flex overflow-hidden">
3-
<!-- <div class="hidden lg:flex flex-col min-h-svh min-w-16 w-72 border-r border-default shrink-0 bg-elevated/25">
4-
<NavigationHeader class="h-16" />
5-
<Navigation />
6-
</div> -->
7-
83
<main class="flex flex-col min-w-0 min-h-svh lg:not-last:border-r lg:not-last:border-default flex-1">
94
<slot />
105
</main>

apps/web-app/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineNuxtConfig({
1919
serviceToken: '',
2020
},
2121
telegram: {
22-
wasabiVistaToken: '',
22+
wasabiToken: '',
2323
adminId: '',
2424
},
2525
public: {

apps/web-app/server/api/ticket/id/[ticketId]/message.post.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { repository } from '@roll-stack/database'
22
import { type } from 'arktype'
3-
import { useWasabiVistaBot } from '~~/server/services/telegram/wasabi-vista'
3+
import { useWasabiBot } from '~~/server/services/telegram/wasabi-bot'
44
import { createTicketMessageSchema } from '~~/shared/services/ticket'
55

66
export default defineEventHandler(async (event) => {
@@ -55,11 +55,11 @@ export default defineEventHandler(async (event) => {
5555
})
5656
}
5757

58-
const wasabiVistaUser = await repository.wasabiVista.findUserById(ticket.userId)
59-
if (wasabiVistaUser) {
58+
const wasabiUser = await repository.wasabi.findUserById(ticket.userId)
59+
if (wasabiUser) {
6060
// Send message to Telegram
6161
const text = `${user.name} ${user.surname}: ${data.text}`
62-
await useWasabiVistaBot().api.sendMessage(wasabiVistaUser.telegramId, text)
62+
await useWasabiBot().api.sendMessage(wasabiUser.telegramId, text)
6363
}
6464

6565
return {

apps/web-app/server/plugins/03.telegram.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import process from 'node:process'
2-
import { useCreateWasabiVistaBot } from '../services/telegram/wasabi-vista'
2+
import { useCreateWasabiBot } from '../services/telegram/wasabi-bot'
33

44
export default defineNitroPlugin(() => {
55
const logger = useLogger('plugin:start-telegram')
@@ -11,13 +11,13 @@ export default defineNitroPlugin(() => {
1111

1212
const { telegram } = useRuntimeConfig()
1313

14-
if (!telegram.wasabiVistaToken) {
14+
if (!telegram.wasabiToken) {
1515
// No config provided
1616
return
1717
}
1818

1919
// Start the bots (using long polling)
20-
useCreateWasabiVistaBot()
20+
useCreateWasabiBot()
2121

2222
logger.success('Telegram server started')
2323
})

apps/web-app/server/services/telegram/wasabi-vista.ts renamed to apps/web-app/server/services/telegram/wasabi-bot.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { Context } from 'grammy'
22
import { repository } from '@roll-stack/database'
33
import { Bot } from 'grammy'
44

5-
const logger = useLogger('telegram:wasabi-vista')
5+
const logger = useLogger('telegram:wasabi-bot')
66
const { telegram } = useRuntimeConfig()
77

88
let bot: Bot | null = null
99

10-
export async function useCreateWasabiVistaBot() {
11-
bot = new Bot(telegram.wasabiVistaToken)
10+
export async function useCreateWasabiBot() {
11+
bot = new Bot(telegram.wasabiToken)
1212

1313
bot.on('message:text', async (ctx) => {
1414
if (ctx.hasCommand('start')) {
@@ -25,9 +25,9 @@ export async function useCreateWasabiVistaBot() {
2525

2626
try {
2727
await bot.start()
28-
logger.info('Wasabi Vista bot started successfully')
28+
logger.info('Wasabi bot started successfully')
2929
} catch (error) {
30-
logger.error('Failed to start Wasabi Vista bot:', error)
30+
logger.error('Failed to start Wasabi bot:', error)
3131
throw error
3232
}
3333
}
@@ -44,11 +44,11 @@ async function handleStart(ctx: Context) {
4444
}
4545

4646
// Find user
47-
const wasabiVistaUser = await repository.wasabiVista.findUserByTelegramId(ctx.message.from.id.toString())
48-
if (!wasabiVistaUser) {
47+
const wasabiUser = await repository.wasabi.findUserByTelegramId(ctx.message.from.id.toString())
48+
if (!wasabiUser) {
4949
const accessKey = await generateAccessCode()
5050

51-
const createdUser = await repository.wasabiVista.createUser({
51+
const createdUser = await repository.wasabi.createUser({
5252
telegramId: ctx.message.from.id.toString(),
5353
accessKey,
5454
firstName: ctx.message.from.first_name,
@@ -64,7 +64,7 @@ async function handleStart(ctx: Context) {
6464
return
6565
}
6666

67-
if (!wasabiVistaUser.user) {
67+
if (!wasabiUser.user) {
6868
await ctx.reply('Нет доступа. Используйте ранее полученный Ключ доступа. Или передайте его в службу поддержки.')
6969
return
7070
}
@@ -77,20 +77,20 @@ async function handleMessage(ctx: Context) {
7777
return
7878
}
7979

80-
const wasabiVistaUser = await repository.wasabiVista.findUserByTelegramId(ctx.message.from.id.toString())
81-
if (!wasabiVistaUser?.user) {
80+
const wasabiUser = await repository.wasabi.findUserByTelegramId(ctx.message.from.id.toString())
81+
if (!wasabiUser?.user) {
8282
return
8383
}
8484

8585
// Get last ticket
86-
const tickets = await repository.ticket.listOpenedByUser(wasabiVistaUser.user.id)
86+
const tickets = await repository.ticket.listOpenedByUser(wasabiUser.user.id)
8787
let ticket = tickets?.[0]
8888
if (!tickets.length || !ticket) {
8989
// Create ticket
9090
ticket = await repository.ticket.create({
91-
title: `Сопровождение ${wasabiVistaUser.user.name} ${wasabiVistaUser.user.surname}`,
91+
title: `${wasabiUser.user.name} ${wasabiUser.user.surname}`,
9292
description: 'Создано автоматически',
93-
userId: wasabiVistaUser.user.id,
93+
userId: wasabiUser.user.id,
9494
status: 'opened',
9595
})
9696
}
@@ -100,24 +100,24 @@ async function handleMessage(ctx: Context) {
100100

101101
await repository.ticket.createMessage({
102102
ticketId: ticket.id,
103-
userId: wasabiVistaUser.user.id,
103+
userId: wasabiUser.user.id,
104104
text: ctx.message.text,
105105
})
106106

107-
logger.log('message', wasabiVistaUser.user.id, ctx.message.from.id, ctx.message.text)
108-
ctx.reply('Ваше сообщение передано в службу поддержки.')
107+
logger.log('message', wasabiUser.user.id, ctx.message.from.id, ctx.message.text)
108+
ctx.reply('Сообщение передано в службу поддержки.')
109109
}
110110

111-
export function useWasabiVistaBot(): Bot {
111+
export function useWasabiBot(): Bot {
112112
if (!bot) {
113-
throw new Error('Wasabi Vista bot is not initialized. Call useCreateWasabiVistaBot() first.')
113+
throw new Error('Wasabi bot is not initialized. Call useCreateWasabiBot() first.')
114114
}
115115

116116
return bot
117117
}
118118

119-
export async function notifyWasabiVistaAdmin(message: string) {
120-
return useWasabiVistaBot().api.sendMessage(telegram.adminId, message)
119+
export async function notifyWasabiAdmin(message: string) {
120+
return useWasabiBot().api.sendMessage(telegram.adminId, message)
121121
}
122122

123123
async function generateAccessCode(): Promise<string> {
@@ -126,8 +126,8 @@ async function generateAccessCode(): Promise<string> {
126126
// Code should be unique
127127
while (!selectedCode) {
128128
const code = getRandInteger(100000, 999999).toString()
129-
const wasabiVistaUser = await repository.wasabiVista.findUserByKey(code)
130-
if (!wasabiVistaUser) {
129+
const wasabiUser = await repository.wasabi.findUserByKey(code)
130+
if (!wasabiUser) {
131131
selectedCode = code
132132
}
133133
}

packages/database/src/repository/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Product } from './product'
2121
import { Task } from './task'
2222
import { Ticket } from './ticket'
2323
import { User } from './user'
24-
import { WasabiVista } from './wasabi-vista'
24+
import { Wasabi } from './wasabi'
2525

2626
class Repository {
2727
readonly activity = Activity
@@ -46,7 +46,7 @@ class Repository {
4646
readonly task = Task
4747
readonly ticket = Ticket
4848
readonly user = User
49-
readonly wasabiVista = WasabiVista
49+
readonly wasabi = Wasabi
5050

5151
async checkHealth(): Promise<boolean> {
5252
await useDatabase().query.users.findFirst()
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import type { WasabiVistaUserDraft } from '../types'
1+
import type { WasabiUserDraft } from '../types'
22
import { eq, sql } from 'drizzle-orm'
33
import { useDatabase } from '../database'
4-
import { wasabiVistaUsers } from '../tables'
4+
import { wasabiUsers } from '../tables'
55

6-
export class WasabiVista {
6+
export class Wasabi {
77
static async findUser(id: string) {
8-
return useDatabase().query.wasabiVistaUsers.findFirst({
8+
return useDatabase().query.wasabiUsers.findFirst({
99
where: (users, { eq }) => eq(users.id, id),
1010
})
1111
}
1212

1313
static async findUserByKey(key: string) {
14-
return useDatabase().query.wasabiVistaUsers.findFirst({
14+
return useDatabase().query.wasabiUsers.findFirst({
1515
where: (users, { eq }) => eq(users.accessKey, key),
1616
})
1717
}
1818

1919
static async findUserByTelegramId(telegramId: string) {
20-
return useDatabase().query.wasabiVistaUsers.findFirst({
20+
return useDatabase().query.wasabiUsers.findFirst({
2121
where: (users, { eq }) => eq(users.telegramId, telegramId),
2222
with: {
2323
user: true,
@@ -26,29 +26,29 @@ export class WasabiVista {
2626
}
2727

2828
static async findUserById(userId: string) {
29-
return useDatabase().query.wasabiVistaUsers.findFirst({
29+
return useDatabase().query.wasabiUsers.findFirst({
3030
where: (users, { eq }) => eq(users.userId, userId),
3131
})
3232
}
3333

34-
static async createUser(data: WasabiVistaUserDraft) {
35-
const [user] = await useDatabase().insert(wasabiVistaUsers).values(data).returning()
34+
static async createUser(data: WasabiUserDraft) {
35+
const [user] = await useDatabase().insert(wasabiUsers).values(data).returning()
3636
return user
3737
}
3838

39-
static async updateUser(id: string, data: Partial<WasabiVistaUserDraft>) {
39+
static async updateUser(id: string, data: Partial<WasabiUserDraft>) {
4040
const [user] = await useDatabase()
41-
.update(wasabiVistaUsers)
41+
.update(wasabiUsers)
4242
.set({
4343
...data,
4444
updatedAt: sql`now()`,
4545
})
46-
.where(eq(wasabiVistaUsers.id, id))
46+
.where(eq(wasabiUsers.id, id))
4747
.returning()
4848
return user
4949
}
5050

5151
static async deleteUser(id: string) {
52-
return useDatabase().delete(wasabiVistaUsers).where(eq(wasabiVistaUsers.id, id))
52+
return useDatabase().delete(wasabiUsers).where(eq(wasabiUsers.id, id))
5353
}
5454
}

packages/database/src/tables.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type PaymentMethodType = 'card' | 'cash' | 'online'
5353

5454
type FeedbackPointType = 'yandex_map' | '2gis_map' | 'vk_group'
5555

56-
type WasabiVistaUserType = 'private' | 'group' | 'supergroup' | 'channel'
56+
type TelegramUserType = 'private' | 'group' | 'supergroup' | 'channel'
5757

5858
type TicketStatus = 'opened' | 'closed'
5959

@@ -613,7 +613,7 @@ export const networkMetrics = pgTable('network_metrics', {
613613
averageCheck: numeric('average_check', { mode: 'number' }).notNull().default(0),
614614
})
615615

616-
export const wasabiVistaUsers = pgTable('wasabi_vista_users', {
616+
export const wasabiUsers = pgTable('wasabi_users', {
617617
id: cuid2('id').defaultRandom().primaryKey(),
618618
createdAt: timestamp('created_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
619619
updatedAt: timestamp('updated_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
@@ -623,7 +623,7 @@ export const wasabiVistaUsers = pgTable('wasabi_vista_users', {
623623
lastName: varchar('last_name'),
624624
username: varchar('username'),
625625
title: varchar('title'),
626-
type: varchar('type').notNull().$type<WasabiVistaUserType>(),
626+
type: varchar('type').notNull().$type<TelegramUserType>(),
627627
userId: cuid2('user_id').references(() => users.id, {
628628
onDelete: 'cascade',
629629
onUpdate: 'cascade',
@@ -693,7 +693,7 @@ export const userRelations = relations(users, ({ many, one }) => ({
693693
taskLists: many(taskLists),
694694
postLikes: many(postLikes),
695695
postComments: many(postComments),
696-
wasabiVistaUsers: many(wasabiVistaUsers),
696+
wasabiUsers: many(wasabiUsers),
697697
tickets: many(tickets),
698698
ticketMessages: many(ticketMessages),
699699
focusedTask: one(tasks, {
@@ -1048,9 +1048,9 @@ export const clientReviewRelations = relations(clientReviews, ({ one }) => ({
10481048
}),
10491049
}))
10501050

1051-
export const wasabiVistaUserRelations = relations(wasabiVistaUsers, ({ one }) => ({
1051+
export const wasabiUserRelations = relations(wasabiUsers, ({ one }) => ({
10521052
user: one(users, {
1053-
fields: [wasabiVistaUsers.userId],
1053+
fields: [wasabiUsers.userId],
10541054
references: [users.id],
10551055
}),
10561056
}))

packages/database/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export type ClientReviewDraft = InferInsertModel<typeof tables.clientReviews>
129129
export type NetworkMetrics = InferSelectModel<typeof tables.networkMetrics>
130130
export type NetworkMetricsDraft = InferInsertModel<typeof tables.networkMetrics>
131131

132-
export type WasabiVistaUser = InferSelectModel<typeof tables.wasabiVistaUsers>
133-
export type WasabiVistaUserDraft = InferInsertModel<typeof tables.wasabiVistaUsers>
132+
export type WasabiUser = InferSelectModel<typeof tables.wasabiUsers>
133+
export type WasabiUserDraft = InferInsertModel<typeof tables.wasabiUsers>
134134

135135
export type Ticket = InferSelectModel<typeof tables.tickets>
136136
export type TicketDraft = InferInsertModel<typeof tables.tickets>

0 commit comments

Comments
 (0)