Skip to content

Add functions.completeSuccess/Error APIs for remote functions #1432

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

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def setUp(self):
if self.channel_id is None:
millis = int(round(time.time() * 1000))
channel_name = f"private-test-channel-{millis}"
self.channel_id = client.conversations_create(
name=channel_name,
is_private=True,
)[
self.channel_id = client.conversations_create(name=channel_name, is_private=True,)[
"channel"
]["id"]

Expand Down
7 changes: 1 addition & 6 deletions integration_tests/web/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ def tearDown(self):

def test_sync(self):
client = self.sync_client
user_id = list(
filter(
lambda u: not u["deleted"] and "bot_id" not in u,
client.users_list(limit=50)["members"],
)
)[
user_id = list(filter(lambda u: not u["deleted"] and "bot_id" not in u, client.users_list(limit=50)["members"],))[
0
]["id"]

Expand Down
26 changes: 26 additions & 0 deletions slack_sdk/web/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3658,6 +3658,32 @@ async def files_completeUploadExternal(
)
return await self.api_call("files.completeUploadExternal", params=kwargs)

async def functions_completeSuccess(
self,
*,
function_execution_id: str,
outputs: Dict[str, Any],
**kwargs,
) -> AsyncSlackResponse:
"""Signal the successful completion of a function
https://api.slack.com/methods/functions.completeSuccess
"""
kwargs.update({"function_execution_id": function_execution_id, "outputs": json.dumps(outputs)})
return await self.api_call("functions.completeSuccess", params=kwargs)

async def functions_completeError(
self,
*,
function_execution_id: str,
error: str,
**kwargs,
) -> AsyncSlackResponse:
"""Signal the failure to execute a function
https://api.slack.com/methods/functions.completeError
"""
kwargs.update({"function_execution_id": function_execution_id, "error": error})
return await self.api_call("functions.completeError", params=kwargs)

# --------------------------
# Deprecated: groups.*
# You can use conversations.* APIs instead.
Expand Down
26 changes: 26 additions & 0 deletions slack_sdk/web/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3649,6 +3649,32 @@ def files_completeUploadExternal(
)
return self.api_call("files.completeUploadExternal", params=kwargs)

def functions_completeSuccess(
self,
*,
function_execution_id: str,
outputs: Dict[str, Any],
**kwargs,
) -> SlackResponse:
"""Signal the successful completion of a function
https://api.slack.com/methods/functions.completeSuccess
"""
kwargs.update({"function_execution_id": function_execution_id, "outputs": json.dumps(outputs)})
return self.api_call("functions.completeSuccess", params=kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

During my testing of python remote functions I found that passing these values to the params parameter lead to some instability and resorted to passing values through the json parameter to resolve the issue

This might have been an issue on my end, but could you confirm this approach is reliable for a variety of outputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WilliamBergamin Oh, this is great catch! i totally forgot to do json.dumps() before passing the value to kwargs. Thanks for saving me!


def functions_completeError(
self,
*,
function_execution_id: str,
error: str,
**kwargs,
) -> SlackResponse:
"""Signal the failure to execute a function
https://api.slack.com/methods/functions.completeError
"""
kwargs.update({"function_execution_id": function_execution_id, "error": error})
return self.api_call("functions.completeError", params=kwargs)

# --------------------------
# Deprecated: groups.*
# You can use conversations.* APIs instead.
Expand Down
26 changes: 26 additions & 0 deletions slack_sdk/web/legacy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3660,6 +3660,32 @@ def files_completeUploadExternal(
)
return self.api_call("files.completeUploadExternal", params=kwargs)

def functions_completeSuccess(
self,
*,
function_execution_id: str,
outputs: Dict[str, Any],
**kwargs,
) -> Union[Future, SlackResponse]:
"""Signal the successful completion of a function
https://api.slack.com/methods/functions.completeSuccess
"""
kwargs.update({"function_execution_id": function_execution_id, "outputs": json.dumps(outputs)})
return self.api_call("functions.completeSuccess", params=kwargs)

def functions_completeError(
self,
*,
function_execution_id: str,
error: str,
**kwargs,
) -> Union[Future, SlackResponse]:
"""Signal the failure to execute a function
https://api.slack.com/methods/functions.completeError
"""
kwargs.update({"function_execution_id": function_execution_id, "error": error})
return self.api_call("functions.completeError", params=kwargs)

# --------------------------
# Deprecated: groups.*
# You can use conversations.* APIs instead.
Expand Down
6 changes: 6 additions & 0 deletions tests/slack_sdk_async/web/test_web_client_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,12 @@ async def run_method(self, method_name, method, async_method):
elif method_name == "files_completeUploadExternal":
self.api_methods_to_call.remove(method(files=[{"id": "F111"}])["method"])
await async_method(files=[{"id": "F111"}])
elif method_name == "functions_completeSuccess":
self.api_methods_to_call.remove(method(function_execution_id="Fn111", outputs={"num": 123}))
await async_method(function_execution_id="Fn111", outputs={"num": 123})
elif method_name == "functions_completeError":
self.api_methods_to_call.remove(method(function_execution_id="Fn111", error="something wrong"))
await async_method(function_execution_id="Fn111", error="something wrong")
elif method_name == "migration_exchange":
self.api_methods_to_call.remove(method(users="U123,U234")["method"])
method(users="U123,U234")
Expand Down