Skip to content

Workflow Reply Text Design

Ed Mozley edited this page Nov 29, 2026 · 2 revisions

The requester's reply in a workflow - design (discussion #451)

Status: step 1 (the reply merge codes) built 29 November 2026 (#3253-#3255), not yet released. Step 2, the optional AI clean-up (section 6), comes later. The code is in includes/workflow_reply.php and workflow/includes/engine.php; the test is tests/workflow-reply-text.php. How it works underneath: Workflow Reply Text - Developer Guide.

The request, from @marek557 on discussion #451:

"It would be great if I could get that reply in the notification email sent via workflows. My thought process is if I am not in the office, I can see what their reply is and reply again if needed. I am trying to avoid adding a shared mailbox/delegate access in Office 365."

@chaseakub checked the code and found the gap: when a requester replies, the The requester replies to a ticket trigger (ticket.reply_received) gives a workflow the ticket's fields and where the reply came from (email or portal). It doesn't give the text of the reply, so no merge code can show it. Their workaround of putting {{ticket.url}} in the email works, but you still have to open FreeITSM to read the reply.

In plain words

  • A workflow on "The requester replies to a ticket" gets the reply itself: who sent it, when, and what it says. {{reply.new_text}} in a Send email action puts the requester's words into the notification, so you can read them on your phone without a shared mailbox.
  • Two versions of the text. {{reply.body}} is the reply as it shows on the ticket. {{reply.new_text}} is only what they just wrote, with the quoted earlier emails removed. When FreeITSM can't tell where the quoted part starts, new_text is the whole message, so the worst case is a longer email and nothing is ever lost.
  • Confidential tickets keep their current protection. A workflow already only emails a confidential ticket to its requester or to analysts, and never posts one to a webhook, Slack or Teams. The reply text follows the same rules (section 4).
  • AI clean-up is a later, optional extra (section 6): off by default, only where an AI provider is set up, and it can never add words the requester didn't write.

1. The new merge codes

Offered on The requester replies to a ticket only, for both email and portal replies:

Merge code What it gives Example
{{reply.from}} The sender's email address sam@example.com
{{reply.from_name}} The sender's name, as it arrived Sam Patel
{{reply.received}} When it arrived, in the install's time zone 29 Nov 2026 14:05
{{reply.subject}} The subject line of the reply RE: Printer on 2F [ETC-623-64409]
{{reply.new_text}} Only what they just wrote, without the quoted emails underneath Still jammed, I've turned it off.
{{reply.body}} The reply as it shows on the ticket (see section 2)
{{reply.has_attachments}} Yes or No Yes

The text codes are plain text: the email's HTML is turned into readable text (paragraphs, line breaks and list items kept, pictures and formatting dropped). That is what reads properly in a notification email, a Teams card or a ticket note. In an HTML email body (Send email with an HTML template) the text goes in escaped, with its line breaks kept, so a reply that says <b> shows <b> rather than turning bold, and nothing the requester typed can become part of the email's markup. Whether a body is HTML is decided from the template, never from the finished email. Each is capped at a sensible length (about 10,000 characters), with "... (cut short - the whole reply is on the ticket)" at the end when it is longer.

Workflow conditions can use them too, for example "Reply · New text contains 'urgent'".

2. Taking off the quoted emails

Some of this already happens before a workflow sees the reply. When an emailed reply arrives, FreeITSM cuts it at its own "Please reply above this line" marker, or failing that at the first quoted block, before storing it (stripInboundThread() in api/tickets/check_mailbox_email.php). So {{reply.body}} is that stored reply, as analysts see it on the ticket. It's usually already short, but not when someone replies to an email FreeITSM didn't send, or their mail program drops the marker.

new_text cuts further, at the first sign of quoted history from other mail programs that it recognises, checked in this order:

  1. The quoted blocks mail programs put in the HTML: Outlook's reply header block, Gmail's gmail_quote, Apple Mail's and Thunderbird's quoted blockquote.
  2. The lines that start a quoted email in plain text: "On Mon, 28 Nov 2026, Jo wrote:", Outlook's "From: ... Sent: ..." header, "-----Original Message-----", and lines starting with >.
  3. A portal reply has no quoted history, so it's always the whole message.

It is deliberately cautious. It only cuts at a marker it recognises and never guesses. If nothing is found, or the cut would leave nothing, new_text is the whole message. Forwarded emails are where every method of this kind goes wrong, and here a mistake costs a longer email, never a missing sentence.

This is the same problem the ticket screen already solves by collapsing quoted history (Tickets → Settings → Reading long tickets). That collapsing only hides text in the page. This one actually removes text, so it uses its own stricter, server-side rules rather than guessing like the screen can.

3. How it works underneath

  • The trigger passes the stored message's id (reply.email_id), plus from, from_name, received, subject and has_attachments, which are short.
  • The text is only loaded when an action uses it. The engine already works this way for {{ticket.full}} (fullForTemplates() in workflow/includes/engine.php): it looks at the action's settings, and only if one mentions reply.body or reply.new_text does it read the message and work out the text. A workflow that doesn't use the text costs nothing extra, and the text isn't copied into the notification bell or the search index.
  • It isn't stored in the run history. A run's log records the event before the text is loaded, so the reply text isn't kept again in Workflows → History. The exception is a Test fire dry run, whose preview shows what each action would send. The text is already stored once, on the ticket.
  • Both places that fire the trigger pass the reply's id: the email check (api/tickets/check_mailbox_email.php) and the portal reply (api/self-service/reply_ticket.php).
  • Found while building it: the portal reply fired the trigger inside its database transaction. The workflow engine reads with its own connection, so it couldn't see the reply that had just been saved, and the text came out blank. The trigger now fires after the commit, which is also where a workflow's own changes belong.

4. Confidential tickets

This follows rules FreeITSM already has (discussion #62), so a workflow can't get round them:

Action On a confidential ticket
Send email The text is filled in, and the email is only sent if every address is the ticket's requester or an analyst. That rule is already enforced. Anyone else and the email isn't sent, and the run history says why.
Webhook, Slack, Teams The text is empty. These already get only the ticket's number and status for a confidential ticket, because a chat post can't be taken back.
Everything else (create a ticket, add a note, set a field...) The text is empty, the same rule as {{ticket.full}}, so a confidential reply can't be copied into an ordinary ticket.

So @marek557's case works on every ticket: an email to an analyst is allowed, confidential or not.

5. Decisions

Date Question Decided Why
29 Nov 2026 Is @chaseakub's reading right, and should the reply go into the trigger? Yes (Ed) The reply is what the notification is about; a link alone means opening FreeITSM to read it.
29 Nov 2026 Should there be AI to pick out the last reply? Yes, as an optional later step on top of the non-AI version, not instead of it (Ed) The non-AI version covers most replies with no cost, no delay and no data leaving the building; AI is for installs that want the awkward cases handled better.
29 Nov 2026 Whole message, new part, or both? Both, reply.body and reply.new_text Some people want the context, most want the new words.
29 Nov 2026 Confidential tickets Follow the existing #62 rules (section 4), no new setting The rules are already there and already trusted; a second set of rules for one trigger would be a gap waiting to happen.

6. Step 2, later: optional AI clean-up

An extra tick on the Send email (and note) action: "Use AI to pick out the new text". It is only shown where an AI provider is set up under System → AI, and it's off by default.

  • Word for word, never a summary. The AI is asked to return the requester's new words exactly as written. When someone reads a reply away from their desk they need what was actually said; a summary can drop or change the one detail that matters ("room 214, not 241").
  • Checked before it's used. FreeITSM checks the AI's answer appears in the original message. If it doesn't (the AI reworded something, or added a word), the answer is thrown away and the non-AI new_text is used. So the AI can make the cut better but can never put words in the requester's mouth.
  • Doesn't hold up the mail check. Replies are processed while the mailbox is being checked, so the AI call can't sit in that path. A workflow using it is run in the background, so a slow or failing provider delays one notification, not every email.
  • Cost and data, said plainly. Every reply a workflow uses it on goes to the AI provider. The tick says so, and a confidential ticket follows the install's AI setting for confidential tickets (System → AI).

Not in this

  • The reply's attachments in the notification. {{reply.has_attachments}} says there are some; the files stay on the ticket.
  • Replying from the notification email back into the ticket. That already works when the notification is sent from the ticket's mailbox with the ticket reference in the subject, and is a separate topic.
  • Analysts' replies. This trigger is the requester replying; an analyst's reply isn't what @marek557 asked for.

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally