Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from leventyalcin/slack
Browse files Browse the repository at this point in the history
Slack integration added
  • Loading branch information
deathowl committed Jun 2, 2014
2 parents 3b92a67 + eebcbf8 commit db50d89
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class UserNotificationMethod(models.Model):
METHOD_EMAIL = 'email'
METHOD_PUSHOVER = 'pushover'
METHOD_XMPP = 'xmpp'
METHOD_SLACK = 'slack'

methods = [METHOD_XMPP, METHOD_PUSHOVER, METHOD_EMAIL, METHOD_TWILIO_SMS, METHOD_TWILIO_CALL]
methods = [METHOD_XMPP, METHOD_PUSHOVER, METHOD_EMAIL, METHOD_TWILIO_SMS, METHOD_TWILIO_CALL, METHOD_SLACK]

user = models.ForeignKey(User, related_name='notification_methods')
position = models.IntegerField()
Expand Down
14 changes: 14 additions & 0 deletions notification/notifier/slack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from slacker import Slacker

class SlackNotifier:

def __init__(self, config):
self.__config = config

def notify(self, notification):
slack = Slacker(self.__config['apikey'])
response = slack.chat.post_message(self.__config['channel'], notification.message)
if not response.error:
print "Slack message sent"
else:
print "Failed to send Slack message"
2 changes: 2 additions & 0 deletions notification/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def send_notifications(notification_id):
notifier = TwilioSmsNotifier(settings.TWILIO_SETTINGS)
if notification.notifier == UserNotificationMethod.METHOD_TWILIO_CALL:
notifier = TwilioCallNotifier(settings.TWILIO_SETTINGS)
if notification.notifier == UserNotificationMethod.METHOD_SLACK:
notifier = SlackNotifier(settings.SLACK_SETTINGS)
elif notification.notifier == UserNotificationMethod.METHOD_PUSHOVER:
notifier = PushoverNotifier()
notifier.notify(notification)
Expand Down
3 changes: 3 additions & 0 deletions openduty/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
TWILIO_SETTINGS = {
}

SLACK_SETTINGS = {
}

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pyasn1_modules
dnspython
oauth2client
sleekxmpp
dj-database-url
dj-database-url
slacker

0 comments on commit db50d89

Please sign in to comment.