We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] Invalid MarkdownV1 parsing
### Steps to Reproduce

1. Call the `mention_markdown(123, "Keeping_the_underscores", version=1)` function from `telegram.helpers`

### Expected behaviour

`[Keeping_the_underscores](tg://user?id=123)`, that is valid MarkdownV1 and consistent with https://core.telegram.org/bots/api#markdown-style.

### Actual behaviour

`[Keeping\\_the\\_underscores](tg://user?id=123)`. However this will fail to parse into well-formed MarkdownV1 -- in fact Telegram will respond with an error if it occurs in a message with `parse_mode = Markdown`.

### Operating System

Linux

### Version of Python, python-telegram-bot & dependencies

```shell
python-telegram-bot==20.0a2
```


### Relevant log output

_No response_

### Additional Context

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `telegram/helpers.py`
Content:
```
1 #!/usr/bin/env python
2 #
3 # A library that provides a Python interface to the Telegram Bot API
4 # Copyright (C) 2015-2022
5 # Leandro Toledo de Souza <devs@python-telegram-bot.org>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser Public License
18 # along with this program.  If not, see [http://www.gnu.org/licenses/].
19 """This module contains convenience helper functions.
20 
21 .. versionchanged:: 20.0
22    Previously, the contents of this module were available through the (no longer existing)
23    module ``telegram.utils.helpers``.
24 """
25 
26 __all__ = (
27     "create_deep_linked_url",
28     "effective_message_type",
29     "escape_markdown",
30     "mention_html",
31     "mention_markdown",
32 )
33 
34 import re
35 from html import escape
36 from typing import TYPE_CHECKING, Optional, Union
37 
38 from telegram.constants import MessageType
39 
40 if TYPE_CHECKING:
41     from telegram import Message, Update
42 
43 
44 def escape_markdown(text: str, version: int = 1, entity_type: str = None) -> str:
45     """Helper function to escape telegram markup symbols.
46 
47     Args:
48         text (:obj:`str`): The text.
49         version (:obj:`int` | :obj:`str`): Use to specify the version of telegrams Markdown.
50             Either ``1`` or ``2``. Defaults to ``1``.
51         entity_type (:obj:`str`, optional): For the entity types
52             :tg-const:`telegram.MessageEntity.PRE`, :tg-const:`telegram.MessageEntity.CODE` and
53             the link part of :tg-const:`telegram.MessageEntity.TEXT_LINK`, only certain characters
54             need to be escaped in :tg-const:`telegram.constants.ParseMode.MARKDOWN_V2`.
55             See the official API documentation for details. Only valid in combination with
56             ``version=2``, will be ignored else.
57     """
58     if int(version) == 1:
59         escape_chars = r"_*`["
60     elif int(version) == 2:
61         if entity_type in ["pre", "code"]:
62             escape_chars = r"\`"
63         elif entity_type == "text_link":
64             escape_chars = r"\)"
65         else:
66             escape_chars = r"\_*[]()~`>#+-=|{}.!"
67     else:
68         raise ValueError("Markdown version must be either 1 or 2!")
69 
70     return re.sub(f"([{re.escape(escape_chars)}])", r"\\\1", text)
71 
72 
73 def mention_html(user_id: Union[int, str], name: str) -> str:
74     """
75     Args:
76         user_id (:obj:`int`): The user's id which you want to mention.
77         name (:obj:`str`): The name the mention is showing.
78 
79     Returns:
80         :obj:`str`: The inline mention for the user as HTML.
81     """
82     return f'<a href="tg://user?id={user_id}">{escape(name)}</a>'
83 
84 
85 def mention_markdown(user_id: Union[int, str], name: str, version: int = 1) -> str:
86     """
87     Args:
88         user_id (:obj:`int`): The user's id which you want to mention.
89         name (:obj:`str`): The name the mention is showing.
90         version (:obj:`int` | :obj:`str`): Use to specify the version of Telegram's Markdown.
91             Either ``1`` or ``2``. Defaults to ``1``.
92 
93     Returns:
94         :obj:`str`: The inline mention for the user as Markdown.
95     """
96     return f"[{escape_markdown(name, version=version)}](tg://user?id={user_id})"
97 
98 
99 def effective_message_type(entity: Union["Message", "Update"]) -> Optional[str]:
100     """
101     Extracts the type of message as a string identifier from a :class:`telegram.Message` or a
102     :class:`telegram.Update`.
103 
104     Args:
105         entity (:class:`telegram.Update` | :class:`telegram.Message`): The ``update`` or
106             ``message`` to extract from.
107 
108     Returns:
109         :obj:`str` | :obj:`None`: One of :class:`telegram.constants.MessageType` if the entity
110             contains a message that matches one of those types. :obj:`None` otherwise.
111 
112     """
113     # Importing on file-level yields cyclic Import Errors
114     from telegram import Message, Update  # pylint: disable=import-outside-toplevel
115 
116     if isinstance(entity, Message):
117         message = entity
118     elif isinstance(entity, Update):
119         if not entity.effective_message:
120             return None
121         message = entity.effective_message
122     else:
123         raise TypeError(f"The entity is neither Message nor Update (got: {type(entity)})")
124 
125     for message_type in MessageType:
126         if message[message_type]:
127             return message_type
128 
129     return None
130 
131 
132 def create_deep_linked_url(bot_username: str, payload: str = None, group: bool = False) -> str:
133     """
134     Creates a deep-linked URL for this :paramref:`bot_username` with the specified
135     :paramref:`payload`. See  https://core.telegram.org/bots#deep-linking to learn more.
136 
137     The :paramref:`payload` may consist of the following characters: ``A-Z, a-z, 0-9, _, -``
138 
139     Note:
140         Works well in conjunction with
141         ``CommandHandler("start", callback, filters=filters.Regex('payload'))``
142 
143     Examples:
144         ``create_deep_linked_url(bot.get_me().username, "some-params")``
145 
146     Args:
147         bot_username (:obj:`str`): The username to link to
148         payload (:obj:`str`, optional): Parameters to encode in the created URL
149         group (:obj:`bool`, optional): If :obj:`True` the user is prompted to select a group to
150             add the bot to. If :obj:`False`, opens a one-on-one conversation with the bot.
151             Defaults to :obj:`False`.
152 
153     Returns:
154         :obj:`str`: An URL to start the bot with specific parameters
155     """
156     if bot_username is None or len(bot_username) <= 3:
157         raise ValueError("You must provide a valid bot_username.")
158 
159     base_url = f"https://t.me/{bot_username}"
160     if not payload:
161         return base_url
162 
163     if len(payload) > 64:
164         raise ValueError("The deep-linking payload must not exceed 64 characters.")
165 
166     if not re.match(r"^[A-Za-z0-9_-]+$", payload):
167         raise ValueError(
168             "Only the following characters are allowed for deep-linked "
169             "URLs: A-Z, a-z, 0-9, _ and -"
170         )
171 
172     if group:
173         key = "startgroup"
174     else:
175         key = "start"
176 
177     return f"{base_url}?{key}={payload}"
178
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/telegram/helpers.py b/telegram/helpers.py
--- a/telegram/helpers.py
+++ b/telegram/helpers.py
@@ -93,7 +93,10 @@
     Returns:
         :obj:`str`: The inline mention for the user as Markdown.
     """
-    return f"[{escape_markdown(name, version=version)}](tg://user?id={user_id})"
+    tg_link = f"tg://user?id={user_id}"
+    if version == 1:
+        return f"[{name}]({tg_link})"
+    return f"[{escape_markdown(name, version=version)}]({tg_link})"
 
 
 def effective_message_type(entity: Union["Message", "Update"]) -> Optional[str]:

{"golden_diff": "diff --git a/telegram/helpers.py b/telegram/helpers.py\n--- a/telegram/helpers.py\n+++ b/telegram/helpers.py\n@@ -93,7 +93,10 @@\n     Returns:\n         :obj:`str`: The inline mention for the user as Markdown.\n     \"\"\"\n-    return f\"[{escape_markdown(name, version=version)}](tg://user?id={user_id})\"\n+    tg_link = f\"tg://user?id={user_id}\"\n+    if version == 1:\n+        return f\"[{name}]({tg_link})\"\n+    return f\"[{escape_markdown(name, version=version)}]({tg_link})\"\n \n \n def effective_message_type(entity: Union[\"Message\", \"Update\"]) -> Optional[str]:\n", "issue": "[BUG] Invalid MarkdownV1 parsing\n### Steps to Reproduce\r\n\r\n1. Call the `mention_markdown(123, \"Keeping_the_underscores\", version=1)` function from `telegram.helpers`\r\n\r\n### Expected behaviour\r\n\r\n`[Keeping_the_underscores](tg://user?id=123)`, that is valid MarkdownV1 and consistent with https://core.telegram.org/bots/api#markdown-style.\r\n\r\n### Actual behaviour\r\n\r\n`[Keeping\\\\_the\\\\_underscores](tg://user?id=123)`. However this will fail to parse into well-formed MarkdownV1 -- in fact Telegram will respond with an error if it occurs in a message with `parse_mode = Markdown`.\r\n\r\n### Operating System\r\n\r\nLinux\r\n\r\n### Version of Python, python-telegram-bot & dependencies\r\n\r\n```shell\r\npython-telegram-bot==20.0a2\r\n```\r\n\r\n\r\n### Relevant log output\r\n\r\n_No response_\r\n\r\n### Additional Context\r\n\r\n_No response_\n", "before_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2022\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains convenience helper functions.\n\n.. versionchanged:: 20.0\n   Previously, the contents of this module were available through the (no longer existing)\n   module ``telegram.utils.helpers``.\n\"\"\"\n\n__all__ = (\n    \"create_deep_linked_url\",\n    \"effective_message_type\",\n    \"escape_markdown\",\n    \"mention_html\",\n    \"mention_markdown\",\n)\n\nimport re\nfrom html import escape\nfrom typing import TYPE_CHECKING, Optional, Union\n\nfrom telegram.constants import MessageType\n\nif TYPE_CHECKING:\n    from telegram import Message, Update\n\n\ndef escape_markdown(text: str, version: int = 1, entity_type: str = None) -> str:\n    \"\"\"Helper function to escape telegram markup symbols.\n\n    Args:\n        text (:obj:`str`): The text.\n        version (:obj:`int` | :obj:`str`): Use to specify the version of telegrams Markdown.\n            Either ``1`` or ``2``. Defaults to ``1``.\n        entity_type (:obj:`str`, optional): For the entity types\n            :tg-const:`telegram.MessageEntity.PRE`, :tg-const:`telegram.MessageEntity.CODE` and\n            the link part of :tg-const:`telegram.MessageEntity.TEXT_LINK`, only certain characters\n            need to be escaped in :tg-const:`telegram.constants.ParseMode.MARKDOWN_V2`.\n            See the official API documentation for details. Only valid in combination with\n            ``version=2``, will be ignored else.\n    \"\"\"\n    if int(version) == 1:\n        escape_chars = r\"_*`[\"\n    elif int(version) == 2:\n        if entity_type in [\"pre\", \"code\"]:\n            escape_chars = r\"\\`\"\n        elif entity_type == \"text_link\":\n            escape_chars = r\"\\)\"\n        else:\n            escape_chars = r\"\\_*[]()~`>#+-=|{}.!\"\n    else:\n        raise ValueError(\"Markdown version must be either 1 or 2!\")\n\n    return re.sub(f\"([{re.escape(escape_chars)}])\", r\"\\\\\\1\", text)\n\n\ndef mention_html(user_id: Union[int, str], name: str) -> str:\n    \"\"\"\n    Args:\n        user_id (:obj:`int`): The user's id which you want to mention.\n        name (:obj:`str`): The name the mention is showing.\n\n    Returns:\n        :obj:`str`: The inline mention for the user as HTML.\n    \"\"\"\n    return f'<a href=\"tg://user?id={user_id}\">{escape(name)}</a>'\n\n\ndef mention_markdown(user_id: Union[int, str], name: str, version: int = 1) -> str:\n    \"\"\"\n    Args:\n        user_id (:obj:`int`): The user's id which you want to mention.\n        name (:obj:`str`): The name the mention is showing.\n        version (:obj:`int` | :obj:`str`): Use to specify the version of Telegram's Markdown.\n            Either ``1`` or ``2``. Defaults to ``1``.\n\n    Returns:\n        :obj:`str`: The inline mention for the user as Markdown.\n    \"\"\"\n    return f\"[{escape_markdown(name, version=version)}](tg://user?id={user_id})\"\n\n\ndef effective_message_type(entity: Union[\"Message\", \"Update\"]) -> Optional[str]:\n    \"\"\"\n    Extracts the type of message as a string identifier from a :class:`telegram.Message` or a\n    :class:`telegram.Update`.\n\n    Args:\n        entity (:class:`telegram.Update` | :class:`telegram.Message`): The ``update`` or\n            ``message`` to extract from.\n\n    Returns:\n        :obj:`str` | :obj:`None`: One of :class:`telegram.constants.MessageType` if the entity\n            contains a message that matches one of those types. :obj:`None` otherwise.\n\n    \"\"\"\n    # Importing on file-level yields cyclic Import Errors\n    from telegram import Message, Update  # pylint: disable=import-outside-toplevel\n\n    if isinstance(entity, Message):\n        message = entity\n    elif isinstance(entity, Update):\n        if not entity.effective_message:\n            return None\n        message = entity.effective_message\n    else:\n        raise TypeError(f\"The entity is neither Message nor Update (got: {type(entity)})\")\n\n    for message_type in MessageType:\n        if message[message_type]:\n            return message_type\n\n    return None\n\n\ndef create_deep_linked_url(bot_username: str, payload: str = None, group: bool = False) -> str:\n    \"\"\"\n    Creates a deep-linked URL for this :paramref:`bot_username` with the specified\n    :paramref:`payload`. See  https://core.telegram.org/bots#deep-linking to learn more.\n\n    The :paramref:`payload` may consist of the following characters: ``A-Z, a-z, 0-9, _, -``\n\n    Note:\n        Works well in conjunction with\n        ``CommandHandler(\"start\", callback, filters=filters.Regex('payload'))``\n\n    Examples:\n        ``create_deep_linked_url(bot.get_me().username, \"some-params\")``\n\n    Args:\n        bot_username (:obj:`str`): The username to link to\n        payload (:obj:`str`, optional): Parameters to encode in the created URL\n        group (:obj:`bool`, optional): If :obj:`True` the user is prompted to select a group to\n            add the bot to. If :obj:`False`, opens a one-on-one conversation with the bot.\n            Defaults to :obj:`False`.\n\n    Returns:\n        :obj:`str`: An URL to start the bot with specific parameters\n    \"\"\"\n    if bot_username is None or len(bot_username) <= 3:\n        raise ValueError(\"You must provide a valid bot_username.\")\n\n    base_url = f\"https://t.me/{bot_username}\"\n    if not payload:\n        return base_url\n\n    if len(payload) > 64:\n        raise ValueError(\"The deep-linking payload must not exceed 64 characters.\")\n\n    if not re.match(r\"^[A-Za-z0-9_-]+$\", payload):\n        raise ValueError(\n            \"Only the following characters are allowed for deep-linked \"\n            \"URLs: A-Z, a-z, 0-9, _ and -\"\n        )\n\n    if group:\n        key = \"startgroup\"\n    else:\n        key = \"start\"\n\n    return f\"{base_url}?{key}={payload}\"\n", "path": "telegram/helpers.py"}], "after_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2022\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains convenience helper functions.\n\n.. versionchanged:: 20.0\n   Previously, the contents of this module were available through the (no longer existing)\n   module ``telegram.utils.helpers``.\n\"\"\"\n\n__all__ = (\n    \"create_deep_linked_url\",\n    \"effective_message_type\",\n    \"escape_markdown\",\n    \"mention_html\",\n    \"mention_markdown\",\n)\n\nimport re\nfrom html import escape\nfrom typing import TYPE_CHECKING, Optional, Union\n\nfrom telegram.constants import MessageType\n\nif TYPE_CHECKING:\n    from telegram import Message, Update\n\n\ndef escape_markdown(text: str, version: int = 1, entity_type: str = None) -> str:\n    \"\"\"Helper function to escape telegram markup symbols.\n\n    Args:\n        text (:obj:`str`): The text.\n        version (:obj:`int` | :obj:`str`): Use to specify the version of telegrams Markdown.\n            Either ``1`` or ``2``. Defaults to ``1``.\n        entity_type (:obj:`str`, optional): For the entity types\n            :tg-const:`telegram.MessageEntity.PRE`, :tg-const:`telegram.MessageEntity.CODE` and\n            the link part of :tg-const:`telegram.MessageEntity.TEXT_LINK`, only certain characters\n            need to be escaped in :tg-const:`telegram.constants.ParseMode.MARKDOWN_V2`.\n            See the official API documentation for details. Only valid in combination with\n            ``version=2``, will be ignored else.\n    \"\"\"\n    if int(version) == 1:\n        escape_chars = r\"_*`[\"\n    elif int(version) == 2:\n        if entity_type in [\"pre\", \"code\"]:\n            escape_chars = r\"\\`\"\n        elif entity_type == \"text_link\":\n            escape_chars = r\"\\)\"\n        else:\n            escape_chars = r\"\\_*[]()~`>#+-=|{}.!\"\n    else:\n        raise ValueError(\"Markdown version must be either 1 or 2!\")\n\n    return re.sub(f\"([{re.escape(escape_chars)}])\", r\"\\\\\\1\", text)\n\n\ndef mention_html(user_id: Union[int, str], name: str) -> str:\n    \"\"\"\n    Args:\n        user_id (:obj:`int`): The user's id which you want to mention.\n        name (:obj:`str`): The name the mention is showing.\n\n    Returns:\n        :obj:`str`: The inline mention for the user as HTML.\n    \"\"\"\n    return f'<a href=\"tg://user?id={user_id}\">{escape(name)}</a>'\n\n\ndef mention_markdown(user_id: Union[int, str], name: str, version: int = 1) -> str:\n    \"\"\"\n    Args:\n        user_id (:obj:`int`): The user's id which you want to mention.\n        name (:obj:`str`): The name the mention is showing.\n        version (:obj:`int` | :obj:`str`): Use to specify the version of Telegram's Markdown.\n            Either ``1`` or ``2``. Defaults to ``1``.\n\n    Returns:\n        :obj:`str`: The inline mention for the user as Markdown.\n    \"\"\"\n    tg_link = f\"tg://user?id={user_id}\"\n    if version == 1:\n        return f\"[{name}]({tg_link})\"\n    return f\"[{escape_markdown(name, version=version)}]({tg_link})\"\n\n\ndef effective_message_type(entity: Union[\"Message\", \"Update\"]) -> Optional[str]:\n    \"\"\"\n    Extracts the type of message as a string identifier from a :class:`telegram.Message` or a\n    :class:`telegram.Update`.\n\n    Args:\n        entity (:class:`telegram.Update` | :class:`telegram.Message`): The ``update`` or\n            ``message`` to extract from.\n\n    Returns:\n        :obj:`str` | :obj:`None`: One of :class:`telegram.constants.MessageType` if the entity\n            contains a message that matches one of those types. :obj:`None` otherwise.\n\n    \"\"\"\n    # Importing on file-level yields cyclic Import Errors\n    from telegram import Message, Update  # pylint: disable=import-outside-toplevel\n\n    if isinstance(entity, Message):\n        message = entity\n    elif isinstance(entity, Update):\n        if not entity.effective_message:\n            return None\n        message = entity.effective_message\n    else:\n        raise TypeError(f\"The entity is neither Message nor Update (got: {type(entity)})\")\n\n    for message_type in MessageType:\n        if message[message_type]:\n            return message_type\n\n    return None\n\n\ndef create_deep_linked_url(bot_username: str, payload: str = None, group: bool = False) -> str:\n    \"\"\"\n    Creates a deep-linked URL for this :paramref:`bot_username` with the specified\n    :paramref:`payload`. See  https://core.telegram.org/bots#deep-linking to learn more.\n\n    The :paramref:`payload` may consist of the following characters: ``A-Z, a-z, 0-9, _, -``\n\n    Note:\n        Works well in conjunction with\n        ``CommandHandler(\"start\", callback, filters=filters.Regex('payload'))``\n\n    Examples:\n        ``create_deep_linked_url(bot.get_me().username, \"some-params\")``\n\n    Args:\n        bot_username (:obj:`str`): The username to link to\n        payload (:obj:`str`, optional): Parameters to encode in the created URL\n        group (:obj:`bool`, optional): If :obj:`True` the user is prompted to select a group to\n            add the bot to. If :obj:`False`, opens a one-on-one conversation with the bot.\n            Defaults to :obj:`False`.\n\n    Returns:\n        :obj:`str`: An URL to start the bot with specific parameters\n    \"\"\"\n    if bot_username is None or len(bot_username) <= 3:\n        raise ValueError(\"You must provide a valid bot_username.\")\n\n    base_url = f\"https://t.me/{bot_username}\"\n    if not payload:\n        return base_url\n\n    if len(payload) > 64:\n        raise ValueError(\"The deep-linking payload must not exceed 64 characters.\")\n\n    if not re.match(r\"^[A-Za-z0-9_-]+$\", payload):\n        raise ValueError(\n            \"Only the following characters are allowed for deep-linked \"\n            \"URLs: A-Z, a-z, 0-9, _ and -\"\n        )\n\n    if group:\n        key = \"startgroup\"\n    else:\n        key = \"start\"\n\n    return f\"{base_url}?{key}={payload}\"\n", "path": "telegram/helpers.py"}]}