mirror of https://github.com/l3uddz/traktarr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
import requests
|
|
|
|
from misc.log import logger
|
|
|
|
log = logger.get_logger(__name__)
|
|
|
|
|
|
class Slack:
|
|
NAME = "Slack"
|
|
|
|
def __init__(self, webhook_url, sender_name='traktarr', sender_icon=':movie_camera:', channel=None):
|
|
self.webhook_url = webhook_url
|
|
self.sender_name = sender_name
|
|
self.sender_icon = sender_icon
|
|
self.channel = channel
|
|
log.debug("Initialized Slack notification agent")
|
|
|
|
def send(self, **kwargs):
|
|
if not self.webhook_url or not self.sender_name or not self.sender_icon:
|
|
log.error("You must specify an webhook_url, sender_name and sender_icon when initializing this class")
|
|
return False
|
|
|
|
# send notification
|
|
try:
|
|
payload = {
|
|
'text': kwargs['message'],
|
|
'username': self.sender_name,
|
|
'icon_emoji': self.sender_icon,
|
|
}
|
|
if self.channel:
|
|
payload['channel'] = self.channel
|
|
|
|
resp = requests.post(self.webhook_url, json=payload, timeout=30)
|
|
return True if resp.status_code == 200 else False
|
|
|
|
except Exception:
|
|
log.exception("Error sending notification to %r", self.webhook_url)
|
|
return False
|