Giter Club home page Giter Club logo

Comments (9)

Bibo-Joshi avatar Bibo-Joshi commented on June 10, 2024 1

See #4207. @aiastia maybe you can install fro that branch and double check if that fixes the problem for you?

from python-telegram-bot.

aiastia avatar aiastia commented on June 10, 2024 1

It worked. Thank you so much

from python-telegram-bot.

Bibo-Joshi avatar Bibo-Joshi commented on June 10, 2024

Hi. Thanks for reaching out. I tried to reproduce the behavior, but don't see an issue. What I've tried is the following.

Use this mwe:

import logging

from telegram import Update
from telegram.ext import (
    ApplicationBuilder,
    ContextTypes,
    MessageHandler,
    filters,
    Defaults,
)

logging.basicConfig(
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.WARNING
)
# set higher logging level for httpx to avoid all GET and POST requests being logged
logging.getLogger("telegram.Bot").setLevel(logging.DEBUG)
logging.getLogger("telegram.ext.ExtBot").setLevel(logging.DEBUG)


async def callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    chat_type = update.message.chat.type
    has_topics = bool(update.message.message_thread_id)
    await update.message.reply_text(
        f"Test reply for chat of type: {chat_type} with topics: {has_topics}",
        message_thread_id=None,
    )


if __name__ == "__main__":

    application = (
        ApplicationBuilder()
        .token("TOKEN")
        # I've tried with and without defaults.
        .defaults(Defaults(do_quote=True))
        .build()
    )
    application.add_handler(MessageHandler(filters.TEXT, callback))

    application.run_polling(allowed_updates=Update.ALL_TYPES)

Then I've sent messages to the bot in the following chats:

  1. private chat
  2. group chat
  3. general topic of a forum group
  4. special topic of a forum group

Everything worked as expected for me.

Can you please provide an MWE along with instructions on how to trigger the exception? Please mention group type, privacy settings of the bot, and any other relevant parameters.

from python-telegram-bot.

aiastia avatar aiastia commented on June 10, 2024
import logging

from telegram import Update
from telegram.ext import (
    ApplicationBuilder,
    ContextTypes,
    MessageHandler,
    filters,
    Defaults,CommandHandler,
)

logging.basicConfig(
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.WARNING
)
# set higher logging level for httpx to avoid all GET and POST requests being logged
logging.getLogger("telegram.Bot").setLevel(logging.DEBUG)
logging.getLogger("telegram.ext.ExtBot").setLevel(logging.DEBUG)


async def callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    chat_type = update.message.chat.type
    has_topics = bool(update.message.message_thread_id)
    await update.message.reply_text(
        f"Test reply for chat of type: {chat_type} with topics: {has_topics}",
        message_thread_id=None,
    )


if __name__ == "__main__":

    application = (
        ApplicationBuilder()
        .token("token")
        # I've tried with and without defaults.
        .defaults(Defaults(do_quote=True))
        .build()
    )
    #application.add_handler(MessageHandler(filters.TEXT, callback))
    application.add_handler(CommandHandler("ja", callback))
    application.run_polling(allowed_updates=Update.ALL_TYPES)

from python-telegram-bot.

aiastia avatar aiastia commented on June 10, 2024

Like this, when you use the ja command in this group, it works normally, but when you use ja to reply to a message in the group, an error message is reported.

from python-telegram-bot.

aiastia avatar aiastia commented on June 10, 2024

Can you see the picture? If you use the command like the picture, you will get an error. like this
IMG_1361

from python-telegram-bot.

aiastia avatar aiastia commented on June 10, 2024

IMG_1362

from python-telegram-bot.

Bibo-Joshi avatar Bibo-Joshi commented on June 10, 2024

Thanks for elaborating (though in the future, please send 1 comment instead of several and paste monospaced text instead of posting screenshots 😉 )

I think I found the issued

Message.message_thread_id can signify either the id of a forum topic. Or it can be the message_id of a message this message is a reply to. We have no way of knownig which one it is.
However, the parameter message_thread_id of send_message accepts only ids of forum topics. Passing a message id is not allowed (instead reply_parameters must be used).

My first idea was that we can fix that, by checking if Message.message_thread_id == Message.reply_to_message.message_id. however, this doesn't work either because:

Message 1

Message 2

Message 3

Here, Message3 will have message_thread_id==1 even though reply_to_message.message_id==2. I.e., 3 is a reply to 2, but since 2 is a reply to 1, the thread is the one of message 1.

TBH at first glance, I don't think how we can make this work reliably as long as we don't know if message_thread_id originates from a forum topic or from a message_id.


As a side note: if we get this to work, we should make reply_*.param.message_thread_id default to DEFAULT_NONE such that passing None actually removes the parameter.

from python-telegram-bot.

Bibo-Joshi avatar Bibo-Joshi commented on June 10, 2024

Poolitzer thankfully pointed me to Message.is_topic_message which is true exactly in the cases where message_thread_id is the id of a forum topic :) that way we can make it work. Have implemented most of the changes already and will open a PR shortly

from python-telegram-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.