def slash_command(request): """ Handles slash commands from slack More details here: https://api.slack.com/slash-commands @param request the request from slack containing the slash command @return: return a HTTP response to indicate the request was handled """ user_id = request.POST.get("user_id") trigger_id = request.POST.get("trigger_id") report = request.POST.get("text") dialog = Dialog( title="Report an Incident", submit_label="Report", elements=[ Text( label="Report", name="report", placeholder="What's the tl;dr?", value=report, ), TextArea( label="Summary", name="summary", optional=False, placeholder="Can you share any more details?", ), TextArea( label="Impact", name="impact", optional=False, placeholder="Who or what might be affected?", hint="Think about affected people, systems, and processes", ), # SelectFromUsers(label="Lead", name="lead", optional=True), SelectWithOptions( [(s.capitalize(), i) for i, s in Incident.SEVERITIES], label="Severity", name="severity", optional=False, ), SelectWithOptions( [("Yes", "yes"), ("No", "no")], label="Send page to pagerduty schedule?", name="pdschedule", optional=True, placeholder="Select whether to page on-call schedule", ), ], ) logger.info( f"Handling Slack slash command for user {user_id}, report {report} - opening dialog" ) dialog.send_open_dialog(INCIDENT_REPORT_DIALOG, trigger_id) return HttpResponse()
def handle_edit_incident_button(ac: ActionContext): dialog = Dialog( title=f"Edit Incident {ac.incident.pk}", submit_label="Save", state=ac.incident.pk, elements=[ Text(label="Report", name="report", value=ac.incident.report), TextArea(label="Summary", name="summary", value=ac.incident.summary, optional=True, placeholder="Can you share any more details?"), TextArea( label="Impact", name="impact", value=ac.incident.impact, optional=True, placeholder="Who or what might be affected?", hint="Think about affected people, systems, and processes"), SelectFromUsers(label="Lead", name="lead", value=ac.incident.lead.external_id if ac.incident.lead else None, optional=True), SelectWithOptions([(s.capitalize(), i) for i, s in Incident.SEVERITIES], value=ac.incident.severity, label="Severity", name="severity", optional=True) ]) dialog.send_open_dialog(INCIDENT_EDIT_DIALOG, ac.trigger_id)
def slash_command(request): """ Handles slash commands from slack More details here: https://api.slack.com/slash-commands Note: The order the elements are specified is the order they appear in the slack dialog @param request the request from slack containing the slash command @return: return a HTTP response to indicate the request was handled """ user_id = request.POST.get("user_id") trigger_id = request.POST.get("trigger_id") channel_id = request.POST.get("channel_id") text = request.POST.get("text").split(" ") command_name = text.pop(0) message = " ".join(text) if command_name == INCIDENT_CREATE_SLUG: name = get_user_profile(user_id)["name"] dialog = Dialog( title="Report an Incident", submit_label="Report", elements=[ Text( label="Title", name="report", placeholder="What's happened, in a sentence?", value=message, ) ], ) if hasattr(settings, "INCIDENT_REPORT_CHANNEL_ID"): dialog.add_element( SelectWithOptions( [ ("Yes - this is a live incident happening right now", "live"), ( "No - this is just a report of something that happened", "report", ), ], label="Is this a live incident?", name="incident_type", optional=False, ) ) dialog.add_element( TextArea( label="Summary", name="summary", optional=True, placeholder="Can you share any more details?", ) ) dialog.add_element( TextArea( label="Impact", name="impact", optional=True, placeholder="Who or what might be affected?", hint="Think about affected people, systems, and processes", ) ) dialog.add_element(SelectFromUsers(label="Lead", name="lead", optional=True)) dialog.add_element( SelectWithOptions( [(s.capitalize(), i) for i, s in Incident.SEVERITIES], label="Severity", name="severity", optional=True, ) ) dialog.send_open_dialog(INCIDENT_REPORT_DIALOG, trigger_id) logger.info( f"Handling Slack slash command for user {user_id}, command {command_name} - opening dialog" ) elif command_name not in get_commands(): settings.SLACK_CLIENT.send_ephemeral_message( channel_id, user_id, get_create_help(), ) else: handle_incident_command( command_name=command_name, message=message, user_id=user_id, channel_id=channel_id, thread_ts=None, ) return HttpResponse()
def slash_command(request): """ Handles slash commands from slack More details here: https://api.slack.com/slash-commands Note: The order the elements are specified is the order they appear in the slack dialog @param request the request from slack containing the slash command @return: return a HTTP response to indicate the request was handled """ user_id = request.POST.get("user_id") channel_id = request.POST.get("channel_id") trigger_id = request.POST.get("trigger_id") report = request.POST.get("text") if ( settings.INCIDENT_REPORT_CHANNEL_ID and channel_id != settings.INCIDENT_REPORT_CHANNEL_ID ): settings.SLACK_CLIENT.send_ephemeral_message( channel_id, user_id, f"Looks like you are trying to report an incident in the wrong " f"channel :thinking_face:\n" f"The correct place is <#{settings.INCIDENT_REPORT_CHANNEL_ID}>", ) return HttpResponse() dialog = Dialog( title="Report an Incident", submit_label="Report", elements=[ Text( label="Title", name="report", placeholder="What's happened, in a sentence?", value=report, ) ], ) if hasattr(settings, "INCIDENT_REPORT_CHANNEL_ID"): dialog.add_element( SelectWithOptions( [ ("Yes - this is a live incident happening right now", "live"), ("No - this is just a report of something that happened", "report"), ], label="Is this a live incident?", name="incident_type", optional=False, ) ) dialog.add_element( TextArea( label="Summary", name="summary", optional=True, placeholder="Can you share any more details?", ) ) dialog.add_element( TextArea( label="Impact", name="impact", optional=True, placeholder="Who or what might be affected?", hint="Think about affected people, systems, and processes", ) ) dialog.add_element(SelectFromUsers(label="Lead", name="lead", optional=True)) dialog.add_element( SelectWithOptions( [(s.capitalize(), i) for i, s in Incident.SEVERITIES], label="Severity", name="severity", optional=True, ) ) logger.info( f"Handling Slack slash command for user {user_id}, report {report} - opening dialog" ) dialog.send_open_dialog(INCIDENT_REPORT_DIALOG, trigger_id) return HttpResponse()
def slash_command(request): """ Handles slash commands from slack More details here: https://api.slack.com/slash-commands @param request the request from slack containing the slash command @return: return a HTTP response to indicate the request was handled """ user_id = request.POST.get("user_id") trigger_id = request.POST.get("trigger_id") report = request.POST.get("text") dialog = Dialog( title="Report an Incident", submit_label="Report", elements=[ Text( label="Report", name="report", placeholder="What's the tl;dr?", value=report, ), TextArea( label="Summary", name="summary", optional=True, placeholder="Can you share any more details?", ), TextArea( label="Impact", name="impact", optional=True, placeholder="Who or what might be affected?", hint="Think about affected people, systems, and processes", ), SelectFromUsers(label="Lead", name="lead", optional=True), SelectWithOptions( [(s.capitalize(), i) for i, s in Incident.SEVERITIES], label="Severity", name="severity", optional=True, ), ], ) if hasattr(settings, "INCIDENT_REPORT_CHANNEL_ID"): dialog.add_element( SelectWithOptions( [ ("Yes - this is a live incident happening right now", "live"), ("No - this is just a report of something that happened", "report"), ], label="Is this a live incident?", name="incident_type", optional=False, ) ) logger.info( f"Handling Slack slash command for user {user_id}, report {report} - opening dialog" ) dialog.send_open_dialog(INCIDENT_REPORT_DIALOG, trigger_id) return HttpResponse()