slack-integration: Add test fixtures for extra Slack payloads.

This commit adds 4 new payload fixtures to the Slack
integration for messages we don't process properly yet:

- Messages with code blocks.
- Messages with overlapping text formatting (e.g, bold
  and italic).
- Messages with formatted mentions.
- Messages with quote blocks.

The follow-up plan to add support for these kind of
Slack messages is tracked in #30827.

Part of #30465.
This commit is contained in:
PieterCK
2024-07-09 14:26:22 +07:00
committed by Tim Abbott
parent f29312ce03
commit 1ebbe2fd99
5 changed files with 332 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
{
"token": "CqCsBJmXoNSHaNCt3wGWYSEe",
"team_id": "T06NRA6HM3P",
"context_team_id": "T06NRA6HM3P",
"context_enterprise_id": null,
"api_app_id": "A0757RM31HN",
"event": {
"user": "U06NU4E26M9",
"type": "message",
"ts": "1719211888.680799",
"client_msg_id": "452a95ae-9e35-4d84-a4c3-7012c6908f09",
"text": "```def is_bot_message(payload: WildValue) -> bool:\n app_api_id = payload.get(\"api_app_id\").tame(check_none_or(check_string))\n bot_app_id = (\n payload.get(\"event\", {})\n .get(\"bot_profile\", {})\n .get(\"app_id\")\n .tame(check_none_or(check_string))\n )\n return bot_app_id is not None and app_api_id == bot_app_id```",
"team": "T06NRA6HM3P",
"blocks": [
{
"type": "rich_text",
"block_id": "293Eu",
"elements": [
{
"type": "rich_text_preformatted",
"elements": [
{
"type": "text",
"text": "def is_bot_message(payload: WildValue) -> bool:\n app_api_id = payload.get(\"api_app_id\").tame(check_none_or(check_string))\n bot_app_id = (\n payload.get(\"event\", {})\n .get(\"bot_profile\", {})\n .get(\"app_id\")\n .tame(check_none_or(check_string))\n )\n return bot_app_id is not None and app_api_id == bot_app_id"
}
],
"border": 0
}
]
}
],
"channel": "C06NRA6JLER",
"event_ts": "1719211888.680799",
"channel_type": "channel"
},
"type": "event_callback",
"event_id": "Ev07A31RB0EL",
"event_time": 1719211888,
"authorizations": [
{
"enterprise_id": null,
"team_id": "T06NRA6HM3P",
"user_id": "U074G5E1ANR",
"is_bot": true,
"is_enterprise_install": false
}
],
"is_ext_shared_channel": false,
"event_context": "4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDZOUkE2SE0zUCIsImFpZCI6IkEwNzU3Uk0zMUhOIiwiY2lkIjoiQzA2TlJBNkpMRVIifQ"
}

View File

@@ -0,0 +1,99 @@
{
"token": "CqCsBJmXoNSHaNCt3wGWYSEe",
"team_id": "T06NRA6HM3P",
"context_team_id": "T06NRA6HM3P",
"context_enterprise_id": null,
"api_app_id": "A0757RM31HN",
"event": {
"user": "U06NU4E26M9",
"type": "message",
"ts": "1719211546.331399",
"client_msg_id": "b763525d-9211-4333-936c-b1c02ff0105e",
"text": "~_*<@U074VRHQ11T>*_~ ~_*<#C06P6T3QGD7|general>*_~ ~_*<!channel>*_~ ",
"team": "T06NRA6HM3P",
"blocks": [
{
"type": "rich_text",
"block_id": "yorkC",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "user",
"user_id": "U074VRHQ11T",
"style": {
"bold": true,
"italic": true,
"strike": true
}
},
{
"type": "text",
"text": " ",
"style": {
"bold": true,
"italic": true,
"strike": true
}
},
{
"type": "channel",
"channel_id": "C06P6T3QGD7",
"style": {
"bold": true,
"italic": true,
"strike": true
}
},
{
"type": "text",
"text": " ",
"style": {
"bold": true,
"italic": true,
"strike": true
}
},
{
"type": "broadcast",
"range": "channel",
"style": {
"bold": true,
"italic": true,
"strike": true
}
},
{
"type": "text",
"text": " ",
"style": {
"bold": true,
"italic": true,
"strike": true
}
}
]
}
]
}
],
"channel": "C06NRA6JLER",
"event_ts": "1719211546.331399",
"channel_type": "channel"
},
"type": "event_callback",
"event_id": "Ev079E3ZLGNP",
"event_time": 1719211546,
"authorizations": [
{
"enterprise_id": null,
"team_id": "T06NRA6HM3P",
"user_id": "U074G5E1ANR",
"is_bot": true,
"is_enterprise_install": false
}
],
"is_ext_shared_channel": false,
"event_context": "4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDZOUkE2SE0zUCIsImFpZCI6IkEwNzU3Uk0zMUhOIiwiY2lkIjoiQzA2TlJBNkpMRVIifQ"
}

View File

