Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
721 stars 143 forks source link

any and otherwise don't work #71

Closed MaximBatanov closed 8 years ago

MaximBatanov commented 8 years ago

error TypeError: Cannot read property 'toString' of undefined at OtherwiseController.methodForCommand (.../TelegramBaseController.js:59:34) at controllers.forEach.e (.../MessageUpdateProcessor.js:63:44) at Array.forEach (native) at _getSession.then.session (.../MessageUpdateProcessor.js:54:33) at process._tickCallback (internal/process/next_tick.js:103:7)

I added a quick fix: (TelegramRouter.js) commandNameForUpdate(update) { /code here/ if( this._otherwiseController ) return 'otherwise'; else if( this._anyController ) return 'any'; }

Naltox commented 8 years ago

@MaximBatanov Hi! What version of module you are using? And can you show your router?

MaximBatanov commented 8 years ago

Version: 3.0.4

Naltox commented 8 years ago

@MaximBatanov Try to update, if that does not help show me your router please.

MaximBatanov commented 8 years ago

Version: 3.0.7 - the same error. My controller: class AnyController extends Telegram.TelegramBaseController { anyHandler( $ ) { console.log( JSON.stringify($.message) ); } get routes() { return { 'any': 'anyHandler', } } } bot.router.any( new AnyController() );

Naltox commented 8 years ago

@MaximBatanov Any controllers cant have routes

Naltox commented 8 years ago

@MaximBatanov use that like this:

class AnyController extends Telegram.TelegramBaseController {
    handle($) {
        //handle all messages here
    }
}

tg.router
    .any(new AnyController())
MaximBatanov commented 8 years ago

Thanks. It's work.