Skip to content

fix(nextcloud-talk): parse rich object file shares from webhook payload - #49866

Closed
VivoKrei wants to merge 1 commit into
openclaw:mainfrom
VivoKrei:fix/nextcloud-talk-attachment-parsing
Closed

VivoKrei wants to merge 1 commit into
openclaw:mainfrom
VivoKrei:fix/nextcloud-talk-attachment-parsing

Conversation

@VivoKrei

Copy link
Copy Markdown

Summary

Fixes #29152

When a user shares a file or image in Nextcloud Talk, the bot webhook receives the message but the NC Talk plugin was not parsing the rich object parameters — so the agent never saw the attachment.

NC Talk encodes file shares as rich object messages where object.content is a JSON string:

{"message":"{file}","parameters":{"file":{"type":"file","id":"12345","name":"IMG_123.jpg","path":"Talk/IMG_123.jpg","link":"https://cloud.example.com/f/12345","mimetype":"image/jpeg","preview-available":"yes"}}}

Previously payloadToInboundMessage() passed this raw JSON string as text, leaving mediaUrls unpopulated.

Changes

monitor.ts

  • Adds parseRichObjectContent() helper that detects JSON-encoded rich object payloads
  • Extracts file links into mediaUrls (https/http only — rejects file://, javascript:, etc.)
  • Resolves {placeholder} names for human-readable displayText (covers file shares, mentions, deck cards, polls, etc.)
  • Uses replaceAll for placeholder substitution to handle duplicate occurrences
  • Falls back to raw content for non-rich-object text — no behaviour change for regular messages

types.ts

  • Adds mediaUrls?: string[] to NextcloudTalkInboundMessage

inbound.ts

  • Passes MediaUrls into finalizeInboundContext so the agent receives them (verified: finalizeInboundContext already consumes MediaUrls: string[] natively)
  • Relaxes the empty-body guard to allow media-only messages through (previously silently dropped)

Tests

  • monitor.attachment.test.ts — 7 unit tests: file share, text passthrough, malformed JSON fallback, name fallback, mention resolution, file:// URL rejection, multi-file
  • monitor.live-integration.test.ts — 5 integration tests using real HMAC-signed payloads against the webhook server

All 12 tests pass. TypeScript compiles clean (tsc --noEmit).

Before / After

Before: Sharing a file in NC Talk → agent receives raw JSON string, never sees the attachment.

After: Sharing a file → agent receives text = "filename.jpg" and `mediaUrls = ["https://..."]" — can immediately process the image via vision without any manual workaround.

@openclaw-barnacle openclaw-barnacle Bot added channel: nextcloud-talk Channel integration: nextcloud-talk size: M labels Mar 18, 2026
When a user shares a file or image in Nextcloud Talk, the webhook
delivers object.content as a JSON-encoded rich object message like:
  {"message":"{file}","parameters":{"file":{"type":"file","name":"IMG.jpg","link":"https://..."}}}

Previously payloadToInboundMessage() passed this raw JSON string as
text, leaving mediaUrls unpopulated and the agent blind to attachments.

This change adds parseRichObjectContent() which:
- Detects JSON-encoded rich object payloads
- Extracts file links into mediaUrls
- Resolves {placeholder} names for human-readable displayText
- Falls back to raw content for non-rich-object text (no behaviour change)

Also updates NextcloudTalkInboundMessage type to include mediaUrls?,
passes mediaUrls through inbound.ts to the agent context payload, and
relaxes the empty-body guard to allow media-only messages through.

Fixes #29152
@greptile-apps

greptile-apps Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes NC Talk file share parsing by adding a parseRichObjectContent() helper in monitor.ts that detects JSON-encoded rich object payloads, extracts HTTPS file links into mediaUrls, and resolves {placeholder} names to human-readable displayText. The type definition, empty-body guard, and finalizeInboundContext call in inbound.ts are all updated consistently.

Key findings:

  • Mention gate vs. media-only messages (inbound.ts, lines 207–228): For group rooms configured with requireMention: true, file shares will still be silently dropped. wasMentioned is evaluated against rawBody (the resolved filename, e.g. "IMG_123.jpg"), which will not match mention patterns. The relaxed empty-body guard on line 70–71 allows the message past the first checkpoint, but the mention gate further down cancels it. This is the primary functional gap versus the PR's stated goal.
  • Personal Tailscale hostname in tests (monitor.live-integration.test.ts): vivokrei-ubuntu.tailfc1e89.ts.net is hardcoded throughout the live integration tests. While no real network call is made to this host, it ties the repository to personal developer infrastructure and should be replaced with a generic domain like cloud.example.com.

Confidence Score: 3/5

  • Safe to merge for DM and non-mention-gated group rooms, but file shares in requireMention: true group rooms will still be silently dropped contrary to the PR's stated goal.
  • The parsing logic and URL sanitisation are correct and well-tested. However, the interaction between the new hasMedia guard and the existing requireMention mention gate creates a functional gap for the primary use case in gated rooms. The personal Tailscale hostname in tests is a minor quality issue. No security issues were found.
  • extensions/nextcloud-talk/src/inbound.ts — the mention gate (lines 207–228) needs attention to decide whether media-only file shares in requireMention rooms should be treated differently.

Comments Outside Diff (1)

  1. extensions/nextcloud-talk/src/inbound.ts, line 207-228 (link)

    P2 Mention gate will silently drop media-only file shares in group rooms

    The wasMentioned check runs against rawBody, which for a file share is the resolved filename (e.g. "IMG_123.jpg") — not the original message content:

    const rawBody = message.text?.trim() ?? "";   // e.g. "IMG_123.jpg"
    const wasMentioned = mentionRegexes.length
      ? core.channel.mentions.matchesMentionPatterns(rawBody, mentionRegexes)
      : false;

    Later, for any group room configured with requireMention: true, the mentionGate will fire and the message will be dropped with "drop room X (no mention)" — even though the new guard on line 69-71 now lets it through the earlier empty-body check.

    The PR's stated goal ("After: agent receives text = 'filename.jpg' and mediaUrls = [...]") will therefore not be realised for rooms that have requireMention: true. Users sharing files in those rooms will see the bot silently ignore them.

    Consider whether file shares in requireMention rooms should bypass or relax the mention gate (e.g. when hasMedia && !rawBody), or at least document this limitation in a comment near the guard.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: extensions/nextcloud-talk/src/inbound.ts
    Line: 207-228
    
    Comment:
    **Mention gate will silently drop media-only file shares in group rooms**
    
    The `wasMentioned` check runs against `rawBody`, which for a file share is the resolved filename (e.g. `"IMG_123.jpg"`) — not the original message content:
    
    ```ts
    const rawBody = message.text?.trim() ?? "";   // e.g. "IMG_123.jpg"
    const wasMentioned = mentionRegexes.length
      ? core.channel.mentions.matchesMentionPatterns(rawBody, mentionRegexes)
      : false;
    ```
    
    Later, for any group room configured with `requireMention: true`, the `mentionGate` will fire and the message will be dropped with `"drop room X (no mention)"` — even though the new guard on line 69-71 now lets it through the earlier empty-body check.
    
    The PR's stated goal ("After: agent receives `text = 'filename.jpg'` and `mediaUrls = [...]`") will therefore **not** be realised for rooms that have `requireMention: true`. Users sharing files in those rooms will see the bot silently ignore them.
    
    Consider whether file shares in `requireMention` rooms should bypass or relax the mention gate (e.g. when `hasMedia && !rawBody`), or at least document this limitation in a comment near the guard.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/monitor.live-integration.test.ts
Line: 37

Comment:
**Personal Tailscale hostname in committed tests**

The integration tests hardcode `vivokrei-ubuntu.tailfc1e89.ts.net`, which is a personal developer Tailscale device hostname. Even though these tests only assert against the *parsed* URL string (no real HTTP call is made to that host), shipping a personal infrastructure address in the repository is not ideal — it will show up in grep/search results, may confuse future contributors, and the hostname could eventually become stale or be repurposed.

Consider replacing with a generic example domain like `cloud.example.com`:

```suggestion
    "x-nextcloud-talk-backend": "https://cloud.example.com",
```

The same applies to every occurrence of `vivokrei-ubuntu.tailfc1e89.ts.net` across this file (lines 45, 96, 116, 132, 144).

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/inbound.ts
Line: 207-228

Comment:
**Mention gate will silently drop media-only file shares in group rooms**

The `wasMentioned` check runs against `rawBody`, which for a file share is the resolved filename (e.g. `"IMG_123.jpg"`) — not the original message content:

```ts
const rawBody = message.text?.trim() ?? "";   // e.g. "IMG_123.jpg"
const wasMentioned = mentionRegexes.length
  ? core.channel.mentions.matchesMentionPatterns(rawBody, mentionRegexes)
  : false;
```

Later, for any group room configured with `requireMention: true`, the `mentionGate` will fire and the message will be dropped with `"drop room X (no mention)"` — even though the new guard on line 69-71 now lets it through the earlier empty-body check.

The PR's stated goal ("After: agent receives `text = 'filename.jpg'` and `mediaUrls = [...]`") will therefore **not** be realised for rooms that have `requireMention: true`. Users sharing files in those rooms will see the bot silently ignore them.

Consider whether file shares in `requireMention` rooms should bypass or relax the mention gate (e.g. when `hasMedia && !rawBody`), or at least document this limitation in a comment near the guard.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "fix(nextcloud-talk):..."

"x-nextcloud-talk-backend": "https://nextcloud.example",
},
};
}

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.

P2 Personal Tailscale hostname in committed tests

The integration tests hardcode vivokrei-ubuntu.tailfc1e89.ts.net, which is a personal developer Tailscale device hostname. Even though these tests only assert against the parsed URL string (no real HTTP call is made to that host), shipping a personal infrastructure address in the repository is not ideal — it will show up in grep/search results, may confuse future contributors, and the hostname could eventually become stale or be repurposed.

Consider replacing with a generic example domain like cloud.example.com:

Suggested change
}
"x-nextcloud-talk-backend": "https://cloud.example.com",

The same applies to every occurrence of vivokrei-ubuntu.tailfc1e89.ts.net across this file (lines 45, 96, 116, 132, 144).

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/monitor.live-integration.test.ts
Line: 37

Comment:
**Personal Tailscale hostname in committed tests**

The integration tests hardcode `vivokrei-ubuntu.tailfc1e89.ts.net`, which is a personal developer Tailscale device hostname. Even though these tests only assert against the *parsed* URL string (no real HTTP call is made to that host), shipping a personal infrastructure address in the repository is not ideal — it will show up in grep/search results, may confuse future contributors, and the hostname could eventually become stale or be repurposed.

Consider replacing with a generic example domain like `cloud.example.com`:

```suggestion
    "x-nextcloud-talk-backend": "https://cloud.example.com",
```

The same applies to every occurrence of `vivokrei-ubuntu.tailfc1e89.ts.net` across this file (lines 45, 96, 116, 132, 144).

How can I resolve this? If you propose a fix, please make it concise.

@VivoKrei

Copy link
Copy Markdown
Author

Closing to re-submit from a clean fork (housekeeping).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: nextcloud-talk Channel integration: nextcloud-talk size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nextcloud Talk: file/image attachments not parsed from webhook payload

1 participant