ehForwarderBot / efb-telegram-master

EFB Telegram Master Channel, a channel for EH Forwarder Bot.
GNU Affero General Public License v3.0
223 stars 79 forks source link

[BUG] Unexpected backslashes in forwarded messages #109

Open SharzyL opened 3 years ago

SharzyL commented 3 years ago

Describe the bug
When EFB forward a message from ETM to EWS, under some circumstances there will be unexpected backslashes in messages in WeChat.

To Reproduce
Steps to reproduce the behavior:

  1. Set up EFB to sync messages between Telegram and WeChat
  2. Send a message in Telegram with the following content:
    URL
    ---------------

    where URL is a URL with address tg://user?id=629325599

Now the message is forwarded to WeChat, but its content is strange:

[URL](tg://user?id=629325599) 
\- \- \- \- \- \- \- \- \- \- \- \- \- \- \-

Expected behavior
The message forwarded to WeChat should be something like:

[URL](tg://user?id=629325599) 
---------------

or

URL
---------------

Version information (please complete the following information):

EH Forwarder Bot
Version: 2.1.0
Python version:
3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]
Running on profile "wechat2tg".

Master channel:
    Telegram Master (blueset.telegram) 2.2.3 # Default instance

Slave channel:
    WeChat Slave (blueset.wechat) 2.0.4 # Default instance

Middleware:
    Search Message Middleware (catbaron.search_msg) 0.1.0 # Default instance

Additional context
If we downgrade efb-telegram-master from 2.2.3 to 2.2.2, everything goes OK.

blueset commented 3 years ago

Thanks for the report.

This was a known issue in a ETM dependency python-telegram-bot, and has been fixed in version 13.2.

Please try to upgrade your python-telegram-bot locally and see if it fixes the issue. The latest version is version.

SharzyL commented 3 years ago

I have upgraded python-telegram-bot to 13.4.1. The versions of other dependencies keep unchanged. But the backslashes still exists.

By the way, it is noteworthy that downgrading efb-telegram-master from 2.2.3 to 2.2.2 fixes the problem.

blueset commented 3 years ago

Thanks again for the report. I can reproduce this behavior in my dev environment.

After inspection, I can confirm that this is an intended behavior by Telegram Bot specs. Telegram MarkdownV2 requires all of the following characters to be escaped when not used as a part of its semantics:

_*[]()~`>#+-=|{}.!

In ETM, we are avoiding such escape to happen when there is no any sort of formatting going on in the message. However, if any Markdown formatting is found, we kept all the escapes per Telegram’s syntax. This is resulting - to be escaped as \-.

By far this is the intended behavior. If you have any idea on improving this, feel free to leave a comment here. Thanks!