Skip to content

Commit

Permalink
Add 'trust me bro' mode (#108)
Browse files Browse the repository at this point in the history
* Add 'trust me bro' mode

* Add text indicating "trust me bro" mode was used
  • Loading branch information
Andrew-Dickinson authored Sep 16, 2024
1 parent 3a9603d commit ba4309e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
17 changes: 17 additions & 0 deletions supportbot/supportbot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 25 additions & 8 deletions supportbot/supportbot/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@
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):
base = 'https://www.nycmesh.net/map/nodes/'
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 = (
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:
text = (
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
Expand All @@ -47,11 +54,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:
Expand Down
37 changes: 37 additions & 0 deletions supportbot/supportbot/utils/block_kit_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
},
]
}

0 comments on commit ba4309e

Please sign in to comment.