"텔레그램_연동_기능_구현_및_설정_스키마_수정"
This commit is contained in:
BIN
backend/app/services/__pycache__/sync_service.cpython-312.pyc
Normal file
BIN
backend/app/services/__pycache__/sync_service.cpython-312.pyc
Normal file
Binary file not shown.
33
backend/app/services/telegram_service.py
Normal file
33
backend/app/services/telegram_service.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import httpx
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class TelegramService:
|
||||
def __init__(self):
|
||||
self.base_url = "https://api.telegram.org/bot"
|
||||
|
||||
async def send_message(self, token: str, chat_id: str, text: str) -> bool:
|
||||
if not token or not chat_id:
|
||||
logger.warning("Telegram: Token or Chat ID is missing.")
|
||||
return False
|
||||
|
||||
url = f"{self.base_url}{token}/sendMessage"
|
||||
payload = {
|
||||
"chat_id": chat_id,
|
||||
"text": text,
|
||||
"parse_mode": "HTML"
|
||||
}
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
resp = await client.post(url, json=payload, timeout=10.0)
|
||||
resp.raise_for_status()
|
||||
logger.info(f"Telegram: Message sent successfully to {chat_id}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Telegram: Failed to send message: {e}")
|
||||
return False
|
||||
|
||||
telegram_service = TelegramService()
|
||||
Reference in New Issue
Block a user