Change wording from "incident" to "alert group" in the Telegram app (#1052)
# What this PR does Makes Telegram integration consistent with the rest of the system so it uses the word "alert group" instead of "incident" when referring to alert groups. ## Checklist - [x] Tests updated - [ ] Documentation added (N/A) - [x] `CHANGELOG.md` updated
This commit is contained in:
parent
9503a77579
commit
0d4701bd81
9 changed files with 73 additions and 25 deletions
15
CHANGELOG.md
15
CHANGELOG.md
|
|
@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## v1.1.14 (TBD)
|
||||
|
||||
### Added
|
||||
|
||||
- TBD
|
||||
|
||||
### Changed
|
||||
|
||||
- Change wording from "incident" to "alert group" for the Telegram integration ([#1052](https://github.com/grafana/oncall/pull/1052))
|
||||
- TBD
|
||||
|
||||
### Fixed
|
||||
|
||||
- TBD
|
||||
|
||||
## v1.1.13 (2023-01-04)
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.16 on 2022-12-29 14:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('telegram', '0001_squashed_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='telegrammessage',
|
||||
name='message_type',
|
||||
field=models.IntegerField(choices=[(0, 'Alert group message'), (1, 'Actions message'), (2, 'Log message'), (3, 'Alert can not be rendered'), (4, 'Alert group message with action buttons and alert group log'), (5, 'Link to channel message'), (6, 'Link to channel message without title')]),
|
||||
),
|
||||
]
|
||||
|
|
@ -5,11 +5,13 @@ from apps.alerts.models import AlertGroup
|
|||
from apps.base.models import UserNotificationPolicy, UserNotificationPolicyLogRecord
|
||||
from apps.telegram.client import TelegramClient
|
||||
from apps.telegram.models import TelegramMessage, TelegramToOrganizationConnector
|
||||
from apps.telegram.tasks import send_link_to_channel_message_or_fallback_to_full_incident
|
||||
from apps.telegram.tasks import send_link_to_channel_message_or_fallback_to_full_alert_group
|
||||
from apps.user_management.models import User
|
||||
|
||||
ONE_MORE_NOTIFICATION = "One more notification about this ☝"
|
||||
ALERT_CANT_BE_RENDERED = "You have a new incident, but Telegram can't render its content! Please check it out: {link}"
|
||||
ALERT_CANT_BE_RENDERED = (
|
||||
"You have a new alert group, but Telegram can't render its content! Please check it out: {link}"
|
||||
)
|
||||
|
||||
|
||||
class TelegramToUserConnector(models.Model):
|
||||
|
|
@ -39,13 +41,13 @@ class TelegramToUserConnector(models.Model):
|
|||
telegram_channel = TelegramToOrganizationConnector.get_channel_for_alert_group(alert_group)
|
||||
|
||||
if telegram_channel is not None:
|
||||
send_link_to_channel_message_or_fallback_to_full_incident.delay(
|
||||
send_link_to_channel_message_or_fallback_to_full_alert_group.delay(
|
||||
alert_group_pk=alert_group.pk,
|
||||
notification_policy_pk=notification_policy.pk,
|
||||
user_connector_pk=self.pk,
|
||||
)
|
||||
else:
|
||||
self.send_full_incident(alert_group=alert_group, notification_policy=notification_policy)
|
||||
self.send_full_alert_group(alert_group=alert_group, notification_policy=notification_policy)
|
||||
|
||||
@staticmethod
|
||||
def create_telegram_notification_error(
|
||||
|
|
@ -62,8 +64,8 @@ class TelegramToUserConnector(models.Model):
|
|||
)
|
||||
log_record.save()
|
||||
|
||||
# send the actual incident and incident log to user's DM
|
||||
def send_full_incident(self, alert_group: AlertGroup, notification_policy: UserNotificationPolicy) -> None:
|
||||
# send the actual alert group and log to user's DM
|
||||
def send_full_alert_group(self, alert_group: AlertGroup, notification_policy: UserNotificationPolicy) -> None:
|
||||
try:
|
||||
telegram_client = TelegramClient()
|
||||
except error.InvalidToken:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class TelegramMessage(models.Model):
|
|||
(ACTIONS_MESSAGE, "Actions message"),
|
||||
(LOG_MESSAGE, "Log message"),
|
||||
(FORMATTING_ERROR, "Alert can not be rendered"),
|
||||
(PERSONAL_MESSAGE, "Alert group message with action buttons and incident log"),
|
||||
(PERSONAL_MESSAGE, "Alert group message with action buttons and alert group log"),
|
||||
(LINK_TO_CHANNEL_MESSAGE, "Link to channel message"),
|
||||
(LINK_TO_CHANNEL_MESSAGE_WITHOUT_TITLE, "Link to channel message without title"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class TelegramKeyboardRenderer:
|
|||
# Inline keyboard with controls for alert group message
|
||||
def render_actions_keyboard(self) -> Optional[InlineKeyboardMarkup]:
|
||||
if self.alert_group.root_alert_group is not None:
|
||||
# No keyboard for attached incident
|
||||
# No keyboard for attached alert group
|
||||
return None
|
||||
|
||||
rows = []
|
||||
|
|
@ -65,7 +65,7 @@ class TelegramKeyboardRenderer:
|
|||
|
||||
@staticmethod
|
||||
def render_link_to_channel_keyboard(link: str) -> InlineKeyboardMarkup:
|
||||
button = InlineKeyboardButton(text="Go to the incident", url=link)
|
||||
button = InlineKeyboardButton(text="Go to the alert group", url=link)
|
||||
return InlineKeyboardMarkup([[button]])
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from apps.slack.slack_formatter import SlackFormatter
|
|||
from common.utils import is_string_with_visible_characters
|
||||
|
||||
MAX_TELEGRAM_MESSAGE_LENGTH = 4096
|
||||
MESSAGE_TRIMMED_TEXT = "\n\nMessage is trimmed! See full incident here: {link}"
|
||||
MESSAGE_TRIMMED_TEXT = "\n\nMessage is trimmed! See full alert group here: {link}"
|
||||
|
||||
|
||||
class TelegramMessageRenderer:
|
||||
|
|
@ -25,7 +25,7 @@ class TelegramMessageRenderer:
|
|||
return text
|
||||
|
||||
def render_log_message(self, max_message_length: int = MAX_TELEGRAM_MESSAGE_LENGTH) -> str:
|
||||
start_line_text = "Incident log:\n"
|
||||
start_line_text = "Alert group log:\n"
|
||||
|
||||
slack_formatter = SlackFormatter(self.alert_group.channel.organization)
|
||||
log_builder = IncidentLogBuilder(alert_group=self.alert_group)
|
||||
|
|
@ -62,10 +62,10 @@ class TelegramMessageRenderer:
|
|||
|
||||
def render_actions_message(self) -> str:
|
||||
if self.alert_group.root_alert_group is None:
|
||||
text = "Actions available for this incident"
|
||||
text = "Actions available for this alert group"
|
||||
else:
|
||||
# No actions for attached incidents
|
||||
text = "No actions are available for this incident"
|
||||
# No actions for attached alert group
|
||||
text = "No actions are available for this alert group"
|
||||
|
||||
return text
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ class TelegramMessageRenderer:
|
|||
return text
|
||||
|
||||
def render_link_to_channel_message(self, include_title: bool = True) -> str:
|
||||
text = "👀 You are invited to look at the incident!"
|
||||
text = "👀 You are invited to look at an alert group!"
|
||||
|
||||
if include_title:
|
||||
first_alert_in_group = self.alert_group.alerts.first()
|
||||
|
|
@ -91,7 +91,7 @@ class TelegramMessageRenderer:
|
|||
|
||||
def render_formatting_error_message(self) -> str:
|
||||
return (
|
||||
"You have a new incident, but Telegram can't render its content! "
|
||||
"You have a new alert group, but Telegram can't render its content! "
|
||||
f"Please check it out: {self.alert_group.web_link}"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ def edit_message(self, message_pk):
|
|||
|
||||
|
||||
@shared_dedicated_queue_retry_task(bind=True, autoretry_for=(Exception,), retry_backoff=True, max_retries=None)
|
||||
def send_link_to_channel_message_or_fallback_to_full_incident(
|
||||
def send_link_to_channel_message_or_fallback_to_full_alert_group(
|
||||
self, alert_group_pk, notification_policy_pk, user_connector_pk
|
||||
):
|
||||
TelegramToUserConnector = apps.get_model("telegram", "TelegramToUserConnector")
|
||||
|
|
@ -96,8 +96,8 @@ def send_link_to_channel_message_or_fallback_to_full_incident(
|
|||
alert_group=alert_group, notification_policy=notification_policy
|
||||
)
|
||||
else:
|
||||
# seems like the message won't appear in Telegram channel, so send the full incident to user
|
||||
user_connector.send_full_incident(alert_group=alert_group, notification_policy=notification_policy)
|
||||
# seems like the message won't appear in Telegram channel, so send the full alert group to user
|
||||
user_connector.send_full_alert_group(alert_group=alert_group, notification_policy=notification_policy)
|
||||
except TelegramToUserConnector.DoesNotExist:
|
||||
# Handle cases when user deleted the bot while escalation is active
|
||||
logger.warning(
|
||||
|
|
@ -111,6 +111,19 @@ def send_link_to_channel_message_or_fallback_to_full_incident(
|
|||
)
|
||||
|
||||
|
||||
@shared_dedicated_queue_retry_task(bind=True, autoretry_for=(Exception,), retry_backoff=True, max_retries=None)
|
||||
def send_link_to_channel_message_or_fallback_to_full_incident(
|
||||
self, alert_group_pk, notification_policy_pk, user_connector_pk
|
||||
):
|
||||
"""
|
||||
Deprecated task, use send_link_to_channel_message_or_fallback_to_full_alert_group above instead.
|
||||
TODO: remove this task after releasing the new version of the task
|
||||
"""
|
||||
send_link_to_channel_message_or_fallback_to_full_alert_group(
|
||||
self, alert_group_pk, notification_policy_pk, user_connector_pk
|
||||
)
|
||||
|
||||
|
||||
@shared_dedicated_queue_retry_task(
|
||||
bind=True, autoretry_for=(Exception,), retry_backoff=True, max_retries=1 if settings.DEBUG else None
|
||||
)
|
||||
|
|
|
|||
|
|
@ -182,6 +182,6 @@ def test_actions_keyboard_silenced(
|
|||
@pytest.mark.django_db
|
||||
def test_link_to_channel_keyboard():
|
||||
keyboard = TelegramKeyboardRenderer.render_link_to_channel_keyboard(link="http://test.com")
|
||||
expected_keyboard = [[InlineKeyboardButton(text="Go to the incident", url="http://test.com")]]
|
||||
expected_keyboard = [[InlineKeyboardButton(text="Go to the alert group", url="http://test.com")]]
|
||||
|
||||
assert are_keyboards_equal(keyboard.inline_keyboard, expected_keyboard) is True
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ def test_log_message(
|
|||
renderer = TelegramMessageRenderer(alert_group=alert_group)
|
||||
text = renderer.render_log_message()
|
||||
|
||||
assert text == f"Incident log:\n<b>0s:</b> acknowledged by {user_name}"
|
||||
assert text == f"Alert group log:\n<b>0s:</b> acknowledged by {user_name}"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
|
@ -126,7 +126,7 @@ def test_actions_message(
|
|||
renderer = TelegramMessageRenderer(alert_group=alert_group)
|
||||
text = renderer.render_actions_message()
|
||||
|
||||
assert text == "Actions available for this incident"
|
||||
assert text == "Actions available for this alert group"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
|
@ -161,7 +161,7 @@ def test_personal_message(
|
|||
"Source: Test integration - Grafana\n"
|
||||
f"{alert_group.web_link}\n\n"
|
||||
f"{alert_receive_channel.config.tests['telegram']['message']}\n\n\n"
|
||||
"Incident log:\n"
|
||||
"Alert group log:\n"
|
||||
f"<b>0s:</b> acknowledged by {user_name}"
|
||||
)
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ def test_link_to_channel_message(make_organization, make_alert_receive_channel,
|
|||
text = renderer.render_link_to_channel_message()
|
||||
|
||||
assert text == (
|
||||
f"👀 You are invited to look at the incident!\n"
|
||||
f"👀 You are invited to look at an alert group!\n"
|
||||
f"<b>#{alert_group.inside_organization_number}, {alert_receive_channel.config.tests['telegram']['title']}</b>"
|
||||
)
|
||||
|
||||
|
|
@ -202,6 +202,6 @@ def test_formatting_error_message(
|
|||
text = renderer.render_formatting_error_message()
|
||||
|
||||
assert text == (
|
||||
"You have a new incident, but Telegram can't render its content! "
|
||||
"You have a new alert group, but Telegram can't render its content! "
|
||||
f"Please check it out: {alert_group.web_link}"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue