Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for conversations.requestShared approve, deny & list #1530

Merged
69 changes: 69 additions & 0 deletions slack_sdk/web/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

"""A Python module for interacting with Slack's Web API."""

import json
import os
import warnings
Expand Down Expand Up @@ -3191,6 +3192,74 @@
)
return await self.api_call("conversations.replies", http_verb="GET", params=kwargs)

async def conversations_requestSharedInvite_approve(
self,
*,
invite_id: str,
channel_id: Optional[str] = None,
is_external_limited: Optional[str] = None,
message: Optional[Dict[str, Any]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one note about message here is that if it is provided, text inside of message is required. not sure if that is possible to model in Python but figured I'd mention it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way to describe such in Python's type hints. The only approaches we can think of would be 1) accept both dict and custom class that has "text" property, 2) add runtime validation that checks if the key is not missing. That said, as long as the server-side returns a clear error code/message for the pattern, I don't think we should do extra on the client code side.

**kwargs,
) -> AsyncSlackResponse:
"""Approve a request to add an external user to a channel. This also sends them a Slack Connect invite.
https://api.slack.com/methods/conversations.requestSharedInvite.approve
"""
kwargs.update(
{
"invite_id": invite_id,
"channel_id": channel_id,
"is_external_limited": is_external_limited,
}
)
if message is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have these lines of code, the above "message": message, is unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 💯

kwargs.update({"message": json.dumps(message)})

Check warning on line 3215 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3215

Added line #L3215 was not covered by tests
return await self.api_call("conversations.requestSharedInvite.approve", params=kwargs)

async def conversations_requestSharedInvite_deny(
self,
*,
invite_id: str,
message: Optional[str] = None,
**kwargs,
) -> AsyncSlackResponse:
"""Deny a request to invite an external user to a channel.
https://api.slack.com/methods/conversations.requestSharedInvite.deny
"""
kwargs.update({"invite_id": invite_id, "message": message})
return await self.api_call("conversations.requestSharedInvite.deny", params=kwargs)

async def conversations_requestSharedInvite_list(
self,
*,
cursor: Optional[str] = None,
include_approved: Optional[bool] = None,
include_denied: Optional[bool] = None,
include_expired: Optional[bool] = None,
invite_ids: Optional[Union[str, Sequence[str]]] = None,
limit: Optional[int] = None,
user_id: Optional[str] = None,
**kwargs,
) -> AsyncSlackResponse:
"""Lists requests to add external users to channels with ability to filter.
https://api.slack.com/methods/conversations.requestSharedInvite.list
"""
kwargs.update(

Check warning on line 3246 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3246

Added line #L3246 was not covered by tests
{
"cursor": cursor,
"include_approved": include_approved,
"include_denied": include_denied,
"include_expired": include_expired,
"limit": limit,
"user_id": user_id,
}
)
if invite_ids is not None:
if isinstance(invite_ids, (list, Tuple)):
kwargs.update({"invite_ids": ",".join(invite_ids)})

Check warning on line 3258 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3256-L3258

Added lines #L3256 - L3258 were not covered by tests
else:
kwargs.update({"invite_ids": invite_ids})
return await self.api_call("conversations.requestSharedInvite.list", params=kwargs)

Check warning on line 3261 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3260-L3261

Added lines #L3260 - L3261 were not covered by tests

async def conversations_setPurpose(
self,
*,
Expand Down
69 changes: 69 additions & 0 deletions slack_sdk/web/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A Python module for interacting with Slack's Web API."""

import json
import os
import warnings
Expand Down Expand Up @@ -3182,6 +3183,74 @@
)
return self.api_call("conversations.replies", http_verb="GET", params=kwargs)

def conversations_requestSharedInvite_approve(
self,
*,
invite_id: str,
channel_id: Optional[str] = None,
is_external_limited: Optional[str] = None,
message: Optional[Dict[str, Any]] = None,
**kwargs,
) -> SlackResponse:
"""Approve a request to add an external user to a channel. This also sends them a Slack Connect invite.
https://api.slack.com/methods/conversations.requestSharedInvite.approve
"""
kwargs.update(
{
"invite_id": invite_id,
"channel_id": channel_id,
"is_external_limited": is_external_limited,
}
)
if message is not None:
kwargs.update({"message": json.dumps(message)})

Check warning on line 3206 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3206

Added line #L3206 was not covered by tests
return self.api_call("conversations.requestSharedInvite.approve", params=kwargs)

