I’m working on a Telegram bot project and need to figure out how to detect whether a specific user is currently active or inactive. My instructor gave me this assignment but I’m struggling to find any documentation or examples online about checking user presence status.
api.on('status_check', async (message) => {
// Need to implement user activity detection here
const userId = message.from.id;
})
I have the user IDs available but I’m not sure if the Telegram Bot API actually provides this functionality. Has anyone successfully implemented something like this before? What methods or endpoints should I be looking at?
totally get that! it sucks that you can’t track exact online status. for privacy reasons, you can only see when they interacted with your bot last. so you gotta work with that info instead.
The Telegram Bot API does not allow tracking real-time user activity due to privacy constraints. A practical approach is to log the timestamps of user interactions with your bot; consider marking users as ‘active’ if they have sent a message within the last 5-10 minutes. Additionally, you can use the last_seen field from message objects to gauge recent engagement. If feasible, you might implement a system where users periodically send updates about their status, but this relies on their participation, which can be challenging.
Unfortunately, Telegram’s Bot API blocks access to user presence info for privacy reasons. Here’s a workaround: build a pseudo-activity tracker using your database. Every time someone messages or interacts with your bot, save their user ID with a timestamp. Then write a function that checks if their last activity was within your threshold (say 3-5 minutes) to mark them as “active”. It’s not real-time presence like other platforms, but it’s a solid approximation based on actual bot usage. Just make sure to handle users who’ve never interacted with your bot.