# Help Scout Conversation Creation

## Objective

Turn an in-app help request into a Help Scout conversation in the right mailbox.

A submission path that opens a Help Scout conversation with the customer, mailbox, tags, and assignee already set correctly.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Resolve the customer from the authenticated session and match on that address exactly. Do not create a customer from a free-text field the user can type, and do not read a matched customer's history back into the app.
2. Make the destination mailbox, tag set, and default assignee configurable per request type, and validate the chosen mailbox when the configuration is saved rather than discovering it is gone at submission time.
3. Preserve what the user actually wrote: line breaks, ordering, and any quoted error text. Send it in a form the provider renders faithfully instead of collapsing the whole message into one paragraph.
4. Carry a request identifier generated before the first attempt through every retry, and deliver through the app's existing background-job system so retry and backoff behaviour is the one the app already has.
5. If Zendesk or Freshdesk briefs are also applied here, exactly one of them owns the user-facing form, the context capture, and the deduplication. This brief supplies only the Help Scout mapping and delivery on top of that shared path.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Matching a customer by email must not leak: the matched record's existing conversations must never be shown back to whoever submitted the form.
- A mailbox that was archived, deleted, or lost permission must fall back to a configured default and raise an operator alert rather than dropping the request on the floor.
- An assignee who has left the team must not silently swallow the conversation into a dormant inbox. Fall back to unassigned so the queue picks it up.
- Attachment metadata — original filename, type, and size — must survive the transfer, or agents receive a wall of unnamed binaries they cannot triage.
- A retry after a timeout must be matched on the request identifier, because the first attempt may have created the conversation before the response was lost.
- Rate limits and provider outages must queue the request with bounded backoff, and the user must be told their message was received rather than shown a provider failure.
- User-supplied text must be escaped before it is placed into rendered content, so a message containing markup cannot alter formatting or embed a link the sender did not write.
- The conversation identifier must be stored against the app record so a later reply threads onto the same conversation.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] A request creates a conversation in the mailbox configured for that request type.
- [ ] The customer is resolved from the session and no matched history is exposed back into the app.
- [ ] Message formatting and attachment metadata arrive intact.
- [ ] A retried submission produces exactly one conversation.
- [ ] A missing, archived, or inaccessible mailbox falls back to a default and alerts an operator.
- [ ] Provider downtime queues the request and the user still receives a clear confirmation.
- [ ] The conversation reference is stored against the app record.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
