Skip to content

Adding a fix for forwarded messages in incident timeline #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/modules/incident/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ def handle_reaction_added(client, ack, body, logger):
logger.error("No incident document found for this channel.")

for message in messages:
# get the forwarded message and get the attachments appeending the forwarded message to the original message
if message.get("attachments"):
attachments = message["attachments"]
for attachment in attachments:
fallback = attachment.get("fallback")
if fallback:
message["text"] += (
"\nForwarded Message :" + attachment["fallback"]
)

# get the message ts time
message_ts = message["ts"]

Expand Down Expand Up @@ -521,6 +531,16 @@ def handle_reaction_removed(client, ack, body, logger):
# get the message we want to delete
message = messages[0]

# get the forwarded message and get the attachments appeending the forwarded message to the original message
if message.get("attachments"):
attachments = message["attachments"]
for attachment in attachments:
fallback = attachment.get("fallback")
if fallback:
message["text"] += (
"Forwarded Message :" + attachment["fallback"]
)

# get the message ts time
message_ts = message["ts"]

Expand Down
54 changes: 54 additions & 0 deletions app/tests/modules/incident/test_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,38 @@ def test_handle_reaction_added_returns_link():
mock_client.chat_getPermalink.assert_called_once()


def test_handle_reaction_added_forwarded_message():
logger = MagicMock()
mock_client = MagicMock()
mock_client.conversations_info.return_value = {"channel": {"name": "incident-123"}}
mock_client.conversations_history.return_value = {
"ok": True,
"messages": [
{
"type": "message",
"attachments": [{"fallback": "This is a forwarded message"}],
"text": "Original message text",
"ts": "1617556890.000100",
"user": "U1234567890",
"files": [{"url_private": "https://example.com/image.png"}],
}
],
}
body = {
"event": {
"reaction": "floppy_disk",
"item": {"channel": "C123456", "ts": "123456"},
}
}

incident.handle_reaction_added(mock_client, lambda: None, body, logger)

# Make assertion that the function calls the correct functions
mock_client.conversations_history.assert_called_once()
mock_client.bookmarks_list.assert_called_once()
mock_client.users_profile_get.assert_called_once()


def test_handle_reaction_removed_successful_message_removal():
# Mock the client and logger
logger = MagicMock()
Expand Down Expand Up @@ -1271,6 +1303,28 @@ def test_handle_reaction_removed_empty_message_list_handling():
)


def test_handle_reaction_removed_forwarded_message():
logger = MagicMock()
mock_client = MagicMock()
mock_client.conversations_history.return_value = {
"attachments": [{"fallback": "This is a forwarded message"}],
"text": "Original message text",
"ts": "1617556890.000100",
"user": "U1234567890",
"files": [{"url_private": "https://example.com/image.png"}],
}
body = {
"event": {
"reaction": "floppy_disk",
"item": {"channel": "C123456", "ts": "123456"},
}
}
assert (
incident.handle_reaction_removed(mock_client, lambda: None, body, logger)
is None
)


def helper_options():
return [{"text": {"type": "plain_text", "text": "name"}, "value": "id"}]

Expand Down
Loading