|
|
@@ -698,7 +698,7 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
use_auto_thread = self.chatto_config.auto_thread.value and not thread_id and not is_dm
|
|
|
|
|
|
message_ids: List[str] = []
|
|
|
- last_resp: Optional[dict] = None
|
|
|
+ last_resp: Optional[Any] = None
|
|
|
last_error: Optional[str] = None
|
|
|
retryable = False
|
|
|
|
|
|
@@ -723,9 +723,7 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
retryable = True
|
|
|
break
|
|
|
|
|
|
- if last_error and not message_ids:
|
|
|
- return SendResult(success=False, error=last_error, retryable=retryable)
|
|
|
-
|
|
|
+ last_resp = msg_obj
|
|
|
self._mark_seen(msg_obj.id)
|
|
|
message_ids.append(msg_obj.id)
|
|
|
self._our_message_ids.add(msg_obj.id)
|
|
|
@@ -738,13 +736,31 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
if use_auto_thread and i == 0 and not thread_id:
|
|
|
thread_id = msg_obj.id
|
|
|
|
|
|
- first_id = message_ids[0] if message_ids else ""
|
|
|
+ # Nothing got through at all — report the failure instead of a phantom success.
|
|
|
+ if not message_ids:
|
|
|
+ return SendResult(
|
|
|
+ success=False,
|
|
|
+ error=last_error or "Chatto: message could not be sent",
|
|
|
+ retryable=retryable,
|
|
|
+ )
|
|
|
+
|
|
|
+ first_id = message_ids[0]
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
|
# Thread following (best-effort, Chatto-unique)
|
|
|
# ------------------------------------------------------------------ #
|
|
|
- if thread_id and message_ids:
|
|
|
+ if thread_id:
|
|
|
+ try:
|
|
|
await client.follow_thread(chat_id, thread_id)
|
|
|
+ except Exception:
|
|
|
+ logger.debug("Chatto: follow_thread failed for %s/%s", chat_id, thread_id, exc_info=True)
|
|
|
+
|
|
|
+ # A later chunk failed after earlier ones went out: partial delivery.
|
|
|
+ if last_error:
|
|
|
+ logger.warning(
|
|
|
+ "Chatto: sent %d/%d chunk(s) to %s before failing: %s",
|
|
|
+ len(message_ids), len(chunks), chat_id, last_error,
|
|
|
+ )
|
|
|
|
|
|
return SendResult(success=True, message_id=first_id, raw_response=last_resp)
|
|
|
|