Naltox / telegram-node-bot

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

Right way of using 'otherwise' #60

Closed kamikazechaser closed 8 years ago

kamikazechaser commented 8 years ago

I am getting errors when trying to set-up the otherwise controller. What is the correct way of setting up the otherwise controller, say for example to message someone with "command not found". An example would be good.

Naltox commented 8 years ago

Hi! Do it like this:

'use strict'

const Telegram = require('telegram-node-bot')
const TelegramBaseController = Telegram.TelegramBaseController
const tg = new Telegram.Telegram('TOKEN')

class PingController extends TelegramBaseController {
    /**
     * @param {Scope} $
     */
    pingHandler($) {
        $.sendMessage('pong')
    }

    get routes() {
        return {
            'ping': 'pingHandler'
        }
    }
}

class OtherwiseController extends TelegramBaseController {
    handle() {
        console.log('otherwise')
    }
}

tg.router
    .when(['ping'], new PingController())
    .otherwise(new OtherwiseController())