import telegram
import json


with open("lib/settings.json", "r") as settings_json:
    settings = json.load(settings_json)
    notification_settings = settings["NotificationSettings"]["Telegram"]


'''
Basic Notification
- acc_name: e.g. "admin"
- message: message to send
'''
class Notification:
    def __init__(self, acc_name, message):
        self.acc_name = acc_name
        self.message = message


'''
Send Notifications via Telegram Bot
'''
class TelegramNotification(Notification):
    def __init__(self, acc_name, message):
        super().__init__(acc_name, message)
        self.token = notification_settings["Bot_API_Key"]

    def send_message(self):
        if notification_settings["Get_Notification"]:
            tgb = telegram.Bot(token=self.token)
            try:
                tgb.send_message(
                    notification_settings["Chat_ID"],
                    self.message,
                    parse_mode='Markdown'
                )
            # any more elegant possibility to catch all network related errors?
            except Exception as e:
                print(f"Connection Error\n{e}")