Skip to content

fix(tools): implement Mattermost direct send via REST API#3689

Open
miki-10xlab wants to merge 1 commit intoNousResearch:mainfrom
miki-10xlab:fix/mattermost-direct-send
Open

fix(tools): implement Mattermost direct send via REST API#3689
miki-10xlab wants to merge 1 commit intoNousResearch:mainfrom
miki-10xlab:fix/mattermost-direct-send

Conversation

@miki-10xlab
Copy link
Copy Markdown

What does this PR do?

Platform.MATTERMOST was fully registered and its config was parsed correctly, but _send_to_platform() had no handler for it — falling through to the else branch and returning "Direct sending not yet implemented for mattermost".

This made every cron job or agent delivery targeting Mattermost silently fail. The root cause was that the only existing send path for Mattermost goes through MattermostAdapter, which requires connect() to be called before use (setting up self._session). The direct-send path (used outside the gateway, e.g. cron jobs) never called connect(), leaving self._session = None and raising AttributeError: 'NoneType' object has no attribute 'post'.

Fix: add _send_mattermost() using a direct aiohttp POST to /api/v4/posts, matching the same pattern already used by _send_discord and _send_slack. No new dependencies — aiohttp is already required by those handlers. Also wires thread_id → Mattermost's root_id for threaded replies.

Note: #3512 fixed platform registration (toolset config parsing). This PR fixes the complementary send-path bug — the platform was correctly registered but delivery was never implemented for the direct-send path used by cron jobs.

Related Issue

Fixes — (no existing issue; discovered in production via cron job delivery failure)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Tests (adding or improving test coverage)

Changes Made

  • tools/send_message_tool.py — add _send_mattermost(pconfig, chat_id, message, thread_id=None) implementing direct REST delivery via aiohttp
  • tools/send_message_tool.py — wire Platform.MATTERMOST in the _send_to_platform() dispatch loop (was hitting else branch)
  • tests/tools/test_send_message_tool.py — add TestSendMattermost class with 4 tests: routing, success (HTTP 201), thread_idroot_id mapping, API error (HTTP 403)

How to Test

  1. Configure Mattermost in ~/.hermes/config.yaml:
    platforms:
      mattermost:
        token: xoxb-your-bot-token
        extra:
          url: https://your-mattermost-instance.com
  2. Schedule a cron job with deliver: mattermost and a channel ID as target, or call send_message with platform: mattermost
  3. Before this fix: delivery returns {"error": "Direct sending not yet implemented for mattermost"}
  4. After this fix: message appears in the Mattermost channel

Unit tests: pytest tests/tools/test_send_message_tool.py::TestSendMattermost -v — 4 passed

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(send_message): implement Mattermost direct send via REST API)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix (2 files: the tool and its test)
  • I've run pytest tests/ -q and all tests pass (10 pre-existing failures on main unrelated to this PR, verified on clean HEAD before branching)
  • I've added tests for my changes
  • I've tested on my platform: macOS 15 (Apple M1)

Documentation & Housekeeping

  • I've updated relevant documentation — N/A (no config keys added; Mattermost was already documented)
  • I've updated cli-config.yaml.example — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A
  • I've considered cross-platform impact — N/A (pure Python/aiohttp, no OS calls)
  • I've updated tool descriptions/schemas — N/A (no schema change, behavior fix only)

Screenshots / Logs

Before (cron job delivery to Mattermost):

{"error": "Direct sending not yet implemented for mattermost"}

After:

{"success": true, "platform": "mattermost", "chat_id": "...", "message_id": "..."}

Platform.MATTERMOST was registered but _send_to_platform() fell through
to the else branch returning 'Direct sending not yet implemented for
mattermost', silently breaking all cron job and agent deliveries.

Fix: add _send_mattermost() using a direct aiohttp POST to /api/v4/posts,
matching the same pattern as _send_discord and _send_slack. No new deps.
Also wires thread_id -> root_id for threaded replies.

Fixes NousResearch#3511
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.

1 participant