cli2telegram 2.0.2__tar.gz → 2.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cli2telegram
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: Small utility to send Telegram messages from the CLI.
5
5
  License: AGPL-3.0-or-later
6
6
  License-File: LICENSE
@@ -18,6 +18,7 @@ import time
18
18
  from datetime import datetime, timedelta
19
19
 
20
20
  from telegram import Bot, InlineKeyboardMarkup, Message
21
+ from telegram.error import BadRequest, Forbidden, InvalidToken
21
22
  from telegram.ext import Application
22
23
 
23
24
  from cli2telegram import RetryLimitReachedException
@@ -88,11 +89,25 @@ async def try_send_message(
88
89
  :param give_up_after: when to give up trying
89
90
  """
90
91
  started_trying = datetime.now()
92
+ parse_mode = "markdown"
91
93
  success = False
92
94
  while not success:
93
95
  try:
94
- await send_message(bot=app.bot, chat_id=chat_id, message=message, parse_mode="markdown")
96
+ await send_message(bot=app.bot, chat_id=chat_id, message=message, parse_mode=parse_mode)
95
97
  success = True
98
+ except BadRequest as ex:
99
+ if parse_mode is not None and "parse entities" in str(ex).lower():
100
+ # characters like "_" or "*" in the text are not valid markdown, so send it as plain text
101
+ LOGGER.warning(f"Message is not valid markdown, sending it as plain text instead: {ex}")
102
+ parse_mode = None
103
+ continue
104
+ # the request itself is wrong, retrying would never help
105
+ LOGGER.exception(ex)
106
+ raise
107
+ except (InvalidToken, Forbidden) as ex:
108
+ # wrong token or the bot is not allowed to write to the chat, retrying would never help
109
+ LOGGER.exception(ex)
110
+ raise
96
111
  except Exception as ex:
97
112
  LOGGER.exception(ex)
98
113
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cli2telegram"
3
- version = "2.0.2"
3
+ version = "2.0.3"
4
4
  description = "Small utility to send Telegram messages from the CLI."
5
5
 
6
6
  license = "AGPL-3.0-or-later"
File without changes
File without changes