1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Building a Telegram bot

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    Hi I am currently building a telegram bot and I want to generate alerts throught the bot with different functnality the issue is I have completed the coding and everything is working fine in terminal and in telegram but the bot isnt generating alerts everyother functionality is working chatgpt told me to save the hat id but that doesnt make sense as we will have to add a chat id for every group and every person can someone tell me what is an easy way

    Here’s a clean, copy-pasteable version you can drop into the “What did you try and what were you expecting?” field:


    I’m building a Telegram bot (Python, python-telegram-bot with Application/CommandHandler/MessageHandler). The bot works for commands and replies (both in terminal logs and in Telegram), but alert messages I generate from my app logic never reach chats. In the terminal I can see the alert text being produced, but no message appears in Telegram.

    What I tried

    • Verified the bot can send a normal reply (update.message.reply_text) — works.
    • Triggered the same alert function manually with a hardcoded chat_id — works.
    • Tried using the chat.id I got from a private /start message — alerts then go to me, but I don’t want to hardcode IDs for every user/group.
    • Added the bot to a group and made it admin; sent messages to create activity; still no alerts delivered unless I hardcode that group’s chat.id.
    • Confirmed handlers are running (console shows alert generation), and there’s no exception from Telegram API in my logs.

    What I expected

    • When a user starts the bot or the bot is added to a group, I expected to capture/store that chat’s chat.id automatically (e.g., via /start or my_chat_member/chat_member updates) so the bot can broadcast alerts to all subscribed chats without manually entering IDs.

    What actually happened

    • Alerts only send if I manually paste a specific chat.id into the code/config. Otherwise, alerts are generated (visible in terminal) but not sent to any chat.

    Why I’m stuck

    • ChatGPT suggested “save the chat id,” but that implies collecting and maintaining a chat.id for every user/group by hand, which isn’t scalable. I’m looking for the right pattern to auto-capture and manage chat IDs (e.g., on /start in DMs and on my_chat_member when added to a group), and then broadcast alerts to those “subscribed” chats.

    Environment

    • Python with python-telegram-bot (v20+), polling (not webhook).
    • Handlers imported like: from telegram.ext import Application, CommandHandler, MessageHandler, filters.

    If helpful, I can share a minimal snippet of how I’m generating/sending the alert and where I’m pulling chat.id.

    Continue reading...

Compartilhe esta Página