Skip to content

Commit b83f17b

Browse files
committed
[beta] Add support for Message Metadata and Subscribe in Slack API (#1151)
* Add apps.notifications.subscriptions.* methods + metadata
1 parent d478699 commit b83f17b

File tree

4 files changed

+197
-0
lines changed

4 files changed

+197
-0
lines changed

slack_sdk/web/async_client.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,69 @@ async def apps_event_authorizations_list(
15241524
)
15251525
return await self.api_call("apps.event.authorizations.list", params=kwargs)
15261526

1527+
async def apps_notifications_subscriptions_create(
1528+
self,
1529+
*,
1530+
trigger_id: str,
1531+
channel_id: str,
1532+
name: str,
1533+
type: Optional[Dict[str, Any]] = None,
1534+
resource_link: Optional[str] = None,
1535+
**kwargs,
1536+
) -> AsyncSlackResponse:
1537+
"""Create a new notification subscription.
1538+
https://api.slack.com/methods/apps.notifications.subscriptions.create
1539+
"""
1540+
kwargs.update(
1541+
{
1542+
"trigger_id": trigger_id,
1543+
"channel_id": channel_id,
1544+
"name": name,
1545+
"type": type,
1546+
"resource_link": resource_link,
1547+
}
1548+
)
1549+
return await self.api_call(
1550+
"apps.notifications.subscriptions.create",
1551+
params=kwargs,
1552+
)
1553+
1554+
async def apps_notifications_subscriptions_delete(
1555+
self,
1556+
*,
1557+
notification_subscription_id: str,
1558+
**kwargs,
1559+
) -> AsyncSlackResponse:
1560+
"""Remove a subscription in Slack
1561+
https://api.slack.com/methods/apps.notifications.subscriptions.delete
1562+
"""
1563+
kwargs.update({"notification_subscription_id": notification_subscription_id})
1564+
return await self.api_call(
1565+
"apps.notifications.subscriptions.delete", params=kwargs
1566+
)
1567+
1568+
async def apps_notifications_subscriptions_update(
1569+
self,
1570+
*,
1571+
notification_subscription_id: str,
1572+
channel_id: str,
1573+
trigger_id: str,
1574+
**kwargs,
1575+
) -> AsyncSlackResponse:
1576+
"""Confirm a subscription has been updated.
1577+
https://api.slack.com/methods/apps.notifications.subscriptions.update
1578+
"""
1579+
kwargs.update(
1580+
{
1581+
"notification_subscription_id": notification_subscription_id,
1582+
"channel_id": channel_id,
1583+
"trigger_id": trigger_id,
1584+
}
1585+
)
1586+
return await self.api_call(
1587+
"apps.notifications.subscriptions.update", params=kwargs
1588+
)
1589+
15271590
async def apps_uninstall(
15281591
self,
15291592
*,
@@ -1978,6 +2041,7 @@ async def chat_postMessage(
19782041
link_names: Optional[bool] = None,
19792042
username: Optional[str] = None,
19802043
parse: Optional[str] = None, # none, full
2044+
metadata: Optional[Dict[str, Any]] = None,
19812045
**kwargs,
19822046
) -> AsyncSlackResponse:
19832047
"""Sends a message to a channel.
@@ -2002,6 +2066,7 @@ async def chat_postMessage(
20022066
"link_names": link_names,
20032067
"username": username,
20042068
"parse": parse,
2069+
"metadata": metadata,
20052070
}
20062071
)
20072072
_parse_web_class_objects(kwargs)
@@ -2094,6 +2159,7 @@ async def chat_update(
20942159
link_names: Optional[bool] = None,
20952160
parse: Optional[str] = None, # none, full
20962161
reply_broadcast: Optional[bool] = None,
2162+
metadata: Optional[Dict[str, Any]] = None,
20972163
**kwargs,
20982164
) -> AsyncSlackResponse:
20992165
"""Updates a message in a channel.
@@ -2110,6 +2176,7 @@ async def chat_update(
21102176
"link_names": link_names,
21112177
"parse": parse,
21122178
"reply_broadcast": reply_broadcast,
2179+
"metadata": metadata,
21132180
}
21142181
)
21152182
_parse_web_class_objects(kwargs)

slack_sdk/web/client.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,65 @@ def apps_event_authorizations_list(
14771477
)
14781478
return self.api_call("apps.event.authorizations.list", params=kwargs)
14791479

1480+
def apps_notifications_subscriptions_create(
1481+
self,
1482+
*,
1483+
trigger_id: str,
1484+
channel_id: str,
1485+
name: str,
1486+
type: Optional[Dict[str, Any]] = None,
1487+
resource_link: Optional[str] = None,
1488+
**kwargs,
1489+
) -> SlackResponse:
1490+
"""Create a new notification subscription.
1491+
https://api.slack.com/methods/apps.notifications.subscriptions.create
1492+
"""
1493+
kwargs.update(
1494+
{
1495+
"trigger_id": trigger_id,
1496+
"channel_id": channel_id,
1497+
"name": name,
1498+
"type": type,
1499+
"resource_link": resource_link,
1500+
}
1501+
)
1502+
return self.api_call(
1503+
"apps.notifications.subscriptions.create",
1504+
params=kwargs,
1505+
)
1506+
1507+
def apps_notifications_subscriptions_delete(
1508+
self,
1509+
*,
1510+
notification_subscription_id: str,
1511+
**kwargs,
1512+
) -> SlackResponse:
1513+
"""Remove a subscription in Slack
1514+
https://api.slack.com/methods/apps.notifications.subscriptions.delete
1515+
"""
1516+
kwargs.update({"notification_subscription_id": notification_subscription_id})
1517+
return self.api_call("apps.notifications.subscriptions.delete", params=kwargs)
1518+
1519+
def apps_notifications_subscriptions_update(
1520+
self,
1521+
*,
1522+
notification_subscription_id: str,
1523+
channel_id: str,
1524+
trigger_id: str,
1525+
**kwargs,
1526+
) -> SlackResponse:
1527+
"""Confirm a subscription has been updated.
1528+
https://api.slack.com/methods/apps.notifications.subscriptions.update
1529+
"""
1530+
kwargs.update(
1531+
{
1532+
"notification_subscription_id": notification_subscription_id,
1533+
"channel_id": channel_id,
1534+
"trigger_id": trigger_id,
1535+
}
1536+
)
1537+
return self.api_call("apps.notifications.subscriptions.update", params=kwargs)
1538+
14801539
def apps_uninstall(
14811540
self,
14821541
*,
@@ -1929,6 +1988,7 @@ def chat_postMessage(
19291988
link_names: Optional[bool] = None,
19301989
username: Optional[str] = None,
19311990
parse: Optional[str] = None, # none, full
1991+
metadata: Optional[Dict[str, Any]] = None,
19321992
**kwargs,
19331993
) -> SlackResponse:
19341994
"""Sends a message to a channel.
@@ -1953,6 +2013,7 @@ def chat_postMessage(
19532013
"link_names": link_names,
19542014
"username": username,
19552015
"parse": parse,
2016+
"metadata": metadata,
19562017
}
19572018
)
19582019
_parse_web_class_objects(kwargs)
@@ -2045,6 +2106,7 @@ def chat_update(
20452106
link_names: Optional[bool] = None,
20462107
parse: Optional[str] = None, # none, full
20472108
reply_broadcast: Optional[bool] = None,
2109+
metadata: Optional[Dict[str, Any]] = None,
20482110
**kwargs,
20492111
) -> SlackResponse:
20502112
"""Updates a message in a channel.
@@ -2061,6 +2123,7 @@ def chat_update(
20612123
"link_names": link_names,
20622124
"parse": parse,
20632125
"reply_broadcast": reply_broadcast,
2126+
"metadata": metadata,
20642127
}
20652128
)
20662129
_parse_web_class_objects(kwargs)

slack_sdk/web/legacy_client.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,65 @@ def apps_event_authorizations_list(
14881488
)
14891489
return self.api_call("apps.event.authorizations.list", params=kwargs)
14901490

1491+
def apps_notifications_subscriptions_create(
1492+
self,
1493+
*,
1494+
trigger_id: str,
1495+
channel_id: str,
1496+
name: str,
1497+
type: Optional[Dict[str, Any]] = None,
1498+
resource_link: Optional[str] = None,
1499+
**kwargs,
1500+
) -> Union[Future, SlackResponse]:
1501+
"""Create a new notification subscription.
1502+
https://api.slack.com/methods/apps.notifications.subscriptions.create
1503+
"""
1504+
kwargs.update(
1505+
{
1506+
"trigger_id": trigger_id,
1507+
"channel_id": channel_id,
1508+
"name": name,
1509+
"type": type,
1510+
"resource_link": resource_link,
1511+
}
1512+
)
1513+
return self.api_call(
1514+
"apps.notifications.subscriptions.create",
1515+
params=kwargs,
1516+
)
1517+
1518+
def apps_notifications_subscriptions_delete(
1519+
self,
1520+
*,
1521+
notification_subscription_id: str,
1522+
**kwargs,
1523+
) -> Union[Future, SlackResponse]:
1524+
"""Remove a subscription in Slack
1525+
https://api.slack.com/methods/apps.notifications.subscriptions.delete
1526+
"""
1527+
kwargs.update({"notification_subscription_id": notification_subscription_id})
1528+
return self.api_call("apps.notifications.subscriptions.delete", params=kwargs)
1529+
1530+
def apps_notifications_subscriptions_update(
1531+
self,
1532+
*,
1533+
notification_subscription_id: str,
1534+
channel_id: str,
1535+
trigger_id: str,
1536+
**kwargs,
1537+
) -> Union[Future, SlackResponse]:
1538+
"""Confirm a subscription has been updated.
1539+
https://api.slack.com/methods/apps.notifications.subscriptions.update
1540+
"""
1541+
kwargs.update(
1542+
{
1543+
"notification_subscription_id": notification_subscription_id,
1544+
"channel_id": channel_id,
1545+
"trigger_id": trigger_id,
1546+
}
1547+
)
1548+
return self.api_call("apps.notifications.subscriptions.update", params=kwargs)
1549+
14911550
def apps_uninstall(
14921551
self,
14931552
*,
@@ -1940,6 +1999,7 @@ def chat_postMessage(
19401999
link_names: Optional[bool] = None,
19412000
username: Optional[str] = None,
19422001
parse: Optional[str] = None, # none, full
2002+
metadata: Optional[Dict[str, Any]] = None,
19432003
**kwargs,
19442004
) -> Union[Future, SlackResponse]:
19452005
"""Sends a message to a channel.
@@ -1964,6 +2024,7 @@ def chat_postMessage(
19642024
"link_names": link_names,
19652025
"username": username,
19662026
"parse": parse,
2027+
"metadata": metadata,
19672028
}
19682029
)
19692030
_parse_web_class_objects(kwargs)
@@ -2056,6 +2117,7 @@ def chat_update(
20562117
link_names: Optional[bool] = None,
20572118
parse: Optional[str] = None, # none, full
20582119
reply_broadcast: Optional[bool] = None,
2120+
metadata: Optional[Dict[str, Any]] = None,
20592121
**kwargs,
20602122
) -> Union[Future, SlackResponse]:
20612123
"""Updates a message in a channel.
@@ -2072,6 +2134,7 @@ def chat_update(
20722134
"link_names": link_names,
20732135
"parse": parse,
20742136
"reply_broadcast": reply_broadcast,
2137+
"metadata": metadata,
20752138
}
20762139
)
20772140
_parse_web_class_objects(kwargs)

tests/slack_sdk_async/web/test_web_client_coverage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def setUp(self):
5555
"apps.manifest.update",
5656
"apps.manifest.validate",
5757
"tooling.tokens.rotate",
58+
# TODO: Subscribe in Slack APIs
59+
"apps.notifications.subscriptions.create",
60+
"apps.notifications.subscriptions.delete",
61+
"apps.notifications.subscriptions.update",
5862
]:
5963
continue
6064
self.api_methods_to_call.append(api_method)

0 commit comments

Comments
 (0)