response icon indicating copy to clipboard operation
response copied to clipboard

Building features on top of demo application

Open ckennedy-proto opened this issue 6 years ago • 5 comments

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.

ckennedy-proto avatar Aug 28 '19 14:08 ckennedy-proto

Related to #58

AshleyPoole avatar Aug 29 '19 11:08 AshleyPoole

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?

ckennedy-proto avatar Aug 31 '19 00:08 ckennedy-proto

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 avatar Sep 04 '19 13:09 milesbxf

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

milesbxf avatar Sep 04 '19 13:09 milesbxf

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.

ckennedy-proto avatar Sep 09 '19 17:09 ckennedy-proto