Chatbot notification - hemanth22/fastapi-webhook-receiver GitHub Wiki

Notification Test case:

import requests

# Replace with your bot token and chat ID
BOT_TOKEN = 'YOUR_BOT_TOKEN_HERE'
CHAT_ID = 'YOUR_CHAT_ID_HERE'

# Sample data dictionary
data = {
    "source": "Command Center",
    "message": "This incident has been reopened.",
    "incident": {
        "detector": "GitGuardian"
    }
}

# Extracting information from data dictionary
source = data.get("source", "Unknown source")
message = data.get("message", "No message")
incident = data.get("incident", {})
detector = incident.get("detector", "Unknown detector")

# Define the message format
formatted_message = f"""
System Alert: Incident Update

Message from {source}:
{message}

Type of Secret Leak:

Secret Type: Username/Password
Reported by: {detector}
"""

# Define the Telegram API URL
url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"

# Define the payload
payload = {
    'chat_id': CHAT_ID,
    'text': formatted_message,
    'parse_mode': 'Markdown'  # Optional: Use 'HTML' if you prefer HTML formatting
}

# Send the message
response = requests.post(url, data=payload)

# Check for successful response
if response.status_code == 200:
    print("Message sent successfully.")
else:
    print(f"Failed to send message. Status code: {response.status_code}")
    print(f"Response: {response.text}")