@@ -2,13 +2,13 @@ import type { Context } from 'grammy'
22import { repository } from '@roll-stack/database'
33import { Bot } from 'grammy'
44
5- const logger = useLogger ( 'telegram:wasabi-vista ' )
5+ const logger = useLogger ( 'telegram:wasabi-bot ' )
66const { telegram } = useRuntimeConfig ( )
77
88let 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
123123async 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 }
0 commit comments