Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
720 stars 144 forks source link

Issue with routers and TextCommands #172

Closed Gigiman closed 7 years ago

Gigiman commented 7 years ago

My buttons dont work on first tap after first command is executed. I have to tap twice to get Controllers working. E.g. after /start is executed I have to tap twice on button 'Русский язык', to get .when(new TextCommand('Русский язык', 'mainPageRuCommand'), new MainRuController()) working. What is wrong with my code?

`class LanguageController extends TelegramBaseController { languageHandler($) { $.runMenu({ options: {parse_mode: 'Markdown'}, message: 'Выберите:', layout: 1, 'Русский язык 🇷🇺': () => {}, 'Английский язык': () => {}, }); } get routes() { return { 'languageCommand': 'languageHandler' }; } };

class MainRuController extends TelegramBaseController { mainPageRuHandler($) { $.runMenu({ message: 'Выберите раздел', layout: 2, 'Фотогалерея': () => {}, 'Меню': () => {}, 'О нас': () => {}, 'Видео': () => {}, 'Контакты': () => {}, 'Доставка': () => {}, 'Заказать столик': () => {}, 'Конкурсы': () => {}, }); } get routes() { console.log('s'); return { 'mainPageRuCommand': 'mainPageRuHandler' }; } };

class OtherwiseController extends TelegramBaseController { handle($) { $.sendMessage('Я вас не понимаю'); } };

tg.router.when(new TextCommand('start', 'languageCommand'), new LanguageController()) .when(new TextCommand('Русский язык', 'mainPageRuCommand'), new MainRuController()) .when(new TextCommand('О нас', 'aboutCommand'), new AboutController()) .when(new TextCommand('Контакты', 'contactCommand'), new ContactsController()) .otherwise(new OtherwiseController());`