Skip to content

Commit

Permalink
Add metadata support to Incoming Webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed May 1, 2023
1 parent 8815d21 commit a6d1a93
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions integration_tests/webhook/test_async_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 13 additions & 0 deletions integration_tests/webhook/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions slack_sdk/webhook/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -126,6 +128,7 @@ async def send(
"delete_original": delete_original,
"unfurl_links": unfurl_links,
"unfurl_media": unfurl_media,
"metadata": metadata,
},
headers=headers,
)
Expand Down
3 changes: 3 additions & 0 deletions slack_sdk/webhook/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -117,6 +119,7 @@ def send(
"delete_original": delete_original,
"unfurl_links": unfurl_links,
"unfurl_media": unfurl_media,
"metadata": metadata,
},
headers=headers,
)
Expand Down

0 comments on commit a6d1a93

Please sign in to comment.