Skip to content

Commit

Permalink
Merge pull request #364 from swar/telegram-notifications
Browse files Browse the repository at this point in the history
Adding Telegram Notifications
  • Loading branch information
swar authored May 15, 2021
2 parents 7d87179 + df9cddc commit 8b8a88b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion config.yaml.default
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ notifications:
notify_pushover: false
pushover_user_key: xx
pushover_api_key: xx


# TELEGRAM
notify_telegram: false
telegram_token: xxxxx

# TWILIO
notify_twilio: false
twilio_account_sid: xxxxx
Expand Down
2 changes: 1 addition & 1 deletion plotmanager/library/parse/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _get_notifications_settings(config):
raise InvalidYAMLConfigException('Failed to find notifications parameter in the YAML.')
notifications = config['notifications']
expected_parameters = ['notify_discord', 'discord_webhook_url', 'notify_sound', 'song', 'notify_pushover',
'pushover_user_key', 'pushover_api_key']
'pushover_user_key', 'pushover_api_key', 'telegram_token']
_check_parameters(parameter=notifications, expected_parameters=expected_parameters, parameter_type='notification')
return notifications

Expand Down
7 changes: 7 additions & 0 deletions plotmanager/library/utilities/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def test_configuration(chia_location, notification_settings, instrumentation_set
raise MissingImportError('Failed to find import "pushover". Be sure to run "pip install -r '
'requirements-notification.txt".')

if instrumentation_settings.get('notify_telegram'):
try:
import telegram_notifier
except ImportError:
raise MissingImportError('Failed to find import "telegram_notifier". Be sure to run "pip install -r '
'requirements-notification.txt".')

if instrumentation_settings.get('prometheus_enabled'):
try:
import prometheus_client
Expand Down
5 changes: 5 additions & 0 deletions plotmanager/library/utilities/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def _send_notifications(title, body, settings):
import pushover
client = pushover.Client(settings.get('pushover_user_key'), api_token=settings.get('pushover_api_key'))
client.send_message(body, title=title)

if settings.get('notify_telegram') is True:
import telegram_notifier
notifier = telegram_notifier.TelegramNotifier(settings.get('telegram_token'), parse_mode="HTML")
notifier.send(body)


def send_notifications(title, body, settings):
Expand Down
3 changes: 2 additions & 1 deletion requirements-notification.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
discord_notify==1.0.0
playsound==1.2.2
prometheus-client==0.10.1
python_pushover==0.4
python_pushover==0.4
telegram_notifier==0.2

0 comments on commit 8b8a88b

Please sign in to comment.