def send_help_text(incident: Incident, user_id: str, message: str): comms_channel = CommsChannel.objects.get(incident=incident) settings.SLACK_CLIENT.send_ephemeral_message( comms_channel.channel_id, user_id, get_help(), ) return True, None
def handle_create_comms_channel(ac: ActionContext): if CommsChannel.objects.filter(incident=ac.incident).exists(): return comms_channel = CommsChannel.objects.create_comms_channel(ac.incident) # Update the headline post to link to this headline_post = HeadlinePost.objects.get(incident=ac.incident) headline_post.comms_channel = comms_channel headline_post.save() comms_channel.post_in_channel(get_help())
def send_help_text(incident: Incident, user_id: str, message: str): return True, get_help()
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(): if channel_id == settings.INCIDENT_CHANNEL_ID: settings.SLACK_CLIENT.send_ephemeral_message( channel_id, user_id, get_create_help(), ) else: comms_channel = CommsChannel.objects.filter(channel_id=channel_id).first() if comms_channel is not None: settings.SLACK_CLIENT.send_ephemeral_message( channel_id, user_id, get_help(), ) else: settings.SLACK_CLIENT.send_ephemeral_message( channel_id, user_id, 'This is not the incident channel, please head over #'+settings.INCIDENT_CHANNEL_NAME, ) else: handle_incident_command( command_name=command_name, message=message, user_id=user_id, channel_id=channel_id, thread_ts=None, ) return HttpResponse()