redlight/redlight_alert_bot.py

30 lines
1.0 KiB
Python
Raw Normal View History

2023-08-17 11:12:07 -04:00
import requests
from logging_module import configure_logger
2023-08-17 11:12:07 -04:00
logger = configure_logger()
2023-08-14 10:39:44 -04:00
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"
}
2023-08-17 11:36:14 -04:00
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:
2023-08-14 10:39:44 -04:00
logger.info(f"Failed to send alert message. Status code: {response.status_code}, Response: {response.text}")