@@ -0,0 +1,94 @@
{
"token": "CqCsBJmXoNSHaNCt3wGWYSEe",
"team_id": "T06NRA6HM3P",
"context_team_id": "T06NRA6HM3P",
"context_enterprise_id": null,
"api_app_id": "A0757RM31HN",
"event": {
"user": "U06NU4E26M9",
"type": "message",
"ts": "1719211406.531029",
"client_msg_id": "f9b21f6a-690b-4acb-b04d-d264cd7512a2",
"text": "this is text messages with overlapping formatting\n_*bold with italic*_\n~*bold with strike through*~\n~_italic with strike through_~\n~_*all three*_~",
"team": "T06NRA6HM3P",
"blocks": [
{
"type": "rich_text",
"block_id": "Gx+b7",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "this is text messages with overlapping formatting\n"
},
{
"type": "text",
"text": "bold with italic",
"style": {
"bold": true,
"italic": true
}
},
{
"type": "text",
"text": "\n"
},
{
"type": "text",
"text": "bold with strike through",
"style": {
"bold": true,
"strike": true
}
},
{
"type": "text",
"text": "\n"
},
{
"type": "text",
"text": "italic with strike through",
"style": {
"italic": true,
"strike": true
}
},
{
"type": "text",
"text": "\n"
},
{
"type": "text",
"text": "all three",
"style": {
"bold": true,
"italic": true,
"strike": true
}
}
]
}
]
}
],
"channel": "C06NRA6JLER",
"event_ts": "1719211406.531029",
"channel_type": "channel"
},
"type": "event_callback",
"event_id": "Ev07A30U5YEL",
"event_time": 1719211406,
"authorizations": [
{
"enterprise_id": null,
"team_id": "T06NRA6HM3P",
"user_id": "U074G5E1ANR",
"is_bot": true,
"is_enterprise_install": false
}
],
"is_ext_shared_channel": false,
"event_context": "4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDZOUkE2SE0zUCIsImFpZCI6IkEwNzU3Uk0zMUhOIiwiY2lkIjoiQzA2TlJBNkpMRVIifQ"
}

View File

@@ -0,0 +1,49 @@
{
"token": "CqCsBJmXoNSHaNCt3wGWYSEe",
"team_id": "T06NRA6HM3P",
"context_team_id": "T06NRA6HM3P",
"context_enterprise_id": null,
"api_app_id": "A0757RM31HN",
"event": {
"user": "U06NU4E26M9",
"type": "message",
"ts": "1719211959.210699",
"client_msg_id": "116749a6-f2e2-4f99-96cb-fcef3300d1a1",
"text": "&gt; This is a quote",
"team": "T06NRA6HM3P",
"blocks": [
{
"type": "rich_text",
"block_id": "k3QzB",
"elements": [
{
"type": "rich_text_quote",
"elements": [
{
"type": "text",
"text": "This is a quote"
}
]
}
]
}
],
"channel": "C06NRA6JLER",
"event_ts": "1719211959.210699",
"channel_type": "channel"
},
"type": "event_callback",
"event_id": "Ev079GN4DWNQ",
"event_time": 1719211959,
"authorizations": [
{
"enterprise_id": null,
"team_id": "T06NRA6HM3P",
"user_id": "U074G5E1ANR",
"is_bot": true,
"is_enterprise_install": false
}
],
"is_ext_shared_channel": false,
"event_context": "4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDZOUkE2SE0zUCIsImFpZCI6IkEwNzU3Uk0zMUhOIiwiY2lkIjoiQzA2TlJBNkpMRVIifQ"
}

View File

@@ -225,6 +225,46 @@ class SlackWebhookTests(WebhookTestCase):
expect_noop=True,
)
def test_message_with_code_block(self) -> None:
message_body = """```def is_bot_message(payload: WildValue) -&gt; bool:\n app_api_id = payload.get(\"api_app_id\").tame(check_none_or(check_string))\n bot_app_id = (\n payload.get(\"event\", {})\n .get(\"bot_profile\", {})\n .get(\"app_id\")\n .tame(check_none_or(check_string))\n )\n return bot_app_id is not None and app_api_id == bot_app_id```"""
expected_message = EXPECTED_MESSAGE.format(user=USER, message=message_body)
self.check_webhook(
"message_with_code_block",
EXPECTED_TOPIC,
expected_message,
content_type="application/json",
)
def test_message_with_complex_formatted_texts(self) -> None:
message_body = "this is text messages with overlapping formatting\n_**bold with italic**_\n~**bold with strike through**~\n~*italic with strike through*~\n~***all three***~"
expected_message = EXPECTED_MESSAGE.format(user=USER, message=message_body)
self.check_webhook(
"message_with_complex_formatted_texts",
EXPECTED_TOPIC,
expected_message,
content_type="application/json",
)
def test_message_with_complex_formatted_mentions(self) -> None:
message_body = "~~***<@U074VRHQ11T>***~~ **#general** ~~***@**all*****~"
expected_message = EXPECTED_MESSAGE.format(user=USER, message=message_body)
self.check_webhook(
"message_with_complex_formatted_mentions",
EXPECTED_TOPIC,
expected_message,
content_type="application/json",
)
def test_message_with_quote_block(self) -> None:
message_body = "&gt; This is a quote"
expected_message = EXPECTED_MESSAGE.format(user=USER, message=message_body)
self.check_webhook(
"message_with_quote_block",
EXPECTED_TOPIC,
expected_message,
content_type="application/json",
)
class SlackLegacyWebhookTests(WebhookTestCase):
CHANNEL_NAME = "slack"