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
70 changes: 70 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,75 @@
)
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,
"message": message,
}
)
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 3216 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3216

Added line #L3216 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 3247 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3247

Added line #L3247 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 3259 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3257-L3259

Added lines #L3257 - L3259 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 3262 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L3261-L3262

Added lines #L3261 - L3262 were not covered by tests

async def conversations_setPurpose(
self,
*,
Expand Down
70 changes: 70 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,75 @@
)
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,
"message": message,
}
)
if message is not None:
kwargs.update({"message": json.dumps(message)})

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

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3207

Added line #L3207 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 3238 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3238

Added line #L3238 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 3250 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3248-L3250

Added lines #L3248 - L3250 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 3253 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L3252-L3253

Added lines #L3252 - L3253 were not covered by tests

def conversations_setPurpose(
self,
*,
Expand Down
70 changes: 70 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,75 @@
)
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,
"message": message,
}
)
if message is not None:
kwargs.update({"message": json.dumps(message)})

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

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3218

Added line #L3218 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 3249 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3249

Added line #L3249 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 3261 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3259-L3261

Added lines #L3259 - L3261 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 3264 in slack_sdk/web/legacy_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/legacy_client.py#L3263-L3264

Added lines #L3263 - L3264 were not covered by tests

def conversations_setPurpose(
self,
*,
Expand Down
Loading
Loading