Skip to content

fix(nextcloud-talk): parse rich object parameters for file/image attachments - #29256

Closed
VivoKrei wants to merge 2 commits into
openclaw:mainfrom
VivoKrei:fix/nc-talk-file-attachments
Closed

VivoKrei wants to merge 2 commits into
openclaw:mainfrom
VivoKrei:fix/nc-talk-file-attachments

Conversation

@VivoKrei

Copy link
Copy Markdown

Summary

When a user shares a file or image in Nextcloud Talk, the bot webhook receives the message but the plugin does not parse the rich object parameters from object.content, so the agent never sees the attachment.

Closes #29152

Problem

NC Talk encodes file shares as rich content JSON in object.content:

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

The plugin extracted object.content as plain text without parsing, so:

  1. JSON-encoded content was never parsed
  2. {file} placeholders were never resolved
  3. No download URL was constructed
  4. File-only messages (empty object.name on NC < 33) were silently dropped

Changes

types.ts

  • Added NextcloudTalkRichObjectParameter type (file metadata from rich content)
  • Added NextcloudTalkRichContent type (parsed object.content structure)
  • Added fileParameters?: NextcloudTalkRichObjectParameter[] to NextcloudTalkInboundMessage

monitor.ts

  • parseRichContent() — safely parse JSON content, returns null on failure
  • resolveRichMessageText() — replace {file}, {mention-user1} etc. with display names
  • extractFileParameters() — filter to file-type parameters only
  • Updated payloadToInboundMessage() to use rich content parsing with graceful fallback

inbound.ts

  • buildFileDownloadUrl() — constructs WebDAV URL from baseUrl/apiUser (secure), falls back to link field
  • buildAttachmentBlock() — formats [User shared an image: filename]\nAttachment: url for the agent
  • No longer drops messages that have file attachments but empty text
  • Body and BodyForAgent now include attachment annotations

Backward Compatibility

  • Normal text messages work identically (JSON with empty parameters resolves to plain message text)
  • Malformed JSON in object.content gracefully falls back to raw string
  • No new dependencies

Testing

Two test files included:

  • rich-content.test.ts — 18 standalone tests (no SDK dependency) covering: normal text, single file, image, text+file combo, malformed JSON fallback, empty content, multiple files, empty params, non-file params (mentions), URL construction
  • monitor.rich-content.test.ts — integration tests importing from monitor.ts (for CI with SDK available)

Tested end-to-end on a live Nextcloud Talk 22.x instance with real file share payloads.

…chments

When a user shares a file or image in Nextcloud Talk, the webhook payload
encodes it as rich content JSON in object.content with {file} placeholders
and a parameters map. The plugin previously treated this as plain text,
so the agent never saw the attachment.

Changes:
- types.ts: Add NextcloudTalkRichContent and NextcloudTalkRichObjectParameter
  types; add fileParameters field to NextcloudTalkInboundMessage
- monitor.ts: Add parseRichContent() to safely parse the JSON content,
  resolveRichMessageText() to replace {file}/{mention-*} placeholders
  with display names, extractFileParameters() to filter file-type params
- inbound.ts: Add buildFileDownloadUrl() (prefers WebDAV URL from
  baseUrl/apiUser, falls back to link field), buildAttachmentBlock()
  for agent-readable annotations; no longer drops file-only messages

Backward compatible: normal text messages work identically. Graceful
fallback to raw content string if JSON parsing fails.

Closes #29152
@openclaw-barnacle openclaw-barnacle Bot added channel: nextcloud-talk Channel integration: nextcloud-talk size: L labels Feb 28, 2026
@greptile-apps

greptile-apps Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds rich content parsing to extract file/image attachments from Nextcloud Talk webhooks. The implementation correctly parses JSON-encoded object.content, resolves placeholder tokens like {file} to filenames, and constructs attachment annotations for the agent.

  • New helper functions (parseRichContent, resolveRichMessageText, extractFileParameters) handle rich content with graceful fallback to plain text
  • WebDAV URL construction prefers secure baseUrl/apiUser over untrusted link field
  • Comprehensive test coverage (18 standalone tests + integration tests)
  • No longer drops file-only messages (empty text but has attachment)

Critical issues found:

  • Type definition mismatch will cause TypeScript compilation errors (readBody, isBackendAllowed, shouldProcessMessage removed from type but still used in implementation)
  • File paths in WebDAV URLs aren't URL-encoded, breaking filenames with spaces/unicode characters

