def send_failure_alert_telegram(printer, rotated_jpg_url, is_warning, print_paused): if not printer.user.telegram_chat_id: return try: photo = requests.get(rotated_jpg_url).content except: photo = None action = '' button_list = ['more_info'] if print_paused: action = 'The print is paused.' button_list = ['cancel', 'resume', 'do_not_ask', 'more_info'] elif printer.action_on_failure == Printer.PAUSE and is_warning: action = 'Printer is NOT paused because The Detective is not very sure about it.' button_list = ['cancel', 'more_info'] notification_text = f"""Hi {printer.user.first_name or ''}, _The Spaghetti Detective_ spotted some suspicious activity on your printer *{printer.name}*. {action}""" try: send_telegram_notification(printer, notification_text, photo, buttons=button_list) except requests.ConnectionError as e: LOGGER.error(e)
def send_print_notification_telegram(_print, event_type=None): if not _print.printer.user.telegram_chat_id: return try: photo = requests.get(_print.poster_url).content except: photo = None body = get_notification_body(_print, event_type=event_type) notification_text = f"Hi {_print.printer.user.first_name or ''},\n\n{body}" try: send_telegram_notification(_print.printer, notification_text, photo) except requests.ConnectionError as e: LOGGER.error(e)
def send_print_notification_telegram(_print): if not _print.printer.user.telegram_chat_id: return try: photo = requests.get(_print.poster_url).content except: photo = None notification_text = f"""Hi {_print.printer.user.first_name or ''}, Your print job *{_print.filename}* {'has been canceled' if _print.is_canceled() else 'is done'} on printer {_print.printer.name}. """ try: send_telegram_notification(_print.printer, notification_text, photo) except requests.ConnectionError as e: LOGGER.error(e)