fix: notify assigned agent when customer replies via email#377
Open
akash2017sky wants to merge 4 commits into
Open
fix: notify assigned agent when customer replies via email#377akash2017sky wants to merge 4 commits into
akash2017sky wants to merge 4 commits into
Conversation
When the email-poll path adds a comment to an existing ticket (`action: comment_added`), send an internal notification to pull the agent's attention rather than wait for them to spot the new comment in the queue. - Notify the ticket's `System.AssignedTo`. If the work item has no assignee (or the assignee is a team identity, not a user), fall back to `SUPPORT_TEAM_NOTIFY_EMAIL`. If neither, log and skip — comment add is unaffected. - Fire-and-forget — the notify call is wrapped so any send failure cannot block or fail the ticket update. - Only triggers from `handleThreadReply`. Comments added from the agent UI use a different code path and never produce a notification. - Internal email goes on its own thread (no `In-Reply-To`), so it doesn't pollute the customer-facing conversation. - Same `renderEmailBody` pipeline as the on-ticket comment, so signature stripping is consistent. Closes #360 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adding SUPPORT_TEAM_NOTIFY_EMAIL pushed the description column past the existing padding. Re-run prettier to widen the column so format:check passes on CI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the email-poll path adds a comment to an existing ticket (
action: comment_added), send an internal notification to the assigned agent so they don't have to discover the reply by refreshing the queue.System.AssignedTo.uniqueNameif it looks like an email, otherwise the newSUPPORT_TEAM_NOTIFY_EMAILenv var, otherwise log and skip.handleThreadReply. Agent-UI comments use a different code path and never produce a notification.In-Reply-Toheader pointing at the customer's email), so it doesn't pollute the customer-facing conversation.renderEmailBodypipeline as the on-ticket comment, so signature stripping is consistent between the two views the agent sees.Fixes
Fixes #360
What this covers
[ZapDesk #N]-tagged email; ticket has an assignee[ZapDesk #N] New customer reply — "<title>"in their inbox with aView Ticket #NbuttonSUPPORT_TEAM_NOTIFY_EMAILis set, the team address gets the notification. Otherwise a[Notify] … skippinglog line is emitted and the comment add still succeeds.@inuniqueName)SUPPORT_TEAM_NOTIFY_EMAIL.action: "comment_added".Files changed
src/lib/email-ingest.ts— capture the work item returned byaddComment, extractSystem.AssignedTo+System.Title, fire-and-forgetsendCustomerReplyNotificationcall. Adds aWorkItemFieldsResponsetype for the PATCH response shape and anotifyAgentOfReplyhelper.src/lib/email.ts— newsendCustomerReplyNotificationexported. UsesgenerateMessageId(id, 'agent-notify')and deliberately omitsinReplyToso the agent thread is independent of the customer thread.src/lib/email-templates.ts— newcustomerReplyNotificationTemplatereusing the existing layout/branding.CLAUDE.md— documents the new optionalSUPPORT_TEAM_NOTIFY_EMAILenv var.New env var
SUPPORT_TEAM_NOTIFY_EMAILsupport@your-domain.com.Test plan
Local manual (verified)
bun run dev, ensureMAIL_*,AZURE_DEVOPS_PAT,EMAIL_WEBHOOK_SECRET,MAIL_POLL_MAILBOXare set.Subject: [ZapDesk #N] testing notification.fetched: 1, ingested: 1,results[0].result.action: "comment_added",ticketId: N.[ZapDesk #N] New customer reply — "<original ticket title>", body showsSubject:,From:, the customer reply (signature-stripped) and a greenView Ticket #Nbutton.Fallback path (verified earlier in the same session)
[ZapDesk #N]email.SUPPORT_TEAM_NOTIFY_EMAILset: notification arrives at the team address.[Notify] No agent assigned and SUPPORT_TEAM_NOTIFY_EMAIL not set — skipping notification for ticket #N. Comment is still added —action: "comment_added"in the response.Failure path (graceful degradation)
MAIL_CLIENT_SECRET, send a[ZapDesk #N]email, re-poll.action: "comment_added"; comment still on the ticket; dev-server logs[Email] Failed to send customer reply notification for ticket #N: .... Restore secret afterwards.UI-originated comments
[Notify]or[Email] Customer reply notificationlog line. The notification path is scoped strictly to inbound email replies.Automated checks
bun run typecheck— passesbun run lint— passes (4 pre-existing warnings, unrelated)bunx prettier --checkon changed files — passesOut of scope
🤖 Generated with Claude Code