1
0
mirror of https://github.com/linkedin/oncall.git synced 2025-11-27 23:18:38 +02:00

Add teams messenger (#239)

* Add teams messenger

* Add pymsteams in setup

* Fix style
This commit is contained in:
Harshit Sharma
2019-02-26 05:05:19 +05:30
committed by Daniel Wang
parent 9542f74b34
commit b688b3c885
5 changed files with 30 additions and 3 deletions

View File

@@ -88,7 +88,7 @@ notifications:
# Reminders are sent using these modes of contact
default_modes:
- "email"
# - "teams_messenger"
# Reminder task settings
reminder:
activated: True
@@ -103,6 +103,9 @@ user_validator:
# Reminders sent using these messengers
messengers:
# - type: teams_messenger
# webhook: "channel_webhook_url"
#
# - type: rocketchat_messenger
# user: username
# password: abc123

View File

@@ -312,7 +312,7 @@ CREATE TABLE IF NOT EXISTS `contact_mode` (
-- Initialize contact modes
-- -----------------------------------------------------
INSERT INTO `contact_mode` (`name`)
VALUES ('email'), ('sms'), ('call'), ('slack');
VALUES ('email'), ('sms'), ('call'), ('slack'), ('teams_messenger');
-- -----------------------------------------------------
-- Table `user_contact`

View File

@@ -31,7 +31,8 @@ setuptools.setup(
'pytz',
'irisclient',
'slackclient',
'icalendar'
'icalendar',
'pymsteams'
],
extras_require={
'ldap': ['python-ldap'],

View File

@@ -6,6 +6,7 @@ SMS_SUPPORT = 'sms'
CALL_SUPPORT = 'call'
SLACK_SUPPORT = 'slack'
ROCKET_SUPPORT = 'rocketchat'
TEAMS_SUPPORT = 'teams_messenger'
ONCALL_REMINDER = 'oncall_reminder'
OFFCALL_REMINDER = 'offcall_reminder'

View File

@@ -0,0 +1,22 @@
import pymsteams
import logging
from oncall.constants import TEAMS_SUPPORT
class teams_messenger(object):
supports = frozenset([TEAMS_SUPPORT])
def __init__(self, config):
self.webhook = config['webhook']
def send(self, message):
heading = message.get("subject")
final_message = "User: " + message.get("user") + " Message: " + message.get("body")
try:
myTeamsMessage = pymsteams.connectorcard(self.webhook)
myTeamsMessage.title(str(heading))
myTeamsMessage.text(str(final_message))
myTeamsMessage.send()
except:
logging.info("An issue occured while sending message to teams messenger")