redlight/redlight_alert_bot.py
2023-08-17 23:36:14 +08:00

30 lines
1.0 KiB
Python

import requests
from logging_module import configure_logger
logger = configure_logger()
class RedlightAlertBot:
def __init__(self, homeserver, access_token):
self.homeserver = homeserver
self.access_token = access_token
self.headers = {
"Authorization": f"Bearer {self.access_token}",
"Content-Type": "application/json"
}
self.logger = configure_logger()
def send_alert_message(self, room_id, message):
endpoint = f"{self.homeserver}/_matrix/client/r0/rooms/{room_id}/send/m.room.message"
payload = {
"msgtype": "m.text",
"body": message
}
response = requests.post(endpoint, headers=self.headers, json=payload)
# Check if the request was successful
if response.status_code == 200:
logger.info("Alert message sent successfully!")
else:
logger.info(f"Failed to send alert message. Status code: {response.status_code}, Response: {response.text}")