Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
720 stars 144 forks source link

How to get user's information? #173

Open ghost opened 7 years ago

ghost commented 7 years ago

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 ?

ribeiroevandro commented 7 years ago

I also have the same doubt.

ribeiroevandro commented 7 years ago

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 commented 7 years ago

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

RobotCharly commented 6 years ago

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 commented 6 years ago

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

rotimi-best commented 5 years ago

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