Skip to content

mattermost: message tool media upload fails with 403 in DMs (channel_id not resolved) #29881

@teconomix

Description

@teconomix

Describe the bug

Using the message tool with a media attachment in a Mattermost DM fails with 403 Forbidden from the Mattermost API. The same call works correctly on Slack.

Steps to reproduce

  1. Configure a Mattermost agent with a bot token
  2. Call the message tool: action=send, target=<user_id>, media=/path/to/image.png
  3. Observe: Mattermost API 403 Forbidden: You do not have the appropriate permissions

Root cause

The Mattermost file upload endpoint (POST /api/v4/files) requires a valid channel_id. The current implementation passes the target user ID directly as channel_id, which Mattermost rejects.

In Slack, the DM channel ID happens to match the user-facing ID format, so it works. In Mattermost, a DM channel ID must be explicitly resolved first via:

POST /api/v4/channels/direct
body: [bot_user_id, target_user_id]
→ returns the real channel_id

Only then can the file upload proceed with the correct channel_id.

Expected behavior

The message tool with media should successfully send file attachments in Mattermost DMs, consistent with Slack behavior.

Workaround

Manually resolve the DM channel ID and upload via direct API calls:

# 1. Get bot user ID
GET /api/v4/users/me

# 2. Resolve DM channel ID
POST /api/v4/channels/direct  body: [bot_id, user_id]

# 3. Upload file with real channel_id
POST /api/v4/files  channel_id=<resolved_channel_id>

# 4. Post with file_ids
POST /api/v4/posts  channel_id=<resolved_channel_id>  file_ids=[<file_id>]

Suggested fix

In extensions/mattermost/src/mattermost/send.ts: before uploading a file in a DM context, resolve the DM channel ID via POST /api/v4/channels/direct (and ideally cache it to avoid repeated API calls per session).

Environment

  • OpenClaw v2026.2.24
  • Channel: mattermost
  • Mattermost Server: self-hosted
  • Affects: DM media attachments (channel messages untested)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions