Skip to content

Following is an upgrade to the d:\FSS\Software\Utils\PythonUtils\notify_manager.py utility to provide robust texting for URGENT notifications (like website or web app offline).

Source: Gemini


=> Before using Telegram solution for cell notification

  • still prefer “normal” cell carrier solution, not requiring additional app
  • research better solution: Twilio free usage sufficient for minimal texts?
  • App: Install Telegram on your phone and register.

  • Bot: Message @BotFather, type /newbot, and save the API Token.

  • ID: Message @userinfobot to get your numeric Chat ID.

  • Verification: Run the test_telegram.py script provided above.

  • Integration: Update notify_manager.py with the new urllib logic.

  • .env: Now ignored globally by Git via your C:\Users\Admin\.gitignore_global.

  • History: All existing .git repos under D:\FSS have been purged of .env files using your new purge-git.ps1.

  • Remotes: Remember to run git push origin --force --all only if you eventually decide to sync those folders to a remote server.


Since you have never used Telegram, think of it as a professional-grade notification service for developers. It is much more reliable than SMS because it bypasses carrier spam filters entirely.

Here are the 5 steps to go from zero to receiving a notification on your phone.

Telegram is a messaging app available for all platforms. You need it installed to receive the “text” alerts.

  • On your Phone: Search for “Telegram Messenger” in the Google Play Store (Android) or App Store (iPhone).

  • On your Desktop (Optional): You can also get it at desktop.telegram.org to copy-paste tokens more easily.

  • Signup: Register with your phone number.

In Telegram, bots are created by talking to a master bot called the “BotFather.”

  1. In the Telegram app, tap the Search icon and type @BotFather.

  2. Tap on the one with the blue checkmark.

  3. Press Start (or type /start).

  4. Type /newbot and follow the prompts:

    • Display Name: Give it a name (e.g., FSS Alerts).

    • Username: Give it a unique username ending in “bot” (e.g., tstevens_alerts_bot).

  5. The Result: It will give you an API Token (a long string of numbers and letters). Copy this down. This is your TELEGRAM_BOT_TOKEN.

Your bot needs to know who to send the message to. In Telegram, every user has a numeric ID.

  1. Search for your newly created bot username (e.g., @tstevens_alerts_bot) in Telegram and press Start.

  2. Search for the bot @userinfobot in Telegram and press Start.

  3. It will immediately reply with your Id (a 9 or 10-digit number). Copy this. This is your chat_id.

Now, update the two files you sent me earlier with these new values.

In D:\FSS\Software\Utils\PythonUtils\.env: Add your token at the bottom.

Plaintext

TELEGRAM_BOT_TOKEN=12345678:ABCDefghIJKLmnop_ExampleToken

In D:\FSS\Software\Utils\PythonUtils\Backups\my_backup.yaml.txt: Replace the old sms section with a telegram section.

YAML

notifications:
enabled: true
email:
# ... (keep your email settings as they are)
telegram:
enabled: true
chat_id: "123456789" # Put the number from @userinfobot here

I have streamlined the logic from your notify_manager.py to use the Telegram API.

Replace your NotificationManager class in notify_manager.py with this:

Python

import smtplib
import os
import urllib.parse
import urllib.request
import json
from email.message import EmailMessage
class NotificationManager:
def __init__(self, config):
self.config = config
self.enabled = config.get('enabled', False)
self.email_conf = config.get('email', {})
self.telegram_conf = config.get('telegram', {})
# Secrets from .env
self.email_password = os.getenv('EMAIL_PASSWORD')
self.tg_token = os.getenv('TELEGRAM_BOT_TOKEN')
def send_failure_alert(self, tool_name, errors):
if not self.enabled:
return
subject = f"FAILURE: {tool_name}"
error_list = "\n".join([f"- {e}" for e in errors])
# 1. Send Email
if self.email_password:
self._send_email(subject, error_list)
# 2. Send Telegram (if enabled)
if self.telegram_conf.get('enabled') and self.tg_token:
msg = f"🚨 <b>{subject}</b>\n\n{error_list}"
self._send_telegram(msg)
def _send_email(self, subject, body):
try:
msg = EmailMessage()
msg.set_content(body)
msg['Subject'] = f"🚨 {subject}"
msg['From'] = f"FSS Alert <{self.email_conf['user']}>"
msg['To'] = self.email_conf['to_email']
with smtplib.SMTP(self.email_conf['smtp_server'], self.email_conf['smtp_port']) as server:
server.starttls()
server.login(self.email_conf['user'], self.email_password)
server.send_message(msg)
except Exception as e:
print(f"[Error] Email failed: {e}")
def _send_telegram(self, message):
chat_id = self.telegram_conf.get('chat_id')
url = f"https://api.telegram.org/bot{self.tg_token}/sendMessage"
payload = {
'chat_id': chat_id,
'text': message,
'parse_mode': 'HTML'
}
try:
data = urllib.parse.urlencode(payload).encode('utf-8')
req = urllib.request.Request(url, data=data)
with urllib.request.urlopen(req) as response:
return json.loads(response.read().decode())
except Exception as e:
print(f"[Error] Telegram failed: {e}")

Would you like me to provide a 5-line “test_telegram.py” script so you can verify the notification arrives before you integrate it into your backup workflow?