DEV Community

Cover image for Stop logging print(): Inspect Telegram Payloads Instantly
Roman
Roman

Posted on

Stop logging print(): Inspect Telegram Payloads Instantly

If you build Telegram bots—whether in Python (aiogram, python-telegram-bot), Node.js (Telegraf), or Go—you know the pain of the "Blind Webhook" cycle.

You want to handle a specific event, like a user forwarding a message or sending a sticker. But you aren't quite sure what the payload structure looks like.

Usually, the workflow looks like this:

  1. Add print(update) or console.log(ctx) to your code.
  2. Redeploy or restart the polling script.
  3. Send the message to your bot.
  4. Dig through terminal logs to find the JSON.
  5. Copy-paste it into a JSON formatter.

It’s inefficient.

I got tired of ad-ridden "ID bots" and the deployment loop just to inspect a payload. So, I built a compliant, stateless tool to solve this cleanly: @re_GetMyIDBot.

The Problem: Guessing JSON Structures

Telegram's API documentation is excellent, but it doesn't always reflect the exact nuance of the data you receive in real-time.

  • Where exactly is the file_id located in a sticker object?
  • Does a forwarded message from a hidden user return a user_id or a sender_name?
  • What is the chat_id of this channel for my .env file?

To answer these, we usually clutter our production code with debug statements.

The Solution: A DevTool, Not Just a Bot

@re_GetMyIDBot is designed as a utility for your toolkit, sitting alongside Postman and Git. It adheres to the UNIX philosophy: Do one thing and do it well.

Feature 1: The "Get JSON" Inspector 🛠

This is the killer feature. When you forward a message, send a photo, or interact with the bot, it offers an inline button: [ Get JSON ].

Clicking it fetches the raw Update object associated with that message. No logging required.

Result of

Example Scenario:
You need to see how a document payload looks. You drop a file into the bot and click [Get JSON]. You get this instantly:

{
  "message_id": 451,
  "from": {
    "id": 123456789,
    "is_bot": false,
    "first_name": "Alex",
    "language_code": "en"
  },
  "chat": {
    "id": 123456789,
    "type": "private"
  },
  "date": 1706892345,
  "document": {
    "file_name": "deployment_logs.txt",
    "mime_type": "text/plain",
    "file_id": "BQACAgIAAxkBAAM...",
    "file_unique_id": "AgAD...",
    "file_size": 2048
  }
}
Enter fullscreen mode Exit fullscreen mode

Now you know exactly how to parse update.message.document.file_id.

Feature 2: Instant Copy-Paste IDs 📋

Most bots return the Chat ID. This bot returns user_id, chat_id, and channel_id formatted in monospace.

Return the Chat ID

Why monospace? Because on mobile and desktop, single-tapping monospace text automatically copies it to the clipboard. It streamlines setting up your .env config variables.

# No more manually typing IDs
TELEGRAM_ADMIN_ID=123456789
LOG_CHANNEL_ID=-100987654321
Enter fullscreen mode Exit fullscreen mode

Feature 3: Forwarding and Channel Debugging

If you forward a message from a Channel to the bot, it extracts the hidden metadata. This is the fastest way to find a Channel ID (-100...) without adding the bot to the channel as an admin first.

Why I Built It

There are plenty of "ID Bots" on Telegram. Most of them suffer from two issues:

  1. Spam/Ads: They push ads for other channels every time you check an ID.
  2. Limited Scope: They only give you the ID, not the payload context.

I wanted a clean, fast, zero-dependency tool for developers. No ads, no spam, just the data.

Try it out

Next time you are stuck guessing whether the field is called caption or text, or you just need to grab your ID for a config file, save yourself the redeploy.

🚀 Bot Link: @re_GetMyIDBot

Happy debugging.

Top comments (0)