Naltox / telegram-node-bot

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

Best practice to access other controllers methods #72

Closed Konfuze closed 8 years ago

Konfuze commented 8 years ago

What will be the best practice to access methods of one controller from another without creating a new instance?

For example I want to access methods of SomethingController from StartController which displays the '/start' menu.

In previous version there was a method $.routeTo('/something')

Naltox commented 8 years ago

@Konfuze Hi! There is no such opportunity yet, but i will add routeTo method soon.

Konfuze commented 8 years ago

It would be great. Thank's for quick response!

cnavigato commented 8 years ago

We use of $.routeTo extensively in the old version. Looking forward to seeing this method in version 3. Thanks you for developing this npm module!

tg.controller('MenuController', ($) => { tg.for('/menu', () => { $.runMenu({ message: '---Keyboard Menu Available---', layout: 3, 'Bud': () => {$.routeTo("/bud");}, 'Edibles': () => {$.routeTo("/edibles");}, 'Wax': () => {$.routeTo("/wax");}, 'Specials': () => {$.routeTo("/specials");}, 'Restart': () => {$.routeTo("/restart");}, 'Feedback': () => {$.routeTo("/feedback");}, 'Help': () => {$.routeTo("/help");}, 'Upload': () => {$.routeTo("/upload");}, 'Payment': () => {$.routeTo("/bitcoin");}, });
}); });

muety commented 8 years ago

Has the $.routeTo method been added yet? Looking forward to something like that, too.

osadchiynikita commented 7 years ago

As @Naltox suggested, there is emulateUpdate method, which can be used like this:

const tg = new Telegram.Telegram(token); tg.emulateUpdate($.update)

herenickname commented 7 years ago

@osadchiynikita and how to route? Where I can define the route?