Skip to content

Commit b07e49f

Browse files
Filip Majfilmaj
authored andcommitted
Add bookmarks.* API support
1 parent 4d3f67d commit b07e49f

File tree

4 files changed

+254
-6
lines changed

4 files changed

+254
-6
lines changed

slack_sdk/web/async_client.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,83 @@ async def auth_test(
16011601
"""
16021602
return await self.api_call("auth.test", params=kwargs)
16031603

1604+
async def bookmarks_add(
1605+
self,
1606+
*,
1607+
channel_id: str,
1608+
title: str,
1609+
type: str,
1610+
emoji: Optional[str] = None,
1611+
entity_id: Optional[str] = None,
1612+
link: Optional[str] = None, # include when type is 'link'
1613+
parent_id: Optional[str] = None,
1614+
**kwargs,
1615+
) -> AsyncSlackResponse:
1616+
"""Add bookmark to a channel.
1617+
https://api.slack.com/methods/bookmarks.add
1618+
"""
1619+
kwargs.update(
1620+
{
1621+
"channel_id": channel_id,
1622+
"title": title,
1623+
"type": type,
1624+
"emoji": emoji,
1625+
"entity_id": entity_id,
1626+
"link": link,
1627+
"parent_id": parent_id,
1628+
}
1629+
)
1630+
return await self.api_call("bookmarks.add", http_verb="POST", params=kwargs)
1631+
1632+
async def bookmarks_edit(
1633+
self,
1634+
*,
1635+
bookmark_id: str,
1636+
channel_id: str,
1637+
emoji: Optional[str] = None,
1638+
link: Optional[str] = None,
1639+
title: Optional[str] = None,
1640+
**kwargs,
1641+
) -> AsyncSlackResponse:
1642+
"""Edit bookmark.
1643+
https://api.slack.com/methods/bookmarks.edit
1644+
"""
1645+
kwargs.update(
1646+
{
1647+
"bookmark_id": bookmark_id,
1648+
"channel_id": channel_id,
1649+
"emoji": emoji,
1650+
"link": link,
1651+
"title": title,
1652+
}
1653+
)
1654+
return await self.api_call("bookmarks.edit", http_verb="POST", params=kwargs)
1655+
1656+
async def bookmarks_list(
1657+
self,
1658+
*,
1659+
channel_id: str,
1660+
**kwargs,
1661+
) -> AsyncSlackResponse:
1662+
"""List bookmark for the channel.
1663+
https://api.slack.com/methods/bookmarks.list
1664+
"""
1665+
kwargs.update({"channel_id": channel_id})
1666+
return await self.api_call("bookmarks.list", http_verb="POST", params=kwargs)
1667+
1668+
async def bookmarks_remove(
1669+
self,
1670+
*,
1671+
bookmark_id: str,
1672+
channel_id: str,
1673+
**kwargs,
1674+
) -> AsyncSlackResponse:
1675+
"""Remove bookmark from the channel.
1676+
https://api.slack.com/methods/bookmarks.remove
1677+
"""
1678+
kwargs.update({"bookmark_id": bookmark_id, "channel_id": channel_id})
1679+
return await self.api_call("bookmarks.remove", http_verb="POST", params=kwargs)
1680+
16041681
async def bots_info(
16051682
self,
16061683
*,

slack_sdk/web/client.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,83 @@ def auth_test(
15521552
"""
15531553
return self.api_call("auth.test", params=kwargs)
15541554

1555+
def bookmarks_add(
1556+
self,
1557+
*,
1558+
channel_id: str,
1559+
title: str,
1560+
type: str,
1561+
emoji: Optional[str] = None,
1562+
entity_id: Optional[str] = None,
1563+
link: Optional[str] = None,
1564+
parent_id: Optional[str] = None,
1565+
**kwargs,
1566+
) -> SlackResponse:
1567+
"""Add bookmark to a channel.
1568+
https://api.slack.com/methods/bookmarks.add
1569+
"""
1570+
kwargs.update(
1571+
{
1572+
"channel_id": channel_id,
1573+
"title": title,
1574+
"type": type,
1575+
"emoji": emoji,
1576+
"entity_id": entity_id,
1577+
"link": link,
1578+
"parent_id": parent_id,
1579+
}
1580+
)
1581+
return self.api_call("bookmarks.add", http_verb="POST", params=kwargs)
1582+
1583+
def bookmarks_edit(
1584+
self,
1585+
*,
1586+
bookmark_id: str,
1587+
channel_id: str,
1588+
emoji: Optional[str] = None,
1589+
link: Optional[str] = None,
1590+
title: Optional[str] = None,
1591+
**kwargs,
1592+
) -> SlackResponse:
1593+
"""Edit bookmark.
1594+
https://api.slack.com/methods/bookmarks.edit
1595+
"""
1596+
kwargs.update(
1597+
{
1598+
"bookmark_id": bookmark_id,
1599+
"channel_id": channel_id,
1600+
"emoji": emoji,
1601+
"link": link,
1602+
"title": title,
1603+
}
1604+
)
1605+
return self.api_call("bookmarks.edit", http_verb="POST", params=kwargs)
1606+
1607+
def bookmarks_list(
1608+
self,
1609+
*,
1610+
channel_id: str,
1611+
**kwargs,
1612+
) -> SlackResponse:
1613+
"""List bookmark for the channel.
1614+
https://api.slack.com/methods/bookmarks.list
1615+
"""
1616+
kwargs.update({"channel_id": channel_id})
1617+
return self.api_call("bookmarks.list", http_verb="POST", params=kwargs)
1618+
1619+
def bookmarks_remove(
1620+
self,
1621+
*,
1622+
bookmark_id: str,
1623+
channel_id: str,
1624+
**kwargs,
1625+
) -> SlackResponse:
1626+
"""Remove bookmark from the channel.
1627+
https://api.slack.com/methods/bookmarks.remove
1628+
"""
1629+
kwargs.update({"bookmark_id": bookmark_id, "channel_id": channel_id})
1630+
return self.api_call("bookmarks.remove", http_verb="POST", params=kwargs)
1631+
15551632
def bots_info(
15561633
self,
15571634
*,

slack_sdk/web/legacy_client.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,83 @@ def auth_test(
15631563
"""
15641564
return self.api_call("auth.test", params=kwargs)
15651565

1566+
def bookmarks_add(
1567+
self,
1568+
*,
1569+
channel_id: str,
1570+
title: str,
1571+
type: str,
1572+
emoji: Optional[str] = None,
1573+
entity_id: Optional[str] = None,
1574+
link: Optional[str] = None,
1575+
parent_id: Optional[str] = None,
1576+
**kwargs,
1577+
) -> Union[Future, SlackResponse]:
1578+
"""Add bookmark to a channel.
1579+
https://api.slack.com/methods/bookmarks.add
1580+
"""
1581+
kwargs.update(
1582+
{
1583+
"channel_id": channel_id,
1584+
"title": title,
1585+
"type": type,
1586+
"emoji": emoji,
1587+
"entity_id": entity_id,
1588+
"link": link,
1589+
"parent_id": parent_id,
1590+
}
1591+
)
1592+
return self.api_call("bookmarks.add", http_verb="POST", params=kwargs)
1593+
1594+
def bookmarks_edit(
1595+
self,
1596+
*,
1597+
bookmark_id: str,
1598+
channel_id: str,
1599+
emoji: Optional[str] = None,
1600+
link: Optional[str] = None,
1601+
title: Optional[str] = None,
1602+
**kwargs,
1603+
) -> Union[Future, SlackResponse]:
1604+
"""Edit bookmark.
1605+
https://api.slack.com/methods/bookmarks.edit
1606+
"""
1607+
kwargs.update(
1608+
{
1609+
"bookmark_id": bookmark_id,
1610+
"channel_id": channel_id,
1611+
"emoji": emoji,
1612+
"link": link,
1613+
"title": title,
1614+
}
1615+
)
1616+
return self.api_call("bookmarks.edit", http_verb="POST", params=kwargs)
1617+
1618+
def bookmarks_list(
1619+
self,
1620+
*,
1621+
channel_id: str,
1622+
**kwargs,
1623+
) -> Union[Future, SlackResponse]:
1624+
"""List bookmark for the channel.
1625+
https://api.slack.com/methods/bookmarks.list
1626+
"""
1627+
kwargs.update({"channel_id": channel_id})
1628+
return self.api_call("bookmarks.list", http_verb="POST", params=kwargs)
1629+
1630+
def bookmarks_remove(
1631+
self,
1632+
*,
1633+
bookmark_id: str,
1634+
channel_id: str,
1635+
**kwargs,
1636+
) -> Union[Future, SlackResponse]:
1637+
"""Remove bookmark from the channel.
1638+
https://api.slack.com/methods/bookmarks.remove
1639+
"""
1640+
kwargs.update({"bookmark_id": bookmark_id, "channel_id": channel_id})
1641+
return self.api_call("bookmarks.remove", http_verb="POST", params=kwargs)
1642+
15661643
def bots_info(
15671644
self,
15681645
*,

tests/slack_sdk_async/web/test_web_client_coverage.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
class TestWebClientCoverage(unittest.TestCase):
18-
# 222 endpoints as of Jan 11, 2022
18+
# 227 endpoints as of Feb 16, 2022
1919
# Can be fetched by running `var methodNames = [].slice.call(document.getElementsByClassName('apiReferenceFilterableList__listItemLink')).map(e => e.href.replace("https://api.slack.com/methods/", ""));console.log(methodNames.toString());console.log(methodNames.length);` on https://api.slack.com/methods
2020
all_api_methods = "admin.analytics.getFile,admin.apps.approve,admin.apps.clearResolution,admin.apps.restrict,admin.apps.uninstall,admin.apps.approved.list,admin.apps.requests.cancel,admin.apps.requests.list,admin.apps.restricted.list,admin.auth.policy.assignEntities,admin.auth.policy.getEntities,admin.auth.policy.removeEntities,admin.barriers.create,admin.barriers.delete,admin.barriers.list,admin.barriers.update,admin.conversations.archive,admin.conversations.convertToPrivate,admin.conversations.create,admin.conversations.delete,admin.conversations.disconnectShared,admin.conversations.getConversationPrefs,admin.conversations.getCustomRetention,admin.conversations.getTeams,admin.conversations.invite,admin.conversations.removeCustomRetention,admin.conversations.rename,admin.conversations.search,admin.conversations.setConversationPrefs,admin.conversations.setCustomRetention,admin.conversations.setTeams,admin.conversations.unarchive,admin.conversations.ekm.listOriginalConnectedChannelInfo,admin.conversations.restrictAccess.addGroup,admin.conversations.restrictAccess.listGroups,admin.conversations.restrictAccess.removeGroup,admin.emoji.add,admin.emoji.addAlias,admin.emoji.list,admin.emoji.remove,admin.emoji.rename,admin.inviteRequests.approve,admin.inviteRequests.deny,admin.inviteRequests.list,admin.inviteRequests.approved.list,admin.inviteRequests.denied.list,admin.teams.admins.list,admin.teams.create,admin.teams.list,admin.teams.owners.list,admin.teams.settings.info,admin.teams.settings.setDefaultChannels,admin.teams.settings.setDescription,admin.teams.settings.setDiscoverability,admin.teams.settings.setIcon,admin.teams.settings.setName,admin.usergroups.addChannels,admin.usergroups.addTeams,admin.usergroups.listChannels,admin.usergroups.removeChannels,admin.users.assign,admin.users.invite,admin.users.list,admin.users.remove,admin.users.setAdmin,admin.users.setExpiration,admin.users.setOwner,admin.users.setRegular,admin.users.session.clearSettings,admin.users.session.getSettings,admin.users.session.invalidate,admin.users.session.list,admin.users.session.reset,admin.users.session.resetBulk,admin.users.session.setSettings,admin.users.unsupportedVersions.export,api.test,apps.connections.open,apps.event.authorizations.list,apps.manifest.create,apps.manifest.delete,apps.manifest.export,apps.manifest.update,apps.manifest.validate,apps.uninstall,auth.revoke,auth.test,auth.teams.list,bookmarks.add,bookmarks.edit,bookmarks.list,bookmarks.remove,bots.info,calls.add,calls.end,calls.info,calls.update,calls.participants.add,calls.participants.remove,chat.delete,chat.deleteScheduledMessage,chat.getPermalink,chat.meMessage,chat.postEphemeral,chat.postMessage,chat.scheduleMessage,chat.unfurl,chat.update,chat.scheduledMessages.list,conversations.acceptSharedInvite,conversations.approveSharedInvite,conversations.archive,conversations.close,conversations.create,conversations.declineSharedInvite,conversations.history,conversations.info,conversations.invite,conversations.inviteShared,conversations.join,conversations.kick,conversations.leave,conversations.list,conversations.listConnectInvites,conversations.mark,conversations.members,conversations.open,conversations.rename,conversations.replies,conversations.setPurpose,conversations.setTopic,conversations.unarchive,dialog.open,dnd.endDnd,dnd.endSnooze,dnd.info,dnd.setSnooze,dnd.teamInfo,emoji.list,files.comments.delete,files.delete,files.info,files.list,files.revokePublicURL,files.sharedPublicURL,files.upload,files.remote.add,files.remote.info,files.remote.list,files.remote.remove,files.remote.share,files.remote.update,migration.exchange,oauth.access,oauth.v2.access,oauth.v2.exchange,openid.connect.token,openid.connect.userInfo,pins.add,pins.list,pins.remove,reactions.add,reactions.get,reactions.list,reactions.remove,reminders.add,reminders.complete,reminders.delete,reminders.info,reminders.list,rtm.connect,rtm.start,search.all,search.files,search.messages,stars.add,stars.list,stars.remove,team.accessLogs,team.billableInfo,team.info,team.integrationLogs,team.billing.info,team.preferences.list,team.profile.get,tooling.tokens.rotate,usergroups.create,usergroups.disable,usergroups.enable,usergroups.list,usergroups.update,usergroups.users.list,usergroups.users.update,users.conversations,users.deletePhoto,users.getPresence,users.identity,users.info,users.list,users.lookupByEmail,users.setActive,users.setPhoto,users.setPresence,users.profile.get,users.profile.set,views.open,views.publish,views.push,views.update,workflows.stepCompleted,workflows.stepFailed,workflows.updateStep,channels.create,channels.info,channels.invite,channels.mark,groups.create,groups.info,groups.invite,groups.mark,groups.open,im.list,im.mark,im.open,mpim.list,mpim.mark,mpim.open".split(
2121
","
@@ -55,11 +55,6 @@ def setUp(self):
5555
"apps.manifest.update",
5656
"apps.manifest.validate",
5757
"tooling.tokens.rotate",
58-
# TODO: bookmarks.*
59-
"bookmarks.add",
60-
"bookmarks.edit",
61-
"bookmarks.list",
62-
"bookmarks.remove",
6358
]:
6459
continue
6560
self.api_methods_to_call.append(api_method)
@@ -392,6 +387,28 @@ async def run_method(self, method_name, method, async_method):
392387
method(client_id="111.222", client_secret="xxx")["method"]
393388
)
394389
await async_method(client_id="111.222", client_secret="xxx")
390+
elif method_name == "bookmarks_add":
391+
self.api_methods_to_call.remove(
392+
method(channel_id="C1234", title="bedtime story", type="article")[
393+
"method"
394+
]
395+
)
396+
await async_method(
397+
channel_id="C1234", title="bedtime story", type="article"
398+
)
399+
elif method_name == "bookmarks_edit":
400+
self.api_methods_to_call.remove(
401+
method(bookmark_id="B1234", channel_id="C1234")["method"]
402+
)
403+
await async_method(bookmark_id="B1234", channel_id="C1234")
404+
elif method_name == "bookmarks_list":
405+
self.api_methods_to_call.remove(method(channel_id="C1234")["method"])
406+
await async_method(channel_id="C1234")
407+
elif method_name == "bookmarks_remove":
408+
self.api_methods_to_call.remove(
409+
method(bookmark_id="B1234", channel_id="C1234")["method"]
410+
)
411+
await async_method(bookmark_id="B1234", channel_id="C1234")
395412
elif method_name == "calls_add":
396413
self.api_methods_to_call.remove(
397414
method(

0 commit comments

Comments
 (0)