def conversations_requestSharedInvite_deny(
self,
*,
invite_id: str,
message: Optional[str] = None,
**kwargs,
) -> SlackResponse:
"""Deny a request to invite an external user to a channel.
https://api.slack.com/methods/conversations.requestSharedInvite.deny
"""
kwargs.update({"invite_id": invite_id, "message": message})
return self.api_call("conversations.requestSharedInvite.deny", params=kwargs)

def conversations_requestSharedInvite_list(
self,
*,
cursor: Optional[str] = None,
include_approved: Optional[bool] = None,
include_denied: Optional[bool] = None,
include_expired: Optional[bool] = None,
invite_ids: Optional[Union[str, Sequence[str]]] = None,
limit: Optional[int] = None,
user_id: Optional[str] = None,
**kwargs,
) -> SlackResponse:
"""Lists requests to add external users to channels with ability to filter.
https://api.slack.com/methods/conversations.requestSharedInvite.list
"""
kwargs.update(

Check warning on line 3237 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3237

Added line #L3237 was not covered by tests
{
"cursor": cursor,
"include_approved": include_approved,
"include_denied": include_denied,
"include_expired": include_expired,
"limit": limit,
"user_id": user_id,
}
)
if invite_ids is not None:
if isinstance(invite_ids, (list, Tuple)):
kwargs.update({"invite_ids": ",".join(invite_ids)})

Check warning on line 3249 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3247-L3249

Added lines #L3247 - L3249 were not covered by tests
else:
kwargs.update({"invite_ids": invite_ids})
return self.api_call("conversations.requestSharedInvite.list", params=kwargs)

Check warning on line 3252 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3251-L3252

Added lines #L3251 - L3252 were not covered by tests

def conversations_setPurpose(
self,
*,
Expand Down
69 changes: 69 additions & 0 deletions slack_sdk/web/legacy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from asyncio import Future

"""A Python module for interacting with Slack's Web API."""

import json
import os
import warnings
Expand Down Expand Up @@ -3193,6 +3194,74 @@
)
return self.api_call("conversations.replies", http_verb="GET", params=kwargs)

def conversations_requestSharedInvite_approve(
self,
*,
invite_id: str,
channel_id: Optional[str] = None,
is_external_limited: Optional[str] = None,
message: Optional[Dict[str, Any]] = None,
**kwargs,
) -> Union[Future, SlackResponse]:
"""Approve a request to add an external user to a channel. This also sends them a Slack Connect invite.
https://api.slack.com/methods/conversations.requestSharedInvite.approve
"""
kwargs.update(
{
"invite_id": invite_id,
"channel_id": channel_id,
"is_external_limited": is_external_limited,
}
)
if message is not None:
kwargs.update({"message": json.dumps(message)})

Check warning on line 3217 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3217

Added line #L3217 was not covered by tests
return self.api_call("conversations.requestSharedInvite.approve", params=kwargs)

def conversations_requestSharedInvite_deny(
self,
*,
invite_id: str,
message: Optional[str] = None,
**kwargs,
) -> Union[Future, SlackResponse]:
"""Deny a request to invite an external user to a channel.
https://api.slack.com/methods/conversations.requestSharedInvite.deny
"""
kwargs.update({"invite_id": invite_id, "message": message})
return self.api_call("conversations.requestSharedInvite.deny", params=kwargs)

def conversations_requestSharedInvite_list(
self,
*,
cursor: Optional[str] = None,
include_approved: Optional[bool] = None,
include_denied: Optional[bool] = None,
include_expired: Optional[bool] = None,
invite_ids: Optional[Union[str, Sequence[str]]] = None,
limit: Optional[int] = None,
user_id: Optional[str] = None,
**kwargs,
) -> Union[Future, SlackResponse]:
"""Lists requests to add external users to channels with ability to filter.
https://api.slack.com/methods/conversations.requestSharedInvite.list
"""
kwargs.update(

Check warning on line 3248 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3248

Added line #L3248 was not covered by tests
{
"cursor": cursor,
"include_approved": include_approved,
"include_denied": include_denied,
"include_expired": include_expired,
"limit": limit,
"user_id": user_id,
}
)
if invite_ids is not None:
if isinstance(invite_ids, (list, Tuple)):
kwargs.update({"invite_ids": ",".join(invite_ids)})

Check warning on line 3260 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3258-L3260

Added lines #L3258 - L3260 were not covered by tests
else:
kwargs.update({"invite_ids": invite_ids})
return self.api_call("conversations.requestSharedInvite.list", params=kwargs)

Check warning on line 3263 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3262-L3263

Added lines #L3262 - L3263 were not covered by tests

def conversations_setPurpose(
self,
*,
Expand Down
Loading
Loading