Files
telegram-shop/src/router/routes.js
NW 7db7a20a1d feat: always show language selector on /start, add change_language button in profile
- /start now always shows language picker (removed language_set check)
- Added 'Change Language' button in profile inline keyboard
- Added handleChangeLanguage callback handler
- Added profile.change_language locale key in en/es/de
- Registered change_language callback route
2026-06-25 23:06:58 +01:00

377 lines
17 KiB
JavaScript

import callbackRouter from './callbackRouter.js';
import messageRouter from './messageRouter.js';
import { isAdmin } from '../middleware/auth.js';
import logger from '../utils/logger.js';
import userHandler from '../handlers/userHandlers/userHandler.js';
import userPurchaseHandler from '../handlers/userHandlers/userPurchaseHandler.js';
import userLocationHandler from '../handlers/userHandlers/userLocationHandler.js';
import userProductHandler from '../handlers/userHandlers/userProductHandler.js';
import userWalletsHandler from '../handlers/userHandlers/wallet/index.js';
import DepositHandler from '../handlers/userHandlers/wallet/depositHandler.js';
import userDeletionHandler from '../handlers/userHandlers/userDeletionHandler.js';
import adminHandler from '../handlers/adminHandlers/adminHandler.js';
import adminUserLocationHandler from '../handlers/adminHandlers/adminUserLocationHandler.js';
import adminDumpHandler from '../handlers/adminHandlers/adminDumpHandler.js';
import adminLocationHandler from '../handlers/adminHandlers/adminLocationHandler.js';
import productHandler from '../handlers/adminHandlers/product/index.js';
import adminWalletsHandler from '../handlers/adminHandlers/adminWalletsHandler.js';
import adminUserHandler from '../handlers/adminHandlers/adminUserHandler.js';
const logDebug = (action, functionName) => {
logger.debug({ action, functionName }, 'Button Press');
};
export function registerRoutes() {
// === Message Input Handlers (order matters — checked first) ===
messageRouter.registerInput(adminLocationHandler.handleLocationInput.bind(adminLocationHandler));
messageRouter.registerInput(productHandler.handleCategoryInput.bind(productHandler));
messageRouter.registerInput(productHandler.handleProductImport.bind(productHandler));
messageRouter.registerInput(productHandler.handleProductEditImport.bind(productHandler));
messageRouter.registerInput(adminDumpHandler.handleDumpImport.bind(adminDumpHandler));
messageRouter.registerInput(adminUserHandler.handleBonusBalanceInput.bind(adminUserHandler));
messageRouter.registerInput(productHandler.handleCategoryUpdate.bind(productHandler));
// === Language Selection ===
callbackRouter.registerPrefix('set_language_', async (cq) => {
logDebug(cq.data, 'handleSetLanguage');
await userHandler.handleSetLanguage(cq);
});
// === Text Commands ===
messageRouter.registerText('keyboard.products', async (msg) => {
logDebug(msg.text, 'showProducts');
await userProductHandler.showProducts(msg);
});
messageRouter.registerText('keyboard.profile', async (msg) => {
logDebug(msg.text, 'showProfile');
await userHandler.showProfile(msg);
});
messageRouter.registerText('keyboard.wallets', async (msg) => {
logDebug(msg.text, 'showBalance');
await userWalletsHandler.showBalance(msg);
});
messageRouter.registerText('keyboard.purchases', async (msg) => {
logDebug(msg.text, 'showPurchases');
await userPurchaseHandler.showPurchases(msg);
});
messageRouter.registerText('keyboard.manage_products', async (msg) => {
if (!isAdmin(msg.from.id)) return;
logDebug(msg.text, 'handleProductManagement');
await productHandler.handleProductManagement(msg);
});
messageRouter.registerText('keyboard.manage_users', async (msg) => {
if (!isAdmin(msg.from.id)) return;
logDebug(msg.text, 'handleUserList');
await adminUserHandler.handleUserList(msg);
});
messageRouter.registerText('keyboard.manage_locations', async (msg) => {
if (!isAdmin(msg.from.id)) return;
logDebug(msg.text, 'handleViewLocations');
await adminLocationHandler.handleViewLocations(msg);
});
messageRouter.registerText('keyboard.database_backup', async (msg) => {
if (!isAdmin(msg.from.id)) return;
logDebug(msg.text, 'handleDump');
await adminDumpHandler.handleDump(msg);
});
messageRouter.registerText('keyboard.manage_wallets', async (msg) => {
if (!isAdmin(msg.from.id)) return;
logDebug(msg.text, 'handleWalletManagement');
await adminWalletsHandler.handleWalletManagement(msg);
});
// === Exact Callback Routes ===
callbackRouter.registerExact('set_location', async (cq) => {
logDebug(cq.data, 'handleSetLocation');
await userLocationHandler.handleSetLocation(cq);
});
callbackRouter.registerExact('change_language', async (cq) => {
logDebug(cq.data, 'handleChangeLanguage');
await userHandler.handleChangeLanguage(cq);
});
callbackRouter.registerExact('back_to_profile', async (cq) => {
logDebug(cq.data, 'handleBackToProfile');
await userHandler.handleBackToProfile(cq);
});
callbackRouter.registerExact('back_to_balance', async (cq) => {
logDebug(cq.data, 'handleBackToBalance');
await userWalletsHandler.handleBackToBalance(cq);
});
callbackRouter.registerExact('delete_account', async (cq) => {
logDebug(cq.data, 'handleDeleteAccount');
await userDeletionHandler.handleDeleteAccount(cq);
});
callbackRouter.registerExact('confirm_delete_account', async (cq) => {
logDebug(cq.data, 'handleConfirmDelete');
await userDeletionHandler.handleConfirmDelete(cq);
});
callbackRouter.registerExact('add_wallet', async (cq) => {
logDebug(cq.data, 'handleAddWallet');
await userWalletsHandler.handleAddWallet(cq);
});
callbackRouter.registerExact('top_up_wallet', async (cq) => {
logDebug(cq.data, 'handleTopUpWallet');
await userWalletsHandler.handleTopUpWallet(cq);
});
callbackRouter.registerExact('deposit_select_wallet', async (cq) => {
logDebug(cq.data, 'handleDepositSelectWallet');
await DepositHandler.handleDepositSelectWallet(cq);
});
callbackRouter.registerPrefix('deposit_wallet_', async (cq) => {
logDebug(cq.data, 'handleDepositSelectAmount');
await DepositHandler.handleDepositSelectAmount(cq);
});
callbackRouter.registerPrefix('deposit_amount_', async (cq) => {
logDebug(cq.data, 'handleDepositInstruction');
await DepositHandler.handleDepositInstruction(cq);
});
callbackRouter.registerPrefix('deposit_copy_', async (cq) => {
logDebug(cq.data, 'handleDepositCopyAddress');
await DepositHandler.handleDepositCopyAddress(cq);
});
callbackRouter.registerExact('wallet_history', async (cq) => {
logDebug(cq.data, 'handleWalletHistory');
await userWalletsHandler.handleWalletHistory(cq);
});
callbackRouter.registerExact('view_archived_wallets', async (cq) => {
logDebug(cq.data, 'handleViewArchivedWallets');
await userWalletsHandler.handleViewArchivedWallets(cq);
});
callbackRouter.registerExact('refresh_balance', async (cq) => {
logDebug(cq.data, 'handleRefreshBalance');
await userWalletsHandler.handleRefreshBalance(cq);
});
callbackRouter.registerExact('shop_start', async (cq) => {
logDebug(cq.data, 'showProducts');
await userProductHandler.showProducts(cq.message);
});
callbackRouter.registerExact('add_location', async (cq) => {
logDebug(cq.data, 'handleAddLocation');
await adminLocationHandler.handleAddLocation(cq);
});
callbackRouter.registerExact('view_locations', async (cq) => {
logDebug(cq.data, 'handleViewLocations');
await adminLocationHandler.handleViewLocations(cq);
});
callbackRouter.registerExact('view_ip', async (cq) => {
logDebug(cq.data, 'handleViewIP');
await adminLocationHandler.handleViewIP(cq);
});
callbackRouter.registerExact('delete_location', async (cq) => {
logDebug(cq.data, 'handleDeleteLocation');
await adminLocationHandler.handleDeleteLocation(cq);
});
callbackRouter.registerExact('admin_menu', async (cq) => {
logDebug(cq.data, 'backToMenu');
await adminLocationHandler.backToMenu(cq);
});
callbackRouter.registerExact('manage_products', async (cq) => {
logDebug(cq.data, 'handleProductManagement');
await productHandler.handleProductManagement(cq);
});
callbackRouter.registerExact('export_database', async (cq) => {
logDebug(cq.data, 'handleExportDatabase');
await adminDumpHandler.handleExportDatabase(cq);
});
callbackRouter.registerExact('import_database', async (cq) => {
logDebug(cq.data, 'handleImportDatabase');
await adminDumpHandler.handleImportDatabase(cq);
});
callbackRouter.registerExact('back_to_wallet_types', async (cq) => {
logDebug(cq.data, 'handleBackToWalletTypes');
await adminWalletsHandler.handleBackToWalletTypes(cq);
});
// === Prefix Callback Routes ===
callbackRouter.registerPrefix('set_country_', async (cq) => {
logDebug(cq.data, 'handleSetCountry');
await userLocationHandler.handleSetCountry(cq);
});
callbackRouter.registerPrefix('set_city_', async (cq) => {
logDebug(cq.data, 'handleSetCity');
await userLocationHandler.handleSetCity(cq);
});
callbackRouter.registerPrefix('set_district_', async (cq) => {
logDebug(cq.data, 'handleSetDistrict');
await userLocationHandler.handleSetDistrict(cq);
});
callbackRouter.registerPrefix('generate_wallet_', async (cq) => {
logDebug(cq.data, 'handleGenerateWallet');
await userWalletsHandler.handleGenerateWallet(cq);
});
callbackRouter.registerPrefix('shop_country_', async (cq) => {
logDebug(cq.data, 'handleCountrySelection');
await userProductHandler.handleCountrySelection(cq);
});
callbackRouter.registerPrefix('shop_city_', async (cq) => {
logDebug(cq.data, 'handleCitySelection');
await userProductHandler.handleCitySelection(cq);
});
callbackRouter.registerPrefix('shop_loc_', async (cq) => {
logDebug(cq.data, 'handleDistrictSelection');
await userProductHandler.handleDistrictSelection(cq);
});
callbackRouter.registerPrefix('shop_category_', async (cq) => {
logDebug(cq.data, 'handleCategorySelection');
await userProductHandler.handleCategorySelection(cq);
});
callbackRouter.registerPrefix('shop_product_', async (cq) => {
logDebug(cq.data, 'handleProductSelection');
await userProductHandler.handleProductSelection(cq);
});
callbackRouter.registerPrefix('increase_quantity_', async (cq) => {
logDebug(cq.data, 'handleIncreaseQuantity');
await userProductHandler.handleIncreaseQuantity(cq);
});
callbackRouter.registerPrefix('decrease_quantity_', async (cq) => {
logDebug(cq.data, 'handleDecreaseQuantity');
await userProductHandler.handleDecreaseQuantity(cq);
});
callbackRouter.registerPrefix('buy_product_', async (cq) => {
logDebug(cq.data, 'handleBuyProduct');
await userProductHandler.handleBuyProduct(cq);
});
callbackRouter.registerPrefix('pay_with_', async (cq) => {
logDebug(cq.data, 'handlePay');
await userProductHandler.handlePay(cq);
});
callbackRouter.registerPrefix('list_purchases_', async (cq) => {
logDebug(cq.data, 'handlePurchaseListPage');
await userPurchaseHandler.handlePurchaseListPage(cq);
});
callbackRouter.registerPrefix('view_purchase_', async (cq) => {
logDebug(cq.data, 'viewPurchase');
await userPurchaseHandler.viewPurchase(cq);
});
callbackRouter.registerPrefix('confirm_received_', async (cq) => {
logDebug(cq.data, 'handleConfirmReceived');
await userPurchaseHandler.handleConfirmReceived(cq);
});
callbackRouter.registerPrefix('confirm_delete_location_', async (cq) => {
logDebug(cq.data, 'handleConfirmDelete');
await adminLocationHandler.handleConfirmDelete(cq);
});
callbackRouter.registerPrefix('prod_country_', async (cq) => {
logDebug(cq.data, 'handleCountrySelection');
await productHandler.handleCountrySelection(cq);
});
callbackRouter.registerPrefix('prod_city_', async (cq) => {
logDebug(cq.data, 'handleCitySelection');
await productHandler.handleCitySelection(cq);
});
callbackRouter.registerPrefix('prod_loc_', async (cq) => {
logDebug(cq.data, 'handleDistrictSelection');
await productHandler.handleDistrictSelection(cq);
});
callbackRouter.registerPrefix('add_category_', async (cq) => {
logDebug(cq.data, 'handleAddCategory');
await productHandler.handleAddCategory(cq);
});
callbackRouter.registerPrefix('edit_category_', async (cq) => {
logDebug(cq.data, 'handleEditCategory');
await productHandler.handleEditCategory(cq);
});
callbackRouter.registerPrefix('prod_category_', async (cq) => {
logDebug(cq.data, 'handleCategorySelection');
await productHandler.handleCategorySelection(cq);
});
callbackRouter.registerPrefix('list_products_', async (cq) => {
logDebug(cq.data, 'handleProductListPage');
await productHandler.handleProductListPage(cq);
});
callbackRouter.registerPrefix('add_product_', async (cq) => {
logDebug(cq.data, 'handleAddProduct');
await productHandler.handleAddProduct(cq);
});
callbackRouter.registerPrefix('view_product_', async (cq) => {
logDebug(cq.data, 'handleViewProduct');
await productHandler.handleViewProduct(cq);
});
callbackRouter.registerPrefix('edit_product_', async (cq) => {
logDebug(cq.data, 'handleProductEdit');
await productHandler.handleProductEdit(cq);
});
callbackRouter.registerPrefix('delete_product_', async (cq) => {
logDebug(cq.data, 'handleProductDelete');
await productHandler.handleProductDelete(cq);
});
callbackRouter.registerPrefix('confirm_delete_product_', async (cq) => {
logDebug(cq.data, 'handleConfirmDelete');
await productHandler.handleConfirmDelete(cq);
});
callbackRouter.registerPrefix('view_user_', async (cq) => {
logDebug(cq.data, 'handleViewUser');
await adminUserHandler.handleViewUser(cq);
});
callbackRouter.registerPrefix('list_users_', async (cq) => {
logDebug(cq.data, 'handleUserListPage');
await adminUserHandler.handleUserListPage(cq);
});
callbackRouter.registerPrefix('delete_user_', async (cq) => {
logDebug(cq.data, 'handleDeleteUser');
await adminUserHandler.handleDeleteUser(cq);
});
callbackRouter.registerPrefix('block_user_', async (cq) => {
logDebug(cq.data, 'handleBlockUser');
await adminUserHandler.handleBlockUser(cq);
});
callbackRouter.registerPrefix('confirm_delete_user_', async (cq) => {
logDebug(cq.data, 'handleConfirmDelete');
await adminUserHandler.handleConfirmDelete(cq);
});
callbackRouter.registerPrefix('confirm_block_user_', async (cq) => {
logDebug(cq.data, 'handleConfirmBlock');
await adminUserHandler.handleConfirmBlock(cq);
});
callbackRouter.registerPrefix('edit_user_balance_', async (cq) => {
logDebug(cq.data, 'handleEditUserBalance');
await adminUserHandler.handleEditUserBalance(cq);
});
callbackRouter.registerPrefix('edit_user_location_', async (cq) => {
logDebug(cq.data, 'handleEditUserLocation');
await adminUserLocationHandler.handleEditUserLocation(cq);
});
callbackRouter.registerPrefix('edit_user_country_', async (cq) => {
logDebug(cq.data, 'handleEditUserCountry');
await adminUserLocationHandler.handleEditUserCountry(cq);
});
callbackRouter.registerPrefix('edit_user_city_', async (cq) => {
logDebug(cq.data, 'handleEditUserCity');
await adminUserLocationHandler.handleEditUserCity(cq);
});
callbackRouter.registerPrefix('edit_user_district_', async (cq) => {
logDebug(cq.data, 'handleEditUserDistrict');
await adminUserLocationHandler.handleEditUserDistrict(cq);
});
callbackRouter.registerPrefix('wallet_type_', async (cq) => {
logDebug(cq.data, 'handleWalletTypeSelection');
await adminWalletsHandler.handleWalletTypeSelection(cq);
});
callbackRouter.registerPrefix('check_balance_', async (cq) => {
logDebug(cq.data, 'handleCheckCommissionBalance');
await adminWalletsHandler.handleCheckCommissionBalance(cq);
});
callbackRouter.registerPrefix('prev_page_', async (cq) => {
logDebug(cq.data, 'handlePagination');
await adminWalletsHandler.handlePagination(cq);
});
callbackRouter.registerPrefix('next_page_', async (cq) => {
logDebug(cq.data, 'handlePagination');
await adminWalletsHandler.handlePagination(cq);
});
callbackRouter.registerPrefix('confirm_export_', async (cq) => {
logDebug(cq.data, 'handleConfirmExport');
await adminWalletsHandler.handleConfirmExport(cq);
});
callbackRouter.registerPrefix('export_csv_', async (cq) => {
logDebug(cq.data, 'handleExportCSV');
await adminWalletsHandler.handleExportCSV(cq);
});
callbackRouter.registerPrefix('view_transaction_history_', async (cq) => {
logDebug(cq.data, 'handleTransactionHistory');
const page = parseInt(cq.data.split('_').pop());
await userWalletsHandler.handleTransactionHistory(cq, page);
});
}