Skip to content

Your lightweight open-source personal agent.

merge main into pr-673 and keep slack empty-text fallback without regressing thread/media support

Re-bin2e50a98a5748
diff --cc nanobot/channels/slack.py
index fb86b3a59,afd1d2dcd..a4e732494
--- a/nanobot/channels/slack.py
+++ b/nanobot/channels/slack.py
@@@ -81,14 -82,27 +82,28 @@@ class SlackChannel(BaseChannel)
thread_ts = slack_meta.get("thread_ts")
channel_type = slack_meta.get("channel_type")
# Only reply in thread for channel/group messages; DMs don't use threads
-- use_thread = thread_ts and channel_type != "im"
- await self._web_client.chat_postMessage(
- channel=msg.chat_id,
- text=msg.content or "<empty_response_from_the_bot>",
- thread_ts=thread_ts if use_thread else None,
- )
+ thread_ts_param = thread_ts if use_thread else None
+
- if msg.content:
++ # Slack rejects empty text payloads. Keep media-only messages media-only,
++ # but send a single blank message when the bot has no text or files to send.
++ if msg.content or not (msg.media or []):
+ await self._web_client.chat_postMessage(
+ channel=msg.chat_id,
- text=self._to_mrkdwn(msg.content),
++ text=self._to_mrkdwn(msg.content) if msg.content else " ",
+ thread_ts=thread_ts_param,
+ )
+
+ for media_path in msg.media or []:
+ try:
+ await self._web_client.files_upload_v2(
+ channel=msg.chat_id,
+ file=media_path,
+ thread_ts=thread_ts_param,
+ )
+ except Exception as e:
+ logger.error("Failed to upload file {}: {}", media_path, e)
except Exception as e:
- logger.error(f"Error sending Slack message: {e}")
+ logger.error("Error sending Slack message: {}", e)
async def _on_socket_request(
self,