Comments (9)
See #4207. @aiastia maybe you can install fro that branch and double check if that fixes the problem for you?
from python-telegram-bot.
It worked. Thank you so much
from python-telegram-bot.
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:
- private chat
- group chat
- general topic of a forum group
- 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.
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.
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.
Can you see the picture? If you use the command like the picture, you will get an error. like this
from python-telegram-bot.
from python-telegram-bot.
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.
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)
- [QUESTION] HOT 5
- [BUG] Getting text_markdown_v2 from message does not always work correctly when the message contains blockquote entities HOT 5
- [BUG] `InlineKeyboardMarkup` does not appear with `send_photo()` HOT 3
- [QUESTION] Get User "Typing" behavior HOT 2
- [FEATURE] API 7.3 HOT 3
- [BUG] Can't get the first example in the documentation to work HOT 3
- Typo in documentation HOT 1
- [ERROR]"Unable to import 'Filters' from 'telegram.ext' in python-telegram-bot library" HOT 3
- Remove Functionality Deprecated by API 7.3
- [QUESTION] Having multiple CallbackQueryHandlers inside a ConversationHandler HOT 5
- [QUESTION] echobot.py is not working. HOT 4
- HTML tag in user's profile name makes problem in parse html HOT 3
- [FEATURE] Make has_args in CommandHandler accept str / pattern in addition to None, bool and int HOT 2
- [FEATURE] Add version deprecated information to PTB raised warnings HOT 2
- cant use proxies in telegram-python-bot [BUG] HOT 5
- [BUG] Timeout when start polling HOT 3
- CallbackQueryHandler to support filtering game_short_name HOT 1
- [FEATURE] API 7.4
- [FEATURE] Automate adding some of the new API features using python script
- [FEATURE] Add chat_id in ChatMemberHandler to Filter Specific Chat(s) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-telegram-bot.