def handle_close_incident(incident: Incident, user_id: str, message: json, trigger_id: str): incident.end_time = datetime.now() # incident.save() try: if CommsChannel.objects.filter(incident=incident).exists(): chan = CommsChannel.objects.get(incident=incident) if chan is not None: leave_channel(chan.channel_id) archive_channel(chan.channel_id) incident.save() except Exception as e: print(str(e)) pass
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) # Invite the bot to the channel invite_user_to_channel(settings.INCIDENT_BOT_ID, comms_channel.channel_id) # Un-invite the user who owns the Slack token, # otherwise they'll be added to every incident channel slack_token_owner = get_slack_token_owner() if ac.incident.reporter != slack_token_owner: leave_channel(comms_channel.channel_id) # 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()