Comments (5)
Hi. Thanks for reaching out. We are aware of this behavior, but this is accepted and documented in the docs of text_markdown_v2. If you are interested in more background story, please have a look at the discussion in #4038.
As alternative, Telegram recommends that you work directly with Message.entities.
I expect that my answer will be unsatisfactory for you - as it is for me - but this is the current status...
from python-telegram-bot.
Hi. Thanks for reaching out. We are aware of this behavior, but this is accepted and documented in the docs of text_markdown_v2.
Thanks for the quick response and sorry, I don't know how I read the documentation and didn't see that warning.
from python-telegram-bot.
Hi. Thanks for the additional investigation. TBH I can't really form a opinion atm if this would affect any other special cases/introduce different problems. At least one point that I see is that simply checking for endswith("\n")
is not enough, since the text could actually end on an escaped \\n
.
Frankly, since TG officially discouraged us from providing these proporties, I'm not very motivated to try and cover every edge case … This is also why we included the note in the docs.
from python-telegram-bot.
If you are interested in more background story, please have a look at the discussion in #4038.
Hi again, I took some time and looked through the discussion and the code responsible for text_markdown_v2
and found the following:
insert = ">" + "\n>".join(escaped_text.splitlines())
/n
at the end of escaped_text
will be ignored by splitlines()
that is what causes behavior which I described in the issue.
When I added insert += "\n" if escaped_text.endswith("\n") else ""
my issue was solved.
But there is another, and it is more about Telegram Desktop only:
If the blockquote is immediately followed by text without \n
, the text will be attached to the blockquote, and if blockquote is immediately after text the telegram.error.BadRequest: Can't parse entities: character '>' is reserved and must be escaped with the preceding '\'
is raised.
Telegram Desktop allows writing blockquote like this
And after sending, blockquote is shown on separate line, but there is no \n
at all.
Since we know where quote actualy starts and ends, I think, it can be fixed, by adding check if there is \n
in the beginning and ending of blockquote, and adding it if needed.
I changed localy:
python-telegram-bot/telegram/_message.py
Line 4562 in ee88973
to this:
elif entity.type == MessageEntity.BLOCKQUOTE:
# Check if there's no \n before blockquote and blockquote is not at the beginning of message
if message_text[entity.offset - 1] != "\n" and entity.offset != 0:
insert = "\n>" + "\n>".join(escaped_text.splitlines())
insert += "\n" if escaped_text.endswith("\n") else ""
else:
insert = ">" + "\n>".join(escaped_text.splitlines())
insert += "\n" if escaped_text.endswith("\n") else ""
# Check if blockquote is not the last thing in message
if entity.length + entity.offset != len(message_text):
# Check if there's an \n after blockquote
if message_text[entity.length + entity.offset] != "\n" and not escaped_text.endswith("\n"):
insert += "\n"
And everything works as expected.
Maybe adding \n
which was not there before is bad, but it should be there according to Telegram's recommendations as in that, mentioned earlier, warning:
Telegram recommends that entities of type BLOCKQUOTE and PRE should start and end on a new line
Hope this will help resolve the issue.
from python-telegram-bot.
Ok.
Thank you for your time.
from python-telegram-bot.
Related Issues (20)
- [QUESTION] running other coroutines along with run_poll HOT 2
- [Type Hinting] `EncryptedCredentials.decrypted_secret` is not properly annotated HOT 2
- [QUESTION] problem with reading timeout. HOT 2
- [BUG] `Message.reply_text` leads to `Message thread not found` HOT 9
- Spelled wrong
- My TeamViewer ID HOT 1
- [BUG] `App.post_stop` is called even if `App.stop` is not called
- My TeamViewer ID HOT 1
- [QUESTION] 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
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.