monzo / response

Monzo's real-time incident response and reporting tool ⚡️
MIT License
1.53k stars 165 forks source link

Building features on top of demo application #118

Open ckennedy-proto opened 5 years ago

ckennedy-proto commented 5 years ago

Hello,

I am trying to leverage the packaged version, and adding additional functionality per this documentation: https://github.com/monzo/response/blob/master/docs/development.md

In manage.py I've added: import ui.keyword_handlers

I've created a new file called keyword_handlers.py:

import json
import re

from response.core.models.incident import Incident
from response.slack.models import HeadlinePost, CommsChannel, UserStats, PinnedMessage
from response.slack.decorators import slack_event, handle_incident_command, handle_keywords, keyword_handler

@keyword_handler(['status page', 'statuspage'])
def status_page_notification(comms_channel: CommsChannel, user: str, text: str, ts: str):
    comms_channel.post_in_channel(f"ℹ️ You mentioned the Status Page - <{settings.STATUS_PAGE_RUNBOOK}|here's the runbook> on how to put it up.")

This isn't working though. How can I add this additional functionality to the packaged version?

Thank you.

AshleyPoole commented 5 years ago

Related to #58

ckennedy-proto commented 5 years ago

To add to this a bit - it appears some of the default handlers are included in the packaged version such as:

:wave: Don't forget to fill out an incident report here: http://localhost:8000/incident/1/

Is there a way to modify these?

milesbxf commented 5 years ago

To your original question - that's odd 🤔 my first thought is that Python isn't importing that file, even though you've imported it in manage.py. Could you try adding an raise RuntimeError("test") to the main body of the file, and see if it loudly fails?

If not, then you might need to add the import somewhere else - e.g. app.py

milesbxf commented 5 years ago

As to overriding the default handlers, it's not possible just yet. We've done something like this for @incident_command, so e.g. you can override the @incident severity command like this:

@incident_command(['severity', 'sev'], helptext='Set the incident severity')
def set_severity(incident: Incident, user_id: str, message: str):
    logger.info("Handling severity command")

    for sev_id, sev_name in Incident.SEVERITIES:
        # look for sev name (e.g. critical) or sev id (1)
        if (sev_name in message) or (sev_id in message):
            incident.severity = sev_id
            incident.save()

            comms_channel.post_in_channel(f"Setting severity to {sev_name}")
            return True, None

    return False, None

I'd like to do something similar for handlers too

ckennedy-proto commented 5 years ago

I was able to work through this, thanks for the help.

In regards to the overriding - would it be possible to prioritize custom vs. built in, in a similar case as you've described for incident_command? That way any custom take priority, and if none exist for a specific command, then the default is chosen.