Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the user's "Last Seen" from a Telegram bot?

Tags:

telegram-bot

When I chat with a telegram user, I can see for each user their "last seen" - when they last connected to Telegram (even if I haven't chatted with them for a while).

Is there a way to query for this information via the bot API? I haven't found a way to access it.

like image 807
ripper234 Avatar asked Jun 30 '16 18:06

ripper234


People also ask

How does Telegram last seen work?

Last seen recently — covers anything between 1 second and 2-3 days. Last seen within a week — between 2-3 and seven days. Last seen within a month — between 6-7 days and a month. Last seen a long time ago — more than a month (this is also always shown to blocked users)

Can a Telegram Bot send message to user?

In order to send a message to "@Username", you will need them to start your bot, and then store the username with the user_id. Then, you can input the username to find the correct user_id each time you want to send them a message.

How can I know Telegram Bot owner?

It's impossible to see the owner of a Telegram Bot according to Telegram MTProto protocol. Probably only Bot Support and Telegram Abuse has access to this informations.


2 Answers

It's not possible with the Telegram Bot API. But it's possible with Telegram API which allows you to build your own customized Telegram clients, and have other methods like read messages, or status (limited by the target users' privacy settings, of course).

After generate an hash to authenticate your API client on my telegram, you can use a library like Telegram-MTProto to call contacts.getStatuses which return an array of ContactStatus and know if user is online or offline.

const getStatuses = async () => {
    const statuses = await telegram('contacts.getStatuses', {})
    // Check online status
    if(statuses[0].status._ === 'userStatusOnline')
        // Online
}
like image 70
Xamrix Avatar answered Jan 03 '23 21:01

Xamrix


That's currently not possible with the Telegram Bot API.

like image 36
Maak Avatar answered Jan 03 '23 20:01

Maak