From 42e6937dcf1b979aa84dee5a09160451653e350e Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Wed, 27 Sep 2023 13:00:05 +0530 Subject: [PATCH] invoke shortcut via the shortcuts://run-shortcuts url --- routers/slack.py | 52 ++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/routers/slack.py b/routers/slack.py index fb1bf51a5..75ed8465e 100644 --- a/routers/slack.py +++ b/routers/slack.py @@ -239,7 +239,9 @@ def slack_oauth_shortcuts(): @router.get("/__/slack/redirect/shortcuts/") -def slack_connect_redirect_shortcuts(request: Request): +def slack_connect_redirect_shortcuts( + request: Request, shortcut_name: str = "Start Copilot" +): retry_button = f'Retry' code = request.query_params.get("code") @@ -286,17 +288,22 @@ def slack_connect_redirect_shortcuts(request: Request): ) sr = convo.bot_integration.saved_run - payload = json.dumps( - dict( - slack_channel=convo.slack_channel_name, - slack_channel_id=convo.slack_channel_id, - slack_user_access_token=access_token, - slack_team_id=team_id, - gooey_example_id=sr.example_id, - gooey_run_id=sr.run_id, - ), - indent=2, + slack_creds = dict( + slack_channel=convo.slack_channel_name, + slack_channel_id=convo.slack_channel_id, + slack_user_access_token=access_token, + slack_team_id=team_id, + gooey_example_id=sr.example_id, + gooey_run_id=sr.run_id, ) + shortcut_url = furl( + "shortcuts://run-shortcut", + query_params=dict( + name=shortcut_name, + input=json.dumps({"slack_creds": slack_creds}), + ), + ).tostr(query_quote_plus=False) + return HTMLResponse( # language=HTML """ @@ -305,24 +312,21 @@ def slack_connect_redirect_shortcuts(request: Request):

- +

-

- + + +

- - """ - % dict(payload=payload) + % dict( + slack_creds=json.dumps(slack_creds, indent=2), + shortcut_url=shortcut_url, + ) )