Skip to content

feat: Let the Assistant add internal notes - #297

Draft
funana777 wants to merge 1 commit into
feat/zammad-assistant-readfrom
feat/zammad-assistant-notes
Draft

funana777 wants to merge 1 commit into
feat/zammad-assistant-readfrom
feat/zammad-assistant-notes

Conversation

@funana777

@funana777 funana777 commented Nov 18, 2026 •

Copy link
Copy Markdown

Lets the Nextcloud Assistant, and any other client, add internal notes to Zammad tickets.

Base: #296 (feat/zammad-assistant-read). Merge #295 and #296 first. The Assistant's tool is nextcloud/context_agent#335.

Why

Support agents work in Zammad, so an analysis of a ticket is most useful as an internal note there, where colleagues see it.

What

  • POST /api/v1/ticket/notes with ticket (ID or link), text and ticket_number adds an internal note, written with the user's own token. Zammad shows the user as author and decides whether they may add notes. No replies to customers.
  • Notes are plain text and stored as given. The API adds no footer and does not check for earlier notes, so it stays usable for any client. Marking and recognizing the Assistant's own notes is done by the Context Agent tool.
  • Wrong-ticket check: if ticket_number does not belong to the ticket, the note is refused (400 ticket_mismatch). The response names the ticket's number and title. The title the client shows the user is not checked.
  • Errors use the helpers from feat: Add a ticket API for the Assistant #296: 404 when the ticket does not exist or the user may not add notes, 502 with Zammad's status code otherwise.
  • The capability's ticket_api goes to 2, so clients only offer notes where the route exists.
  • No admin setting: in the Assistant, the user confirms every note before it is written.

408 lines added, 3 removed; without openapi.json 134 added, of which 44 are tests.

How to test

  1. composer run test:unit
  2. As a connected user: curl -u user:pass -H 'OCS-APIRequest: true' -H 'Content-Type: application/json' -X POST 'https://<nextcloud>/ocs/v2.php/apps/integration_zammad/api/v1/ticket/notes?format=json' -d '{"ticket":"<id>","ticket_number":"<number>","text":"Summary\n- first point"}'
  3. Check the note in Zammad: internal, plain text with its line breaks, you as author, exactly the text you sent.
  4. Use another ticket's number: 400 ticket_mismatch.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Code, tests and this description were drafted with Claude Code (claude-opus-5-5) under my direction.

How this was tested before opening the PR

This version: 24 unit tests on Nextcloud 35 (note stored as given, wrong ticket number, Zammad errors, empty and too long notes, not connected), psalm, php-cs-fixer, OpenAPI extractor v1.9.1.

An earlier version, which added the footer on the server, ran on a sandbox Nextcloud 35.0.1 with a fake Zammad, directly and through the Context Agent. Against support.nextcloud.com, on a test ticket: a text/plain internal note posted form-encoded with internal=1, as Nextcloud's HTTP client sends it, was stored as internal, type note, sender Agent, and rendered with its line breaks and - list lines, so no JSON option is needed.

This version (05b9ac8, rebased on #296 with the contact-times fix) ran end to end on 2026-11-24 on a sandbox Nextcloud 35.0.1 against a fake Zammad, together with #298 and nextcloud/context_agent#335: through the Context Agent with scripted tool calls (confirmation asked, note stored internal and form-encoded with the footer the tool adds, ticket_mismatch with nothing sent to Zammad, the add-note tool hidden with ticket_api 1) and with Claude Haiku as the model. The run found that the tool's check for an earlier note needs the single ticket's last_contact_customer_at, which #296 now returns. The route has not run against a real Zammad yet.


Generated by Claude Code

@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 677a706 to e70d32c Compare November 18, 2026 16:08
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 3768841 to f591563 Compare November 18, 2026 16:32
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from e70d32c to 2d9286c Compare November 18, 2026 16:32
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch from f591563 to aba025f Compare November 18, 2026 17:37
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from aaf430c to 8a246c7 Compare November 18, 2026 17:47
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch from aba025f to 3d53583 Compare November 18, 2026 17:47
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch 2 times, most recently from 4dd5f71 to 76bc693 Compare November 18, 2026 18:04
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 152d4b8 to 1176599 Compare November 18, 2026 18:17
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 76bc693 to 602d9e6 Compare November 18, 2026 18:17
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 3 times, most recently from 3a29221 to c2d6fe5 Compare November 19, 2026 10:27
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from f7acc34 to 47c7c69 Compare November 19, 2026 10:27
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 2ccde0c to d54980b Compare November 19, 2026 13:15
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 6c93cd1 to 486b36f Compare November 19, 2026 13:15
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 0a78892 to 7e8d077 Compare November 19, 2026 15:04
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 12cf2b2 to 45f1db3 Compare November 19, 2026 15:04
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 45f1db3 to b058a99 Compare November 19, 2026 16:07
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 6895625 to f980027 Compare November 19, 2026 16:23
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch 2 times, most recently from 6a5e26f to ab971ef Compare November 19, 2026 17:24
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch from f980027 to acbad62 Compare November 19, 2026 17:24
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from ab971ef to d483afc Compare November 19, 2026 17:28
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 7ad0966 to b765a7c Compare November 19, 2026 17:35
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from d483afc to 5c27337 Compare November 19, 2026 17:35
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 64a2482 to 3f2cd30 Compare November 19, 2026 18:11
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch from 3f2cd30 to 8729cfb Compare November 19, 2026 18:23
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 08deba1 to 6fca5cb Compare November 19, 2026 18:23
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from f25545b to 7705b91 Compare November 19, 2026 18:26
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 41fc5bd to 487ed73 Compare November 19, 2026 18:26
funana777 added a commit that referenced this pull request Nov 19, 2026
A check against support.nextcloud.com showed that Zammad stores a note
posted as form fields with internal=1 as internal, the way Nextcloud's
HTTP client sends an array body. The JSON option on
ZammadAPIService::request() is no longer needed, so #297 leaves that
service unchanged.

Assisted-by: ClaudeCode:claude-opus-5-5
funana777 added a commit that referenced this pull request Nov 19, 2026
A check against support.nextcloud.com showed that Zammad stores a note
posted as form fields with internal=1 as internal, the way Nextcloud's
HTTP client sends an array body. The JSON option on
ZammadAPIService::request() is no longer needed, so #297 leaves that
service unchanged.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch from 3219f1d to 14b3ba9 Compare November 19, 2026 18:38
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from 487ed73 to bcd138a Compare November 19, 2026 18:52
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from efa72f0 to b08ebcb Compare November 19, 2026 18:58
@funana777
funana777 force-pushed the feat/zammad-assistant-read branch from bcd138a to 80f4fbf Compare November 19, 2026 18:58
$this->l10n->t('Ticket %s does not exist, or your Zammad account has no access to it.', [(string)$ticketId])),
default => self::error(Http::STATUS_BAD_GATEWAY, 'zammad_error', $this->l10n->t('Zammad answered with an error.')),
};
return $this->zammadError($response, $ticketId);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change? Shouldn't be in this PR, IMO.

$this->l10n->t('Give a ticket ID or a ticket link like %s/#ticket/zoom/123.', [$zammadUrl]));
$ticketId = TicketText::parseTicketReference($zammadUrl, $ticket)['id'] ?? null;
if ($ticketId === null) {
return $this->invalidTicket($zammadUrl, $ticket);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change.

Comment thread lib/Controller/TicketApiController.php Outdated
}
}

$footer = self::ASSISTANT_FOOTER_PREFIX . $this->getAuthorName();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not lose generality of the API. Anyone could be using this API and would then get the created by assistant footer. That's not nice.

Comment thread lib/Controller/TicketApiController.php Outdated
'sender' => self::stringOrNull($article['sender'] ?? null),
'type' => self::stringOrNull($article['type'] ?? null),
'internal' => !empty($article['internal']),
'assistant_note' => self::isAssistantNote($article),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's lose this.

@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch 2 times, most recently from 8016961 to 9daa1e1 Compare November 24, 2026 13:42
@funana777

Copy link
Copy Markdown
Author

Thanks! All four addressed:

POST /api/v1/ticket/notes writes an internal note with the user's own
token, so Zammad shows the user as its author and decides whether they
may add notes. The note is plain text and is stored as given: the API
adds no footer and does not check for earlier notes, so any client can
use it. Marking and recognizing the Assistant's own notes is up to the
client.

A note is refused if the ticket has a different number than the one the
caller meant, a mistake an agent can make with similar tickets. The
title a client shows the user is not checked.

The capability's ticket_api goes to 2, so clients only offer notes
where the route exists. On support.nextcloud.com, a note posted as
form fields with internal=1, the way Nextcloud's HTTP client sends it,
was stored as an internal note and rendered with its line breaks.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
@funana777
funana777 force-pushed the feat/zammad-assistant-notes branch from 9daa1e1 to 05b9ac8 Compare November 24, 2026 16:41

This branch has not been deployed

No deployments
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.

2 participants