Skip to content

fix: deliver Slack TTS audio with text fallback - #10496

Merged
RC-CHN merged 3 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/slack-tts-delivery
Oct 11, 2026
Merged

RC-CHN merged 3 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/slack-tts-delivery

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes missing Slack replies when TTS is enabled and dual output is disabled.

Modifications / 改动点

  • Upload TTS audio to the destination channel/DM and skip empty messages.

  • Fall back to source text on upload failure, without duplicating dual-output text.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Verification steps: enable TTS (trigger probability 1), disable streaming and dual output, then request a short reply. Expect playable audio. If upload fails, expect one text reply with dual output either on or off.

  • Live Slack Webhook + MiMo audio delivery verified.
  • 77 Slack tests passed, including upload failure and dual-output deduplication.
  • ruff format ., ruff check ., and git diff --check passed.

Before

Before

After

After

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

  • 📚 I checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zh 和 docs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Ensure Slack TTS responses reliably deliver playable audio with concise text fallbacks when delivery fails.

New Features:

  • Deliver Slack TTS audio directly to channels and direct messages, including support for mixed text and audio responses.

Bug Fixes:

  • Fall back to source text when Slack audio uploads or message delivery fail, while avoiding empty replies and duplicate dual-output text.
  • Preserve message ordering and prevent already delivered content from being resent during retries.

Tests:

  • Add Slack TTS coverage for successful uploads, upload failures, message retries, dual-output deduplication, and mixed-content ordering.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review October 10, 2026 21:15

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/slack/slack_adapter.py" line_range="92" />
<code_context>
         blocks, text = await SlackMessageEvent._parse_slack_blocks(
             message_chain=message_chain,
             web_client=self.web_client,
+            channel_id=channel_id,
         )
+        if not blocks and not text.strip():
</code_context>
<issue_to_address>
**Replies disappear after rejection**

When slack rejects `chat_postMessage` after `_parse_slack_blocks` returns a block-based audio reply, `SlackAdapter.send_by_session` catches and logs the exception without retrying the source text, so the caller receives no reply.

Retry the source text when posting the block-based reply fails.
</issue_to_address>

### Comment 2
<location path="astrbot/core/platform/sources/slack/slack_event.py" line_range="145-154" />
<code_context>
                 text_content += segment.text
             elif isinstance(segment, At):
                 text_content += f"<@{segment.qq}>"
+            elif isinstance(segment, Record):
+                try:
+                    if not channel_id:
+                        raise ValueError("Slack audio upload requires a destination.")
+                    path = Path(await segment.convert_to_file_path())
+                    # File uploads require a conversation ID, not a user ID.
+                    if channel_id.startswith(("U", "W")):
+                        response = await web_client.conversations_open(users=channel_id)
+                        channel_id = response["channel"]["id"]
+                    response = await web_client.files_upload_v2(
+                        file=await asyncio.to_thread(path.read_bytes),
+                        filename=path.name,
</code_context>
<issue_to_address>
**Audio arrives before preceding text**

When a message chain contains `Plain` text before a `Record` and the audio upload succeeds, `_parse_slack_blocks` uploads the `Record` before posting the accumulated text, so Slack shows the audio before the text that precedes it in the chain.

Post accumulated text before uploading the `Record`.
</issue_to_address>

### Comment 3
<location path="tests/test_slack_tts.py" line_range="107-108" />
<code_context>
+    )
+
+    client.files_upload_v2.assert_awaited_once()
+    assert client.chat_postMessage.await_count == 2
+    assert client.chat_postMessage.await_args.kwargs == {
+        "channel": "C123",
+        "text": "Speech test.",
</code_context>
<issue_to_address>
**Block retry test skips first request**

When the Slack sender incorrectly sends text-only on its first request, `test_slack_tts_block_failure_retries_source_text` checks only the call count and final request, so an implementation that sends text-only on the first call and retries text-only after the mock error still passes without ever attempting block delivery.

Assert that the first `chat_postMessage` call includes blocks and that the retry is text-only.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the change uploads Record audio to Slack and may open a direct-message conversation before sending it, so a wrong destination or fallback decision could disclose audio or send an unintended message that cannot be recalled by reverting. The impact is bounded to the affected messages, but the external upload already occurred.

Blocking findings: astrbot/core/platform/sources/slack/slack_adapter.py:92, astrbot/core/platform/sources/slack/slack_event.py:154, tests/test_slack_tts.py:108


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/platform/sources/slack/slack_adapter.py
Comment thread astrbot/core/platform/sources/slack/slack_event.py
Comment thread tests/test_slack_tts.py
@wcqqq1214

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. The change adds Slack file uploads and can leave audio files and notifications in the destination conversation even after a revert. Mistakes appear bounded and can generally be repaired by deleting the uploaded file or correcting delivery, but they are not fully undone by reverting the code.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@RC-CHN
RC-CHN merged commit 1d47485 into AstrBotDevs:master Oct 11, 2026
23 checks passed
@wcqqq1214
wcqqq1214 deleted the fix/slack-tts-delivery branch October 11, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants