mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 14:10:52 -07:00
Add GroupMe notification agent
This commit is contained in:
parent
ae5777e612
commit
abf55df26d
1 changed files with 100 additions and 1 deletions
|
@ -87,7 +87,8 @@ AGENT_IDS = {'growl': 0,
|
||||||
'join': 18,
|
'join': 18,
|
||||||
'hipchat': 19,
|
'hipchat': 19,
|
||||||
'discord': 20,
|
'discord': 20,
|
||||||
'androidapp': 21
|
'androidapp': 21,
|
||||||
|
'groupme': 22
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,6 +117,10 @@ def available_notification_agents():
|
||||||
'name': 'facebook',
|
'name': 'facebook',
|
||||||
'id': AGENT_IDS['facebook']
|
'id': AGENT_IDS['facebook']
|
||||||
},
|
},
|
||||||
|
{'label': 'GroupMe',
|
||||||
|
'name': 'groupme',
|
||||||
|
'id': AGENT_IDS['groupme']
|
||||||
|
},
|
||||||
{'label': 'Growl',
|
{'label': 'Growl',
|
||||||
'name': 'growl',
|
'name': 'growl',
|
||||||
'id': AGENT_IDS['growl']
|
'id': AGENT_IDS['growl']
|
||||||
|
@ -362,6 +367,8 @@ def get_agent_class(agent_id=None, config=None):
|
||||||
return DISCORD(config=config)
|
return DISCORD(config=config)
|
||||||
elif agent_id == 21:
|
elif agent_id == 21:
|
||||||
return ANDROIDAPP(config=config)
|
return ANDROIDAPP(config=config)
|
||||||
|
elif agent_id == 22:
|
||||||
|
return GROUPME(config=config)
|
||||||
else:
|
else:
|
||||||
return Notifier(config=config)
|
return Notifier(config=config)
|
||||||
else:
|
else:
|
||||||
|
@ -1503,6 +1510,98 @@ class FACEBOOK(Notifier):
|
||||||
return config_option
|
return config_option
|
||||||
|
|
||||||
|
|
||||||
|
class GROUPME(Notifier):
|
||||||
|
"""
|
||||||
|
GroupMe notifications
|
||||||
|
"""
|
||||||
|
_DEFAULT_CONFIG = {'access_token': '',
|
||||||
|
'bot_id': '',
|
||||||
|
'incl_subject': 1,
|
||||||
|
'incl_poster': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
def notify(self, subject='', body='', action='', **kwargs):
|
||||||
|
if not subject or not body:
|
||||||
|
return
|
||||||
|
|
||||||
|
data = {'bot_id': self.config['bot_id']}
|
||||||
|
|
||||||
|
if self.config['incl_subject']:
|
||||||
|
data['text'] = subject.encode('utf-8') + '\r\n' + body.encode('utf-8')
|
||||||
|
else:
|
||||||
|
data['text'] = body.encode('utf-8')
|
||||||
|
|
||||||
|
if self.config['incl_poster'] and kwargs.get('parameters'):
|
||||||
|
parameters = kwargs['parameters']
|
||||||
|
poster_url = parameters.get('poster_url','')
|
||||||
|
|
||||||
|
if poster_url:
|
||||||
|
headers = {'X-Access-Token': self.config['access_token'],
|
||||||
|
'Content-Type': 'image/jpeg'}
|
||||||
|
poster_data = urllib.urlopen(poster_url).read()
|
||||||
|
|
||||||
|
response = requests.post('https://image.groupme.com/pictures',
|
||||||
|
headers=headers,
|
||||||
|
data=poster_data)
|
||||||
|
request_status = response.status_code
|
||||||
|
request_content = json.loads(response.text)
|
||||||
|
|
||||||
|
if request_status == 200:
|
||||||
|
logger.info(u"PlexPy Notifiers :: GroupMe poster sent.")
|
||||||
|
data['attachments'] = [{'type': 'image',
|
||||||
|
'url': request_content['payload']['picture_url']}]
|
||||||
|
elif request_status >= 400 and request_status <= 500:
|
||||||
|
logger.warn(u"PlexPy Notifiers :: GroupMe poster failed: %s" % request_content.get('errors'))
|
||||||
|
else:
|
||||||
|
logger.warn(u"PlexPy Notifiers :: GroupMe poster failed.")
|
||||||
|
|
||||||
|
http_handler = HTTPSConnection("api.groupme.com")
|
||||||
|
http_handler.request("POST",
|
||||||
|
"/v3/bots/post",
|
||||||
|
body=json.dumps(data))
|
||||||
|
response = http_handler.getresponse()
|
||||||
|
request_status = response.status
|
||||||
|
|
||||||
|
if request_status == 202:
|
||||||
|
logger.info(u"PlexPy Notifiers :: GroupMe notification sent.")
|
||||||
|
return True
|
||||||
|
elif request_status >= 400 and request_status < 500:
|
||||||
|
logger.warn(u"PlexPy Notifiers :: GroupMe notification failed: [%s] %s" % (request_status, response.reason))
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
logger.warn(u"PlexPy Notifiers :: GroupMe notification failed.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def return_config_options(self):
|
||||||
|
config_option = [{'label': 'GroupMe Access Token',
|
||||||
|
'value': self.config['access_token'],
|
||||||
|
'name': 'groupme_access_token',
|
||||||
|
'description': 'Your GroupMe access token.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'GroupMe Bot ID',
|
||||||
|
'value': self.config['bot_id'],
|
||||||
|
'name': 'groupme_bot_id',
|
||||||
|
'description': 'Your GroupMe bot ID.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'Include Subject Line',
|
||||||
|
'value': self.config['incl_subject'],
|
||||||
|
'name': 'groupme_incl_subject',
|
||||||
|
'description': 'Include the subject line with the notifications.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
|
},
|
||||||
|
{'label': 'Include Poster Image',
|
||||||
|
'value': self.config['incl_poster'],
|
||||||
|
'name': 'groupme_incl_poster',
|
||||||
|
'description': 'Include a poster with the notifications.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return config_option
|
||||||
|
|
||||||
|
|
||||||
class GROWL(Notifier):
|
class GROWL(Notifier):
|
||||||
"""
|
"""
|
||||||
Growl notifications, for OS X.
|
Growl notifications, for OS X.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue