Open ghost opened 7 years ago
I also have the same doubt.
I do not know if this is the best way, but I was able to return the first name of the user, using scope._update._message._from._firstName
, stored in a variable and returned where I needed it.
Simply use scope.message._from
. From that you can access ._id
, ._firstName
and so on.
Hello guys, I'm pretty new in Telegram, do you have an example? I'm incorrectly making this: class StartController extends Telegram.TelegramBaseController { before(scope) { scope.someData = true
return scope
}
startHandler($){ $.sendMessage('Good and bright day' + scope._update._message._from._firstName);
}
sorry for english im from spain
Scope is $. So for userId you can use: const userId = $.chatId; (because userId is same as chatId)
@ghost This is how I get the userId, first_name, last_name from the scope ($)
const firstName = $.message.chat.firstName ? $.message.chat.firstName : $.message.chat.lastName;
const msg = $.message.text ? $.message.text : 'Not a text';
const userId = $.message.chat.id;
console.log(`First name: ${firstName}. Message: ${msg}. UserId: ${userId}`);
How can I get userId, first_name, last_name, etc from $ scope in controller? or is there any way to pass the User object to the controller ?