Repository navigation
Conversation
fee27cd to
f11161f
Compare
677a706 to
e70d32c
Compare
f11161f to
52496b9
Compare
d483afc to
5c27337
Compare
487ed73 to
bcd138a
Compare
Ticket text goes to language models, which need what an article says itself, not the whole quoted mail thread. TicketText holds the text handling: - htmlToText and the ticket link parsing, moved unchanged from the Context Chat import and the link previews, where each was private. The import produces the same text as before. - articleText cuts an email's HTML body at Zammad's signature marker, <span class="js-signatureMarker"></span>, and removes blockquote elements from what is left with DOMDocument. A check against support.nextcloud.com showed the marker stored in the body of every quoted customer mail, before the signature and the quoted thread, for blockquote and Outlook-style replies alike, and that a quote can start before it. Plain-text mails are kept as they are, a message that would come out empty keeps all its text, and bodies over 1 MB are only converted. No language patterns: the quote header line before the marker stays, and some Outlook-style replies keep part of their quote. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
Lets the Assistant, and any other client, read Zammad tickets with the user's own token, so Zammad decides what the user may see, internal notes included. - GET /api/v1/tickets passes the query to Zammad's ticket search unchanged, with mine, limit (at most 20), sort_by and order_by. Each ticket has its state, priority, owner and customer as names and Zammad's own contact and escalation times. A refused query is reported as search_failed; Zammad's server errors as zammad_error. - GET /api/v1/ticket?ticket=<ID or link> returns one ticket with its articles as plain text, newest last. Email articles go through the quote cleanup; notes, web form, phone and chat articles are kept whole. If the articles do not fit into max_chars, the oldest are left out and truncated is true. Attachments are listed, not downloaded. Links to another Zammad server are refused. - Lists and tickets name people the same way, from the assets Zammad returns with full=true. Those assets carry no groups for an agent token, so tickets have no group field; group.name: in a query works. - A capability, so clients can see that the API exists, the OpenAPI spec with its CI check, and a README section. InstanceIdTest pins the Context Chat instance ID that the Context Agent's tools compute too. The controller calls ZammadAPIService directly: no settings, no service layer, no computed ticket flags. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
bcd138a to
80f4fbf
Compare
| if (!is_int($code) || $code >= 500) { | ||
| return self::error(Http::STATUS_BAD_GATEWAY, 'zammad_error', $this->l10n->t('Zammad answered with an error.')); | ||
| } | ||
| return self::error(Http::STATUS_BAD_REQUEST, 'search_failed', $this->l10n->t('Zammad could not run this search. Check the query syntax.')); |
There was a problem hiding this comment.
We should pass through errors more fine granularly. e.g. 403 is now reported as "Check query syntax"
There was a problem hiding this comment.
True. I'll separate errors for 401/403 (no access), 404, 429 (rate limit), and only real query errors as search_failed.
There was a problem hiding this comment.
For the record, now that it's pushed in dcdd633: 401 returns bad_credentials (412), 403 returns forbidden (403), and only 400/422 return search_failed. 404, 429 and anything else return zammad_error (502) with Zammad's status in the message, so a rate limit shows up but has no code of its own.
| return self::error(Http::STATUS_PRECONDITION_FAILED, 'not_connected', | ||
| $this->l10n->t('Your Zammad account is not known yet. Please disconnect and connect it again in the Connected accounts settings.')); | ||
| } | ||
| $query = $query === '' ? 'owner_id:' . $zammadUserId : '(' . $query . ') AND owner_id:' . $zammadUserId; |
There was a problem hiding this comment.
This only works if ElasticSearch is installed with Zammad. Not sure how we can know that.
There was a problem hiding this comment.
"mine" is now sent as a search condition, which Zammad applies on both backends. The docs now say that field syntax in query needs Elasticsearch.
Co-authored-by: Marcel Klehr <mklehr@gmx.net> Signed-off-by: Christian Fu Mueller <fu@funana.de>
Every refused search was reported as a query syntax error, also when Zammad answered 403 because the account may not search tickets, and server errors and network errors read the same. Now a search answers 403 forbidden when Zammad refuses access, 400 search_failed only when Zammad refuses the search itself (400 or 422, e.g. an unknown sort_by), and 502 zammad_error with Zammad's status code in the message, or that Zammad could not be reached. The error handling of a ticket request moves into zammadError() and invalidTicket(), which the notes route builds on. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
The mine filter added owner_id:<id> to the search query. Only Elasticsearch understands that syntax. Without it, Zammad matches the query as plain text against title, number and articles, so the filter found no tickets at all, and no error said why. The filter is now sent as a search condition on ticket.owner_id, which Zammad applies on both search backends (Zammad 6.0 and later). The docs of the query parameter now say that field syntax needs Elasticsearch, and that a query Zammad cannot parse finds no tickets instead of giving an error. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
d343aa8 to
1b33d1d
Compare
GET /api/v1/ticket left out last_contact_customer_at, last_contact_agent_at and escalation_at, which the list route already returns. The Assistant's note tool compares its last note with last_contact_customer_at, so without it every note after the first one on a ticket was refused as already_noted, even after the customer had written again. Found in a sandbox run of the stack against a fake Zammad. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
4e499cd to
7959525
Compare
Adds OCS routes that let the Nextcloud Assistant, and any other client, list Zammad tickets and read a ticket with its conversation.
Base: #295 (
feat/zammad-tooling). Merge #295 first. #297 (notes) builds on this PR. The tools that use these routes are in nextcloud/context_agent#335.Why
Support teams work in Zammad and want the Assistant's help on tickets. Today the Assistant cannot read a ticket: asked about one, it calls Zammad without a token and then asks the user to paste one into the chat. The user's token already sits in this app, so the routes go through it. Every call uses the user's own token, and Zammad decides what the user may see, internal notes included.
What
GET /api/v1/tickets: passes the query to Zammad's ticket search unchanged (the same syntax as Zammad's search bar), withmine,limit(at most 20),sort_byandorder_by. Each ticket has its state, priority, owner and customer as names, and Zammad's own contact and escalation times.mineis sent as a search condition on the ticket owner, which Zammad applies with and without Elasticsearch. Field syntax in the query needs Elasticsearch on the Zammad server; without it, Zammad matches the query as plain text. Errors:forbidden(403) when Zammad refuses access,search_failed(400) only when Zammad refuses the search itself (400 or 422, e.g. an unknownsort_by), otherwisezammad_error(502) with Zammad's status code in the message.GET /api/v1/ticket?ticket=<ID or link>: one ticket with its articles as plain text, newest last. Email articles are cut at Zammad's signature marker and lose their blockquotes; notes, web form, phone and chat articles are kept whole. If they do not fit intomax_chars(which the Context Agent sets to the room the model has), the oldest are left out andtruncatedis true. Attachments are listed, not downloaded. Links to another Zammad server are refused.full=true.last_contact_customer_atto tell whether the customer wrote after its last note.ticket_api: 1), the OpenAPI spec with its CI check, and a short README section.Notes for review:
ZammadAPIServicedirectly. No new service, no settings.<span class="js-signatureMarker"></span>in the HTML body of incoming mails, before the signature and the quoted thread, for blockquote and Outlook-style replies alike;preferences.signature_detectionwas never set. The body is cut at the marker, then blockquotes are removed withDOMDocument, as a quote can start before the marker. No language patterns: the quote header line ("On ... wrote:") before the marker stays in the text. Known limit: in some Outlook-style replies Zammad puts the marker well after Outlook's quote header, so part of the quoted mail stays. The size limit still applies, and the similar-ticket search only uses the first customer message.InstanceIdTestpins the Context Chat instance ID with the same test vector as the Context Agent's tools, which compute it too.1,889 lines added, 44 removed; without
openapi.json1,059 added, of which 93 are the OpenAPI CI workflow and 285 tests.How to test
composer run test:unitcurl -u user:pass -H 'OCS-APIRequest: true' 'https://<nextcloud>/ocs/v2.php/apps/integration_zammad/api/v1/tickets?query=state.name:new&format=json'..../api/v1/ticket?ticket=https://<zammad>/%23ticket/zoom/<id>&format=json. Quoted mail history is gone, internal notes are markedinternal: true. With&max_chars=4000on a long ticket, older articles are left out andtruncatedis true.🤖 AI (if applicable)
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
On a sandbox Nextcloud 35.0.1 against a fake Zammad API on
zammad.example.comwith realistic JSON: an HTML mail with quoted history, internal notes, a 40-article thread. Covered: field queries,mine, quote stripping, internal notes in the result, truncation withmax_chars, the error responses and the capability. List and single ticket give the same owner and customer names. The routes were also used by the Context Agent in the end-to-end runs described in nextcloud/context_agent#335. 20 unit tests; psalm (stable32) shows no new errors. After review: the error mapping and theminecondition are covered by unit tests on Nextcloud 35, and theconditionparameter was checked in Zammad's source (6.0.0, 7.2.3 and develop), not yet against a real Zammad.End-to-end run on 2026-11-24 with the whole stack (#297, #298, nextcloud/context_agent#335) on a sandbox Nextcloud 35.0.1 against a fake Zammad, first with scripted tool calls, then with Claude Haiku as the model. It found the missing contact times on a single ticket, fixed in the last commit (one more unit test assertion, red without the fix).
Generated by Claude Code