Open developerium opened 6 years ago
same question. you solve it?
Hi after being done with message received, I want to redirect them to another controller of mine.
for example after user sending
/start
, I want to process what was registered for/start
and then redirect them to/hello
is there any way to achieve this functionality?
In my opinion I see 2 options,
class IntroController extends TelegramBaseController {
/**
* @param {Scope} $
*/
startHandler($) {
const scope = $;
$.sendMessage('Welcome');
this.helloHandler(scope); //call hello handler here
}
/**
* @param {Scope} $
*/
helloHandler($) {
const user = $.message.chat.firstName;
$.sendMessage(`Hello ${user}`);
}
get routes() {
return {
'startCommand': 'startHandler',
'helloCommand': 'helloHandler'
}
}
}
tg.router
.when( new TextCommand('/start', 'startCommand'), new IntroController())
.when( new TextCommand('/hello', 'helloCommand'), new IntroController())
It might not be the best solution please let me know what you think about this approach
Another simpler would be to call your hello controller in the start. Like this
class StartController extends TelegramBaseController {
startHandler($) {
const scope = $;
$.sendMessage('Welcome');
const helloController = new HelloController(); //call 2nd controller
helloController.helloHandler(scope); //Pass the scope as a variable
}
get routes() {
return {
'startCommand': 'startHandler',
}
}
}
class HelloController extends TelegramBaseController {
/**
* @param {Scope} $
*/
helloHandler($) {
const user = $.message.chat.firstName;
$.sendMessage(`Hello ${user}`);
}
get routes() {
return {
'helloCommand': 'helloHandler'
}
}
}
bot.router
.when( new TextCommand('/start', 'startCommand'), new StartController())
.when( new TextCommand('/hello', 'helloCommand'), new HelloController())
Hi after being done with message received, I want to redirect them to another controller of mine.
for example after user sending
/start
, I want to process what was registered for/start
and then redirect them to/hello
is there any way to achieve this functionality?