Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get user's information? #173

Open
ghost opened this issue Apr 7, 2017 · 6 comments
Open

How to get user's information? #173

ghost opened this issue Apr 7, 2017 · 6 comments

Comments

@ghost
Copy link

ghost commented Apr 7, 2017

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 ?

@ghost ghost changed the title Get user's information How to get user's information? Apr 7, 2017
@ribeiroevandro
Copy link

I also have the same doubt.

@ribeiroevandro
Copy link

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.

@riccardoscotti
Copy link

Simply use scope.message._from. From that you can access ._id, ._firstName and so on.

@RobotCharly
Copy link

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

@dobrosavljevicmilos
Copy link

Scope is $.
So for userId you can use:
const userId = $.chatId;
(because userId is same as chatId)

@rotimi-best
Copy link

rotimi-best commented Nov 8, 2018

@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}`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants