Store MAX publication URLs
This commit is contained in:
@@ -161,6 +161,9 @@ class MAXAPIClient:
|
||||
payload["attachments"] = attachments
|
||||
return await self.request("POST", f"/messages?chat_id={chat_id}", json=payload)
|
||||
|
||||
async def get_message(self, message_id: str) -> dict[str, Any]:
|
||||
return await self.request("GET", f"/messages/{quote(message_id, safe='')}")
|
||||
|
||||
async def get_video_info(self, token: str) -> dict[str, Any]:
|
||||
return await self.request("GET", f"/videos/{quote(token, safe='')}")
|
||||
|
||||
@@ -486,6 +489,13 @@ class MAXPoster:
|
||||
candidates.extend([body.get("id"), body.get("mid"), body.get("message_id")])
|
||||
return next((str(value) for value in candidates if value), "")
|
||||
|
||||
def message_url_from_response(self, data: dict[str, Any]) -> str | None:
|
||||
candidates = [data.get("url")]
|
||||
message = data.get("message") if isinstance(data.get("message"), dict) else {}
|
||||
body = message.get("body") if isinstance(message.get("body"), dict) else {}
|
||||
candidates.extend([message.get("url"), body.get("url")])
|
||||
return next((str(value).strip() for value in candidates if str(value or "").strip()), None)
|
||||
|
||||
async def send_message_waiting_for_media(
|
||||
self,
|
||||
client: MAXAPIClient,
|
||||
@@ -579,10 +589,15 @@ class MAXPoster:
|
||||
first_text = chunks[0] if chunks else ""
|
||||
first = await self.send_message_waiting_for_media(client, first_text, attachments)
|
||||
message = first.get("message") if isinstance(first.get("message"), dict) else first
|
||||
first_url = message.get("url") if isinstance(message, dict) else None
|
||||
first_url = self.message_url_from_response(message) if isinstance(message, dict) else None
|
||||
first_message_id = self.message_id_from_response(first)
|
||||
if first_message_id:
|
||||
message_ids.append(first_message_id)
|
||||
if not first_url:
|
||||
try:
|
||||
first_url = self.message_url_from_response(await client.get_message(first_message_id))
|
||||
except Exception as exc:
|
||||
logger.warning("MAX message URL lookup failed message={}: {}", first_message_id, exc)
|
||||
if self.auto_reaction_enabled and self.reaction_path_template:
|
||||
try:
|
||||
await client.react(self.reaction_path_template, first_message_id, self.auto_reaction)
|
||||
|
||||
Reference in New Issue
Block a user