Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building features on top of demo application #118

Open
ckennedy-proto opened this issue Aug 28, 2019 · 5 comments
Open

Building features on top of demo application #118

ckennedy-proto opened this issue Aug 28, 2019 · 5 comments

Comments

@ckennedy-proto
Copy link

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
Copy link
Contributor

Related to #58

@ckennedy-proto
Copy link
Author

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

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

Is there a way to modify these?

@milesbxf
Copy link
Contributor

milesbxf commented Sep 4, 2019

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
Copy link
Contributor

milesbxf commented Sep 4, 2019

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants