Repository navigation
Conversation
…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
Greptile SummaryAdds rich content parsing to extract file/image attachments from Nextcloud Talk webhooks. The implementation correctly parses JSON-encoded
Critical issues found:
Confidence Score: 2/5
Last reviewed commit: 495f292 |
| 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; | ||
| } |
There was a problem hiding this 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
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.
Additional Comments (1)
Prompt To Fix With AIThis 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. |
There was a problem hiding this comment.
💡 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}`; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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"); |
There was a problem hiding this comment.
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 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
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.contentas plain text without parsing, so:{file}placeholders were never resolvedobject.nameon NC < 33) were silently droppedChanges
types.tsNextcloudTalkRichObjectParametertype (file metadata from rich content)NextcloudTalkRichContenttype (parsedobject.contentstructure)fileParameters?: NextcloudTalkRichObjectParameter[]toNextcloudTalkInboundMessagemonitor.tsparseRichContent()— safely parse JSON content, returns null on failureresolveRichMessageText()— replace{file},{mention-user1}etc. with display namesextractFileParameters()— filter to file-type parameters onlypayloadToInboundMessage()to use rich content parsing with graceful fallbackinbound.tsbuildFileDownloadUrl()— constructs WebDAV URL from baseUrl/apiUser (secure), falls back tolinkfieldbuildAttachmentBlock()— formats[User shared an image: filename]\nAttachment: urlfor the agentBodyandBodyForAgentnow include attachment annotationsBackward Compatibility
parametersresolves to plain message text)object.contentgracefully falls back to raw stringTesting
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 constructionmonitor.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.