From 1df61b766ec1df55e149b6282f5c444f1457f926 Mon Sep 17 00:00:00 2001 From: Andrew Dickinson Date: Tue, 10 Sep 2024 21:01:40 -0400 Subject: [PATCH 1/2] Add 'trust me bro' mode --- supportbot/supportbot/app.py | 17 +++++++++ supportbot/supportbot/request_handler.py | 32 ++++++++++++---- .../supportbot/utils/block_kit_templates.py | 37 +++++++++++++++++++ 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/supportbot/supportbot/app.py b/supportbot/supportbot/app.py index 112a0fa..7207018 100644 --- a/supportbot/supportbot/app.py +++ b/supportbot/supportbot/app.py @@ -44,6 +44,23 @@ def open_modal(ack, shortcut, client): ) ) + @app.action("confirm_bad_network_number") + def confirm_bad_network_number(ack, body, logger, view, action, shortcut): + ack() + + metadata = json.loads(action['value']) + network_number = metadata['network_number_override'] + + requests.post(body['response_url'], json = { + 'response_type': 'ephemeral', + 'text': '', + 'replace_original': True, + 'delete_original': True + }) + + handle_support_request(app, config, metadata['user'], metadata['channel'], metadata['ts'], + manual_number=network_number, force_nn=True) + # Manual shorcut button flow @app.view("manually_run_diagnostics") diff --git a/supportbot/supportbot/request_handler.py b/supportbot/supportbot/request_handler.py index 4c0988a..c20582a 100644 --- a/supportbot/supportbot/request_handler.py +++ b/supportbot/supportbot/request_handler.py @@ -5,7 +5,7 @@ from supportbot.utils.diagnostics_report import upload_report_file, get_report from supportbot.utils.user_data import MeshUser import subprocess -from supportbot.utils.block_kit_templates import confrimation_dialog_block_kit, help_suggestion_message_block_kit +from supportbot.utils.block_kit_templates import confirmation_of_bad_nn_block_kit from slack_bolt import App def nn_to_map_url(nn): @@ -13,13 +13,18 @@ def nn_to_map_url(nn): return f'<{base}-{nn}|NN{nn}>' -def handle_support_request(app, config, user_id, channel_id, message_ts, manual_number=None): +def handle_support_request(app, config, user_id, channel_id, message_ts, manual_number=None, force_nn=False): database_client = MeshDBDatabaseClient(os.environ.get("MESHDB_AUTH_TOKEN")) user = MeshUser(app, user_id, config['nn_property_id'], database_client=database_client) network_number = None + include_override_button_in_response = False if manual_number: - manual_nn = database_client.get_nn(int(manual_number)) + if not force_nn: + manual_nn = database_client.get_nn(int(manual_number)) + else: + manual_nn = manual_number + if manual_nn: network_number = manual_nn text = ( @@ -32,6 +37,7 @@ def handle_support_request(app, config, user_id, channel_id, message_ts, manual_ f"Entered number: {manual_number} could not be found. Please check the number is a " f"valid install or network number and try again" ) + include_override_button_in_response = True else: if user.network_number: network_number = user.network_number @@ -47,11 +53,21 @@ def handle_support_request(app, config, user_id, channel_id, message_ts, manual_ "your number in our system to better assist you." ) - app.client.chat_postMessage( - channel=channel_id, - thread_ts=message_ts, - text=text - ) + message_fields = { + "channel": channel_id, + "thread_ts": message_ts, + "text": text, + } + if include_override_button_in_response: + message_fields["blocks"] = confirmation_of_bad_nn_block_kit( + channel_id, + message_ts, + user_id, + manual_number, + text + )['blocks'] + + app.client.chat_postMessage(**message_fields) if network_number: try: diff --git a/supportbot/supportbot/utils/block_kit_templates.py b/supportbot/supportbot/utils/block_kit_templates.py index 5f384b6..e1cd45b 100644 --- a/supportbot/supportbot/utils/block_kit_templates.py +++ b/supportbot/supportbot/utils/block_kit_templates.py @@ -151,4 +151,41 @@ def help_suggestion_dialog_block_kit(channel_id, message_ts, user_id, nn=None): "emoji": True }}, ] + } + + +def confirmation_of_bad_nn_block_kit(channel_id, message_ts, user_id, network_number, message): + return { + "blocks": [ + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": message + } + ] + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "emoji": True, + "text": "I understand, run anyway" + }, + "value": + json.dumps({ + 'channel': channel_id, + 'ts': message_ts, + 'user': user_id, + 'network_number_override': network_number, + }), + "action_id": "confirm_bad_network_number", + }, + ] + }, + ] } \ No newline at end of file From 70213d6a5d9d00dcb9a46ac2a6a049cbda9747ce Mon Sep 17 00:00:00 2001 From: Andrew Dickinson Date: Sat, 14 Sep 2024 02:05:38 -0400 Subject: [PATCH 2/2] Add text indicating "trust me bro" mode was used --- supportbot/supportbot/request_handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/supportbot/supportbot/request_handler.py b/supportbot/supportbot/request_handler.py index c20582a..5a0fc26 100644 --- a/supportbot/supportbot/request_handler.py +++ b/supportbot/supportbot/request_handler.py @@ -30,6 +30,7 @@ def handle_support_request(app, config, user_id, channel_id, message_ts, manual_ text = ( f"The network number entered was {nn_to_map_url(network_number)}" + (f" (via install #{manual_number})" if int(manual_number) != int(network_number) else "") + + (f". This node could not be found in MeshDB, continuing anyway due to an override" if force_nn else "") + f". Diagnostic report running..." ) else: