Handle Telegram BadRequest (#404)

This commit is contained in:
Vadim Stepanov 2022-08-24 15:35:01 +01:00 committed by GitHub
parent 8730a8c7e4
commit eba799abb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 15 deletions

View file

@ -136,20 +136,30 @@ def send_log_and_actions_message(self, channel_chat_id, group_chat_id, channel_m
with OkToRetry(
task=self, exc=(error.RetryAfter, error.TimedOut), compute_countdown=lambda e: getattr(e, "retry_after", 3)
):
if not log_message_sent:
telegram_client.send_message(
chat_id=group_chat_id,
message_type=TelegramMessage.LOG_MESSAGE,
alert_group=alert_group,
reply_to_message_id=reply_to_message_id,
)
if not actions_message_sent:
telegram_client.send_message(
chat_id=group_chat_id,
message_type=TelegramMessage.ACTIONS_MESSAGE,
alert_group=alert_group,
reply_to_message_id=reply_to_message_id,
)
try:
if not log_message_sent:
telegram_client.send_message(
chat_id=group_chat_id,
message_type=TelegramMessage.LOG_MESSAGE,
alert_group=alert_group,
reply_to_message_id=reply_to_message_id,
)
if not actions_message_sent:
telegram_client.send_message(
chat_id=group_chat_id,
message_type=TelegramMessage.ACTIONS_MESSAGE,
alert_group=alert_group,
reply_to_message_id=reply_to_message_id,
)
except error.BadRequest as e:
if e.message == "Chat not found":
logger.warning(
f"Could not send log and actions messages to Telegram group with id {group_chat_id} "
f"due to 'Chat not found'. alert_group {alert_group.pk}"
)
return
else:
raise
@shared_dedicated_queue_retry_task(

View file

@ -4,7 +4,7 @@ from apps.telegram.updates.update_handlers import UpdateHandler
from apps.telegram.utils import is_verification_message
USER_CONNECTED_TEXT = "Done! This Telegram account is now linked to <b>{username}</b> 🎉"
RELINK_ACCOUNT_TEXT = """This user is already connected to a Telegram account</b>
RELINK_ACCOUNT_TEXT = """This user is already connected to a Telegram account.
Please unlink Telegram account in profile settings of user <b>{username}</b> or contact Grafana OnCall support."""
WRONG_VERIFICATION_CODE = "Verification failed: wrong verification code"