Skip to content

feat(platform): add Mattermost bot support#7369

Merged
Soulter merged 7 commits intoAstrBotDevs:masterfrom
KagurazakaNyaa:feat/mattermost-bot-support-6009
Apr 6, 2026
Merged

feat(platform): add Mattermost bot support#7369
Soulter merged 7 commits intoAstrBotDevs:masterfrom
KagurazakaNyaa:feat/mattermost-bot-support-6009

Conversation

@KagurazakaNyaa
Copy link
Copy Markdown
Contributor

@KagurazakaNyaa KagurazakaNyaa commented Apr 5, 2026

Resolve #6009

Modifications / 改动点

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

  • Added a native Mattermost platform adapter using the official REST and WebSocket APIs.

  • Supported incoming posts, mention-based wakeup, session replies, and attachment upload/download.

  • Registered Mattermost in platform loading, default config metadata, and the README platform list.

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

  • uv run ruff format .
408 files left unchanged
  • uv run ruff check .
All checks passed!
  • basedpyright diagnostics on astrbot/core/platform/sources/mattermost
0 errors, 0 warnings, 0 notes
  • uv run pytest tests/test_mattermost_adapter.py -q (covers Mattermost mention parsing / attachment smoke tests)
..                                                                       [100%]
=============================== warnings summary ===============================
<frozen importlib._bootstrap>:488
  <frozen importlib._bootstrap>:488: DeprecationWarning: builtin type SwigPyPacked has no __module__ attribute

<frozen importlib._bootstrap>:488
  <frozen importlib._bootstrap>:488: DeprecationWarning: builtin type SwigPyObject has no __module__ attribute

<frozen importlib._bootstrap>:488
  <frozen importlib._bootstrap>:488: DeprecationWarning: builtin type swigvarlink has no __module__ attribute

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
2 passed, 3 warnings in 2.25s

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 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.txtpyproject.toml 文件相应位置。

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

Summary by Sourcery

Add a native Mattermost platform adapter using Mattermost REST and WebSocket APIs and wire it into the platform system and documentation.

New Features:

  • Introduce a Mattermost platform adapter that handles incoming posts, replies, mentions, and WebSocket-based events.
  • Support sending and receiving Mattermost attachments including files, images, audio, and video via a dedicated client.
  • Allow configuring Mattermost connection details (URL, bot token, reconnect delay) via the default chat provider configuration template.

Enhancements:

  • Integrate Mattermost into the platform manager so it can be dynamically loaded like other chat platforms.

Documentation:

  • List Mattermost as an officially supported platform in the README platform table.

Copilot AI review requested due to automatic review settings April 5, 2026 05:28
@auto-assign auto-assign bot requested review from LIghtJUNction and Soulter April 5, 2026 05:28
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Apr 5, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In MattermostMessageEvent.send_streaming, the generator is fully consumed to build and send buffered output, then passed to super().send_streaming(...) even though it is already exhausted; consider either not forwarding to super() or restructuring so the base implementation processes the original stream.
  • The adapter attaches temporary_file_paths to AstrBotMessage via setattr; if this pattern is expected long-term, it may be more robust to add an explicit field or helper on the message/event type rather than relying on a dynamic attribute.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `MattermostMessageEvent.send_streaming`, the `generator` is fully consumed to build and send buffered output, then passed to `super().send_streaming(...)` even though it is already exhausted; consider either not forwarding to `super()` or restructuring so the base implementation processes the original stream.
- The adapter attaches `temporary_file_paths` to `AstrBotMessage` via `setattr`; if this pattern is expected long-term, it may be more robust to add an explicit field or helper on the message/event type rather than relying on a dynamic attribute.

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/mattermost/mattermost_event.py" line_range="30-39" />
<code_context>
+        await self.client.send_message_chain(self.get_session_id(), message)
+        await super().send(message)
+
+    async def send_streaming(
+        self,
+        generator: AsyncGenerator,
+        use_fallback: bool = False,
+    ):
+        if not use_fallback:
+            buffer = None
+            async for chain in generator:
+                if not buffer:
+                    buffer = chain
+                else:
+                    buffer.chain.extend(chain.chain)
+            if not buffer:
+                return None
+            buffer.squash_plain()
+            await self.send(buffer)
+            return await super().send_streaming(generator, use_fallback)
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The non-fallback streaming branch buffers all chunks and then calls `super().send_streaming` on an exhausted generator, which adds complexity without effect.

In the `not use_fallback` branch you fully consume `generator` into a single buffered `MessageChain`, send that once, and then call `super().send_streaming(generator, use_fallback)` on an already-exhausted async generator. That call won’t stream anything and only obscures the control flow. Consider either (1) buffering and sending once, then returning, or (2) delegating directly to `super().send_streaming` without buffering, depending on the behavior you want.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Apr 5, 2026
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a Mattermost platform adapter, enabling AstrBot to integrate with Mattermost via its API and WebSocket. The implementation includes a new client for handling authentication, file operations, and message delivery, as well as an adapter for processing events and converting messages. Review feedback focuses on performance enhancements, such as offloading blocking file I/O to separate threads using asyncio.to_thread, pre-compiling regex for bot mentions, and optimizing the duplicate message detection logic. Additionally, adding return type hints was suggested to improve code quality.

@KagurazakaNyaa KagurazakaNyaa force-pushed the feat/mattermost-bot-support-6009 branch from 7101ab0 to 0349ada Compare April 5, 2026 05:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a native Mattermost platform adapter (REST + WebSocket) so AstrBot can receive posts, wake on mentions, reply in-session, and upload/download attachments.

Changes:

  • Introduces a Mattermost adapter, event wrapper, and API client to handle inbound/outbound messaging and attachments.
  • Registers the new platform in the platform manager and default config template/metadata.
  • Updates README platform list to include Mattermost.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Adds Mattermost to the supported platforms list.
astrbot/core/platform/sources/mattermost/mattermost_event.py Adds Mattermost-specific AstrMessageEvent for sending + fallback streaming behavior + group lookup.
astrbot/core/platform/sources/mattermost/mattermost_adapter.py Implements the Mattermost Platform adapter (WS listen loop, message conversion, mention parsing, de-dup).
astrbot/core/platform/sources/mattermost/client.py Implements REST/WS client helpers and attachment upload/download + chain sending.
astrbot/core/platform/sources/mattermost/init.py Adds the package module for the new platform source.
astrbot/core/platform/manager.py Registers Mattermost in the platform loader switch.
astrbot/core/config/default.py Adds default Mattermost platform template and config metadata entries.

KagurazakaNyaa and others added 4 commits April 5, 2026 13:39
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 6, 2026
@Soulter Soulter changed the title feat(platform): add Mattermost bot support (#6009) feat(platform): add Mattermost bot support Apr 6, 2026
Copy link
Copy Markdown
Member

@Soulter Soulter left a comment

Choose a reason for hiding this comment

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

good!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 6, 2026
@Soulter Soulter merged commit 0ce5fde into AstrBotDevs:master Apr 6, 2026
6 of 7 checks passed
@KagurazakaNyaa KagurazakaNyaa deleted the feat/mattermost-bot-support-6009 branch April 6, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]希望可以加入对Mattermost消息平台的支持

3 participants