Minor refactoring to use common const for telegram API url
All checks were successful
Validate / Hassfest (push) Successful in 4s
All checks were successful
Validate / Hassfest (push) Successful in 4s
This commit is contained in:
@@ -50,7 +50,8 @@ from .coordinator import AlbumData, ImmichAlbumWatcherCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Telegram photo limits
|
||||
# Telegram constants
|
||||
TELEGRAM_API_BASE_URL = "https://api.telegram.org/bot"
|
||||
TELEGRAM_MAX_PHOTO_SIZE = 10 * 1024 * 1024 # 10 MB - Telegram's max photo size
|
||||
TELEGRAM_MAX_DIMENSION_SUM = 10000 # Maximum sum of width + height in pixels
|
||||
|
||||
@@ -408,7 +409,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
"""Send a simple text message to Telegram."""
|
||||
import aiohttp
|
||||
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendMessage"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendMessage"
|
||||
|
||||
payload: dict[str, Any] = {
|
||||
"chat_id": chat_id,
|
||||
@@ -463,7 +464,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
"""
|
||||
import aiohttp
|
||||
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendChatAction"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendChatAction"
|
||||
payload = {"chat_id": chat_id, "action": action}
|
||||
|
||||
try:
|
||||
@@ -652,7 +653,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
if reply_to_message_id:
|
||||
payload["reply_to_message_id"] = reply_to_message_id
|
||||
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendPhoto"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendPhoto"
|
||||
try:
|
||||
async with session.post(telegram_url, json=payload) as response:
|
||||
result = await response.json()
|
||||
@@ -725,7 +726,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
form.add_field("reply_to_message_id", str(reply_to_message_id))
|
||||
|
||||
# Send to Telegram
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendPhoto"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendPhoto"
|
||||
|
||||
_LOGGER.debug("Uploading photo to Telegram")
|
||||
async with session.post(telegram_url, data=form) as response:
|
||||
@@ -803,7 +804,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
if reply_to_message_id:
|
||||
payload["reply_to_message_id"] = reply_to_message_id
|
||||
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendVideo"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendVideo"
|
||||
try:
|
||||
async with session.post(telegram_url, json=payload) as response:
|
||||
result = await response.json()
|
||||
@@ -857,7 +858,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
form.add_field("reply_to_message_id", str(reply_to_message_id))
|
||||
|
||||
# Send to Telegram
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendVideo"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendVideo"
|
||||
|
||||
_LOGGER.debug("Uploading video to Telegram")
|
||||
async with session.post(telegram_url, data=form) as response:
|
||||
@@ -935,7 +936,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
if reply_to_message_id:
|
||||
payload["reply_to_message_id"] = reply_to_message_id
|
||||
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendDocument"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendDocument"
|
||||
try:
|
||||
async with session.post(telegram_url, json=payload) as response:
|
||||
result = await response.json()
|
||||
@@ -964,7 +965,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
form.add_field("reply_to_message_id", str(reply_to_message_id))
|
||||
|
||||
# Send to Telegram
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendDocument"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendDocument"
|
||||
|
||||
_LOGGER.debug("Uploading document to Telegram (%d bytes, %s)", len(data), content_type)
|
||||
async with session.post(telegram_url, data=form) as response:
|
||||
@@ -1236,7 +1237,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
if chunk_idx == 0 and reply_to_message_id:
|
||||
payload["reply_to_message_id"] = reply_to_message_id
|
||||
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendMediaGroup"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendMediaGroup"
|
||||
try:
|
||||
async with session.post(telegram_url, json=payload) as response:
|
||||
result = await response.json()
|
||||
@@ -1295,7 +1296,7 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
form.add_field("media", json.dumps(media_json))
|
||||
|
||||
# Send to Telegram
|
||||
telegram_url = f"https://api.telegram.org/bot{token}/sendMediaGroup"
|
||||
telegram_url = f"{TELEGRAM_API_BASE_URL}{token}/sendMediaGroup"
|
||||
|
||||
try:
|
||||
_LOGGER.debug("Uploading media group chunk %d/%d (%d files, %d cached) to Telegram",
|
||||
|
||||
Reference in New Issue
Block a user