Skip to content

Commit 06e55d1

Browse files
authored
Add functions.completeSuccess/Error APIs for remote functions (#1432)
1 parent 7fb3daf commit 06e55d1

File tree

6 files changed

+86
-10
lines changed

6 files changed

+86
-10
lines changed

integration_tests/web/test_admin_conversations_restrictAccess.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ def setUp(self):
4040
if self.channel_id is None:
4141
millis = int(round(time.time() * 1000))
4242
channel_name = f"private-test-channel-{millis}"
43-
self.channel_id = client.conversations_create(
44-
name=channel_name,
45-
is_private=True,
46-
)[
43+
self.channel_id = client.conversations_create(name=channel_name, is_private=True,)[
4744
"channel"
4845
]["id"]
4946

integration_tests/web/test_calls.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ def tearDown(self):
2424

2525
def test_sync(self):
2626
client = self.sync_client
27-
user_id = list(
28-
filter(
29-
lambda u: not u["deleted"] and "bot_id" not in u,
30-
client.users_list(limit=50)["members"],
31-
)
32-
)[
27+
user_id = list(filter(lambda u: not u["deleted"] and "bot_id" not in u, client.users_list(limit=50)["members"],))[
3328
0
3429
]["id"]
3530

slack_sdk/web/async_client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,32 @@ async def files_completeUploadExternal(
36583658
)
36593659
return await self.api_call("files.completeUploadExternal", params=kwargs)
36603660

3661+
async def functions_completeSuccess(
3662+
self,
3663+
*,
3664+
function_execution_id: str,
3665+
outputs: Dict[str, Any],
3666+
**kwargs,
3667+
) -> AsyncSlackResponse:
3668+
"""Signal the successful completion of a function
3669+
https://api.slack.com/methods/functions.completeSuccess
3670+
"""
3671+
kwargs.update({"function_execution_id": function_execution_id, "outputs": json.dumps(outputs)})
3672+
return await self.api_call("functions.completeSuccess", params=kwargs)
3673+
3674+
async def functions_completeError(
3675+
self,
3676+
*,
3677+
function_execution_id: str,
3678+
error: str,
3679+
**kwargs,
3680+
) -> AsyncSlackResponse:
3681+
"""Signal the failure to execute a function
3682+
https://api.slack.com/methods/functions.completeError
3683+
"""
3684+
kwargs.update({"function_execution_id": function_execution_id, "error": error})
3685+
return await self.api_call("functions.completeError", params=kwargs)
3686+
36613687
# --------------------------
36623688
# Deprecated: groups.*
36633689
# You can use conversations.* APIs instead.

slack_sdk/web/client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,6 +3649,32 @@ def files_completeUploadExternal(
36493649
)
36503650
return self.api_call("files.completeUploadExternal", params=kwargs)
36513651

3652+
def functions_completeSuccess(
3653+
self,
3654+
*,
3655+
function_execution_id: str,
3656+
outputs: Dict[str, Any],
3657+
**kwargs,
3658+
) -> SlackResponse:
3659+
"""Signal the successful completion of a function
3660+
https://api.slack.com/methods/functions.completeSuccess
3661+
"""
3662+
kwargs.update({"function_execution_id": function_execution_id, "outputs": json.dumps(outputs)})
3663+
return self.api_call("functions.completeSuccess", params=kwargs)
3664+
3665+
def functions_completeError(
3666+
self,
3667+
*,
3668+
function_execution_id: str,
3669+
error: str,
3670+
**kwargs,
3671+
) -> SlackResponse:
3672+
"""Signal the failure to execute a function
3673+
https://api.slack.com/methods/functions.completeError
3674+
"""
3675+
kwargs.update({"function_execution_id": function_execution_id, "error": error})
3676+
return self.api_call("functions.completeError", params=kwargs)
3677+
36523678
# --------------------------
36533679
# Deprecated: groups.*
36543680
# You can use conversations.* APIs instead.

slack_sdk/web/legacy_client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,32 @@ def files_completeUploadExternal(
36603660
)
36613661
return self.api_call("files.completeUploadExternal", params=kwargs)
36623662

3663+
def functions_completeSuccess(
3664+
self,
3665+
*,
3666+
function_execution_id: str,
3667+
outputs: Dict[str, Any],
3668+
**kwargs,
3669+
) -> Union[Future, SlackResponse]:
3670+
"""Signal the successful completion of a function
3671+
https://api.slack.com/methods/functions.completeSuccess
3672+
"""
3673+
kwargs.update({"function_execution_id": function_execution_id, "outputs": json.dumps(outputs)})
3674+
return self.api_call("functions.completeSuccess", params=kwargs)
3675+
3676+
def functions_completeError(
3677+
self,
3678+
*,
3679+
function_execution_id: str,
3680+
error: str,
3681+
**kwargs,
3682+
) -> Union[Future, SlackResponse]:
3683+
"""Signal the failure to execute a function
3684+
https://api.slack.com/methods/functions.completeError
3685+
"""
3686+
kwargs.update({"function_execution_id": function_execution_id, "error": error})
3687+
return self.api_call("functions.completeError", params=kwargs)
3688+
36633689
# --------------------------
36643690
# Deprecated: groups.*
36653691
# You can use conversations.* APIs instead.

tests/slack_sdk_async/web/test_web_client_coverage.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ async def run_method(self, method_name, method, async_method):
640640
elif method_name == "files_completeUploadExternal":
641641
self.api_methods_to_call.remove(method(files=[{"id": "F111"}])["method"])
642642
await async_method(files=[{"id": "F111"}])
643+
elif method_name == "functions_completeSuccess":
644+
self.api_methods_to_call.remove(method(function_execution_id="Fn111", outputs={"num": 123}))
645+
await async_method(function_execution_id="Fn111", outputs={"num": 123})
646+
elif method_name == "functions_completeError":
647+
self.api_methods_to_call.remove(method(function_execution_id="Fn111", error="something wrong"))
648+
await async_method(function_execution_id="Fn111", error="something wrong")
643649
elif method_name == "migration_exchange":
644650
self.api_methods_to_call.remove(method(users="U123,U234")["method"])
645651
method(users="U123,U234")

0 commit comments

Comments
 (0)