@
@
@eingod2018-12-03 06:57:52
Node.js
@eingod, 2018-12-03 06:57:52

Telegram Bot node js - How to get user id?

In general, the task is this: I need to give the user his own ID in the message. How can this be implemented?
I am using node-telegram-bot-api. Tried like this:

var idforuser = bot.user_id;

bot.on('message', (msg) => {
if (msg.text.toLowerCase() === "мой айди"){
bot.sendMessage(msg.chat.id, "Это твой айди - " + idforuser, menu)
}
});

But when executed, it says: "Here is your ID - undefined".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eingod, 2018-12-03
_

Decisionmsg.from.id

M
Maxim Kuvardin, 2018-12-03
@Kuvardin

The user ID comes in the from object. See https://t.me/RequestCodeBot for the structure of requests to bots

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question