From a6d1a93f2b015bf62627fffeebe9daa41b0f3416 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Mon, 1 May 2023 21:28:16 +0900 Subject: [PATCH] Add metadata support to Incoming Webhooks --- integration_tests/webhook/test_async_webhook.py | 14 ++++++++++++++ integration_tests/webhook/test_webhook.py | 13 +++++++++++++ slack_sdk/webhook/async_client.py | 3 +++ slack_sdk/webhook/client.py | 3 +++ 4 files changed, 33 insertions(+) diff --git a/integration_tests/webhook/test_async_webhook.py b/integration_tests/webhook/test_async_webhook.py index 911382873..8095c2fa1 100644 --- a/integration_tests/webhook/test_async_webhook.py +++ b/integration_tests/webhook/test_async_webhook.py @@ -276,3 +276,17 @@ async def test_with_attachments_dict(self): ) self.assertEqual(200, response.status_code) self.assertEqual("ok", response.body) + + @async_test + async def test_metadata(self): + url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL] + webhook = AsyncWebhookClient(url) + response = await webhook.send( + text="Hello with metadata", + metadata={ + "event_type": "foo", + "event_payload": {"foo": "bar"}, + }, + ) + self.assertEqual(200, response.status_code) + self.assertEqual("ok", response.body) diff --git a/integration_tests/webhook/test_webhook.py b/integration_tests/webhook/test_webhook.py index a9aa46897..d1e55c6a0 100644 --- a/integration_tests/webhook/test_webhook.py +++ b/integration_tests/webhook/test_webhook.py @@ -270,3 +270,16 @@ def test_with_attachments_dict(self): ) self.assertEqual(200, response.status_code) self.assertEqual("ok", response.body) + + def test_metadata(self): + url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL] + webhook = WebhookClient(url) + response = webhook.send( + text="Hello with metadata", + metadata={ + "event_type": "foo", + "event_payload": {"foo": "bar"}, + }, + ) + self.assertEqual(200, response.status_code) + self.assertEqual("ok", response.body) diff --git a/slack_sdk/webhook/async_client.py b/slack_sdk/webhook/async_client.py index 019854778..0480cdd31 100644 --- a/slack_sdk/webhook/async_client.py +++ b/slack_sdk/webhook/async_client.py @@ -96,6 +96,7 @@ async def send( delete_original: Optional[bool] = None, unfurl_links: Optional[bool] = None, unfurl_media: Optional[bool] = None, + metadata: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, str]] = None, ) -> WebhookResponse: """Performs a Slack API request and returns the result. @@ -109,6 +110,7 @@ async def send( delete_original: True if you use this option for response_url requests unfurl_links: Option to indicate whether text url should unfurl unfurl_media: Option to indicate whether media url should unfurl + metadata: Metadata attached to the message headers: Request headers to append only for this request Returns: @@ -126,6 +128,7 @@ async def send( "delete_original": delete_original, "unfurl_links": unfurl_links, "unfurl_media": unfurl_media, + "metadata": metadata, }, headers=headers, ) diff --git a/slack_sdk/webhook/client.py b/slack_sdk/webhook/client.py index 17df0b754..db403acd0 100644 --- a/slack_sdk/webhook/client.py +++ b/slack_sdk/webhook/client.py @@ -86,6 +86,7 @@ def send( delete_original: Optional[bool] = None, unfurl_links: Optional[bool] = None, unfurl_media: Optional[bool] = None, + metadata: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, str]] = None, ) -> WebhookResponse: """Performs a Slack API request and returns the result. @@ -100,6 +101,7 @@ def send( delete_original: True if you use this option for response_url requests unfurl_links: Option to indicate whether text url should unfurl unfurl_media: Option to indicate whether media url should unfurl + metadata: Metadata attached to the message headers: Request headers to append only for this request Returns: @@ -117,6 +119,7 @@ def send( "delete_original": delete_original, "unfurl_links": unfurl_links, "unfurl_media": unfurl_media, + "metadata": metadata, }, headers=headers, )