Writing
Telegram group statistics: an open-source bot you can self-host
Telegram shows you how many people are in a group. I wanted to know what was happening inside it. Who actually talks? When does the chat get busy? Has activity changed since last month? The member count doesn’t answer those questions.
I built History Bot to keep track of that activity. It works with messages Telegram sends to the bot after you add it to a group. The source code is on GitHub under the MIT license. You can use my hosted bot or deploy your own copy.
What it tracks
History Bot counts messages and words, tracks who’s active, and shows how activity changes over time. A few useful commands:
/top: most active members today./activity_weekand/activity_month: activity charts./activity_users_week: activity by member./summary: optional summaries, if you’ve configured them.
There are screenshots on the project site. I also put together a comparison with Combot, because the tools overlap a little. History Bot is for statistics. For anti-spam and moderation, you’d still want a tool built for those jobs.
Try it in a group
Add @stat_history_bot to your Telegram group and send /help to see the commands.
The bot needs some activity before the charts are worth looking at. It can’t pull in messages from before it joined. Telegram’s privacy settings also affect which group messages it receives, so you may need to give it access to ordinary messages to get complete statistics.
Run your own copy on Cloudflare
I made a deployment option for anyone who’d rather keep their own bot token and infrastructure. It runs as a separate installation in your Cloudflare account, using Workers and Cloudflare’s data services. You don’t need to run a server yourself.
- Create a bot with @BotFather and copy its token.
- Open Deploy to Cloudflare. Pick your Cloudflare account and add the token as the
TOKENsecret. - Check that the deploy command is
npm run deploy. It creates the required resources and runs the database migrations. - Open your new Worker’s URL. It will redirect to
/admin/setup. Sign in using the BotFather token, check the database, then choose Connect webhook. - Add the new bot to your group. If you want it to track regular messages and not just commands, check
/setprivacyin BotFather. After changing that setting, re-add the bot.
The self-hosting guide has the rest of the setup and upgrade details. The basic installation starts with activity statistics. AI summaries and advanced analysis are optional.
The limits
History Bot only knows about messages Telegram delivers to it. It can’t see earlier conversations or get around a group’s permissions, so the statistics reflect the activity it has actually observed.
If you try it, give it a few days in an active group before judging the weekly chart.