-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6319c9
commit 68825f3
Showing
27 changed files
with
146 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
OPEN_AI_TOKEN= | ||
TELEGRAM_TOKEN= | ||
MONGODB_URI= | ||
MONGODB_URI= | ||
SUPER_ADMIN_USERNAME= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './admin/logs.callbacks'; | ||
export * from './admin/sessions.callbacks'; | ||
export * from './admin/users.callbacks'; | ||
export * from './admin/logs.callback'; | ||
export * from './admin/sessions.callback'; | ||
export * from './admin/users.callback'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { addUserConversation } from '@bot/conversations'; | ||
import { BotContextType } from '@bot/types'; | ||
import { conversations, createConversation } from '@grammyjs/conversations'; | ||
import { Composer, Middleware } from 'grammy'; | ||
|
||
const composer = new Composer<BotContextType>(); | ||
|
||
composer.use(conversations()); | ||
|
||
composer.use(createConversation(addUserConversation)); | ||
|
||
export const conversationComposer = (): Middleware<BotContextType> => composer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { config } from '@bot/config'; | ||
import { gptModel, supportLanguageCodes } from '@bot/constants'; | ||
import { mapBotCommands, mapBotDescription } from '@bot/helpers'; | ||
import { BotContextType } from '@bot/types'; | ||
import { I18n } from '@grammyjs/i18n'; | ||
import { Api, Composer, Middleware } from 'grammy'; | ||
import path from 'path'; | ||
|
||
const api = new Api(config.TELEGRAM_TOKEN); | ||
|
||
const composer = new Composer<BotContextType>(); | ||
|
||
const i18n = new I18n<BotContextType>({ | ||
defaultLocale: 'en', | ||
globalTranslationContext: (ctx) => ({ | ||
botName: ctx?.me?.first_name ?? '', | ||
firstName: ctx?.from?.first_name ?? '', | ||
model: gptModel, | ||
username: ctx?.from?.username ?? '', | ||
}), | ||
directory: path.join(__dirname, '../locales'), | ||
useSession: true, | ||
}); | ||
|
||
supportLanguageCodes.forEach(async (languageCode) => { | ||
await api.setMyDescription(mapBotDescription(i18n, languageCode), { | ||
language_code: languageCode, | ||
}); | ||
|
||
await api.setMyCommands(mapBotCommands(i18n, languageCode), { | ||
language_code: languageCode, | ||
}); | ||
}); | ||
|
||
composer.use(i18n); | ||
|
||
export const i18nComposer = (): Middleware<BotContextType> => composer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './conversation.composer'; | ||
export * from './menu.composer'; | ||
export * from './session.composer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
adminDynamicUsersForDeleteSessionsMenu, | ||
adminDynamicUsersForSessionsMenu, | ||
adminDynamicUsersMenu, | ||
adminLogsMenu, | ||
adminMainMenu, | ||
adminSessionsMenu, | ||
adminUsersMenu, | ||
} from '@bot/menu'; | ||
import { BotContextType } from '@bot/types'; | ||
import { Composer, Middleware } from 'grammy'; | ||
|
||
const composer = new Composer<BotContextType>(); | ||
|
||
adminMainMenu.register(adminSessionsMenu); | ||
adminMainMenu.register(adminUsersMenu); | ||
adminMainMenu.register(adminLogsMenu); | ||
adminMainMenu.register(adminDynamicUsersMenu); | ||
adminMainMenu.register(adminDynamicUsersForSessionsMenu); | ||
adminMainMenu.register(adminDynamicUsersForDeleteSessionsMenu); | ||
|
||
composer.use(adminMainMenu); | ||
|
||
export const menuComposer = (): Middleware<BotContextType> => composer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createInitialSessionData } from '@bot/helpers'; | ||
import { mongo } from '@bot/services'; | ||
import { BotContextType } from '@bot/types'; | ||
import { Composer, Middleware, session } from 'grammy'; | ||
|
||
const composer = new Composer<BotContextType>(); | ||
|
||
composer.use( | ||
session({ | ||
type: 'multi', | ||
custom: { | ||
storage: mongo.sessionAdapter, | ||
initial: createInitialSessionData, | ||
}, | ||
conversation: {}, | ||
}), | ||
); | ||
|
||
export const sessionComposer = (): Middleware<BotContextType> => composer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './api.helpers'; | ||
export * from './gpt.helpers'; | ||
export * from './lang.helpers'; | ||
export * from './session.helpers'; | ||
export * from './user.helpers'; | ||
export * from './api.helper'; | ||
export * from './gpt.helper'; | ||
export * from './lang.helper'; | ||
export * from './logger.helper'; | ||
export * from './session.helper'; | ||
export * from './user.helper'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { logger } from '@bot/services'; | ||
import { BotError, GrammyError, HttpError } from 'grammy'; | ||
|
||
export const handleBotError = (error: BotError) => { | ||
const ctx = error.ctx; | ||
const err = error.error; | ||
|
||
logger.error(`botInitialize::error while handling update::${ctx.update.update_id}:`); | ||
|
||
if (err instanceof GrammyError) { | ||
logger.error(`botInitialize::error in request::${err.description}`); | ||
} else if (err instanceof HttpError) { | ||
logger.error(`botInitialize::could not contact Telegram::${err.message}`); | ||
} else { | ||
logger.error(`botInitialize::unknown error::${(err as Error).message}`); | ||
} | ||
}; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './bot.types'; | ||
export * from './middleware.types'; | ||
export * from './model.types'; | ||
export * from './service.types'; | ||
export * from './bot.type'; | ||
export * from './middleware.type'; | ||
export * from './model.type'; | ||
export * from './service.type'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.