Confidence Score: 2/5

  • This PR has critical type definition bugs that will cause compilation errors
  • Two critical bugs found: (1) removed type fields still used in implementation causes TypeScript errors, (2) unencoded file paths break URLs with special characters. Both need fixing before merge.
  • extensions/nextcloud-talk/src/types.ts (type mismatch), extensions/nextcloud-talk/src/inbound.ts (URL encoding)

Last reviewed commit: 495f292

@greptile-apps greptile-apps 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.

5 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +42 to +51
function buildFileDownloadUrl(
file: NextcloudTalkRichObjectParameter,
baseUrl: string,
apiUser: string | undefined,
): string | undefined {
if (baseUrl && apiUser && file.path) {
return `${baseUrl}/remote.php/dav/files/${encodeURIComponent(apiUser)}/${file.path}`;
}
return file.link || undefined;
}

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.

file.path not URL-encoded — breaks with special characters (spaces, unicode) in filenames

split path by / and encodeURIComponent() each segment, or encode the whole path

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/inbound.ts
Line: 42-51

Comment:
`file.path` not URL-encoded — breaks with special characters (spaces, unicode) in filenames

split path by `/` and `encodeURIComponent()` each segment, or encode the whole path

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

@greptile-apps

greptile-apps Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

extensions/nextcloud-talk/src/types.ts
removed readBody, isBackendAllowed, and shouldProcessMessage from type, but monitor.ts:250-252 and monitor.ts:414-421 still reference/pass these fields — will cause TypeScript errors

export type NextcloudTalkWebhookServerOptions = {
  port: number;
  host: string;
  path: string;
  secret: string;
  maxBodyBytes?: number;
  readBody?: (req: import("node:http").IncomingMessage, maxBodyBytes: number) => Promise<string>;
  isBackendAllowed?: (backend: string) => boolean;
  shouldProcessMessage?: (message: NextcloudTalkInboundMessage) => boolean | Promise<boolean>;
  onMessage: (message: NextcloudTalkInboundMessage) => void | Promise<void>;
  onError?: (error: Error) => void;
  abortSignal?: AbortSignal;
};
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/types.ts
Line: 188-197

Comment:
removed `readBody`, `isBackendAllowed`, and `shouldProcessMessage` from type, but `monitor.ts:250-252` and `monitor.ts:414-421` still reference/pass these fields — will cause TypeScript errors

```suggestion
export type NextcloudTalkWebhookServerOptions = {
  port: number;
  host: string;
  path: string;
  secret: string;
  maxBodyBytes?: number;
  readBody?: (req: import("node:http").IncomingMessage, maxBodyBytes: number) => Promise<string>;
  isBackendAllowed?: (backend: string) => boolean;
  shouldProcessMessage?: (message: NextcloudTalkInboundMessage) => boolean | Promise<boolean>;
  onMessage: (message: NextcloudTalkInboundMessage) => void | Promise<void>;
  onError?: (error: Error) => void;
  abortSignal?: AbortSignal;
};
```

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 495f292d7f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

apiUser: string | undefined,
): string | undefined {
if (baseUrl && apiUser && file.path) {
return `${baseUrl}/remote.php/dav/files/${encodeURIComponent(apiUser)}/${file.path}`;

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.

P1 Badge Percent-encode file paths in WebDAV attachment URLs

buildFileDownloadUrl appends file.path verbatim when constructing the WebDAV link, so filenames containing spaces or reserved URL characters (for example #, ?, %, or non-ASCII) produce malformed Attachment: URLs in BodyForAgent. In those cases the link is truncated or interpreted incorrectly by downstream URL parsers, so the agent cannot reliably access shared files even though the webhook payload is valid.

Useful? React with 👍 / 👎.

Filenames with spaces, parens, or unicode (e.g. 'photo (3).png')
broke the constructed WebDAV URL. Now splits path on '/' and
encodes each segment individually.

Addresses review feedback from greptile and codex bots.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d1ee5ca08

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

parameters: Record<string, NextcloudTalkRichObjectParameter> | undefined,
): NextcloudTalkRichObjectParameter[] {
if (!parameters) return [];
return Object.values(parameters).filter((p) => p.type === "file");

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 Badge Guard file-parameter extraction against null entries

extractFileParameters assumes every parameters value is an object and reads p.type directly, so a payload like {"message":"...","parameters":{"file":null}} throws a TypeError during webhook handling. In that case the request falls into the generic error path and returns 500, dropping the inbound message instead of safely ignoring the bad parameter entry. Adding a shape check before accessing type would make rich-content parsing robust to malformed or partial parameter objects.

Useful? React with 👍 / 👎.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Mar 5, 2026
@VivoKrei VivoKrei closed this by deleting the head repository Mar 18, 2026
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: L stale Marked as stale due to inactivity

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