> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open.cx/llms.txt
> Use this file to discover all available pages before exploring further.

# Ticket Flow

> How OpenCX processes Gorgias tickets, replies to customers, and hands off to your team when the AI cannot resolve.

Once your Gorgias helpdesk is [connected](/integrations/gorgias/connect), OpenCX listens for customer messages via webhook and processes them in real time. This page covers how messages flow, when the AI replies, and what happens on handoff.

## How tickets flow

```mermaid theme={"dark"}
flowchart LR
  A[Customer messages on ticket] --> B[Gorgias webhook]
  B --> C[OpenCX AI]
  C --> D{Can resolve?}
  D -- Yes --> E[AI replies on ticket]
  D -- No --> F[AI replies + marks handoff]
  F --> G[Gorgias workflow routes to rep]
```

## What the AI listens for

OpenCX processes one type of Gorgias event: **customer messages on tickets assigned to the AI user**.

| Condition                                                             | What OpenCX does                                                     |
| --------------------------------------------------------------------- | -------------------------------------------------------------------- |
| **Customer sends a message** on a ticket assigned to the AI user      | Creates or continues a session and generates an AI reply.            |
| **Customer sends a message** on a ticket assigned to a different user | Ignores the message — the ticket belongs to a human agent.           |
| **Agent replies** on a ticket                                         | Not processed. Gorgias webhooks for agent messages are filtered out. |

<Note>
  OpenCX only processes messages where the sender email matches the customer email on the ticket. Internal notes and agent replies are ignored.
</Note>

## AI reply

When the AI generates a response, it posts the reply directly on the Gorgias ticket via the API. The reply appears as a message from **AI Assistant** (`ai@open.cx`), visible to the customer in whatever channel they used (email, chat, social).

<Note>
  AI replies are posted through the Gorgias REST API, not as the configured Gorgias user. The sender name in Gorgias shows "AI Assistant." To control how this appears to customers, configure your Gorgias email templates.
</Note>

## Handoff to your team

When the AI determines it cannot resolve a ticket, three things happen:

<Steps>
  <Step title="AI posts a final reply">
    The AI sends a response on the ticket — typically acknowledging the customer's request and letting them know a team member will follow up.
  </Step>

  <Step title="Session is marked as handed off">
    The OpenCX session state changes to handed off. The AI will not process further messages on this ticket, even if it remains assigned to the AI user.
  </Step>

  <Step title="Ticket is reassigned">
    OpenCX reassigns the ticket to the configured default user and team (if set) via the Gorgias API. If you configured a **default team**, the ticket moves into that team's view.
  </Step>
</Steps>

<Warning>
  **Set up a Gorgias workflow rule** to route handed-off tickets to the right agent. Since the AI stops processing after handoff, the ticket needs a human to pick it up. A Gorgias rule that triggers on assignment change or team change is the recommended approach.
</Warning>

## What the rep sees

* The ticket appears in their **Gorgias inbox** — routed there by your Gorgias workflow rule.
* The full AI-to-customer conversation is already in the ticket thread — no separate tool to check.
* The customer's email, name, and order context (if Gorgias has it) are on the ticket as usual.

## Good to know

<AccordionGroup>
  <Accordion title="Assignment-based processing" icon="user-check">
    The AI only touches tickets assigned to the default user ID you configured. If a ticket is assigned to anyone else — or is unassigned — OpenCX ignores it entirely. This prevents the AI from interfering with tickets your human agents are already working on.
  </Accordion>

  <Accordion title="Duplicate message protection" icon="shield-check">
    OpenCX deduplicates incoming messages using a content hash. If Gorgias delivers the same webhook event twice (e.g. due to a retry), the AI will not reply a second time. The deduplication window is 1 hour.
  </Accordion>

  <Accordion title="Session continuity across messages" icon="messages">
    All messages on the same Gorgias ticket map to the same OpenCX session. The AI sees the full conversation history when generating each reply, not just the latest message.
  </Accordion>

  <Accordion title="Reply format" icon="envelope">
    AI replies are posted via the Gorgias API as text messages from "AI Assistant" (`ai@open.cx`). On the Gorgias side, they appear as API-sourced messages. The customer receives them in whatever channel they originally used — the display format depends on your Gorgias email templates and channel settings.
  </Accordion>

  <Accordion title="After handoff, the AI stops" icon="circle-stop">
    Once a session is marked as handed off, the AI ignores all further messages on that ticket — even if the ticket remains assigned to the AI user in Gorgias. This prevents the AI from interfering after your team takes over.
  </Accordion>
</AccordionGroup>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Connect Gorgias" icon="plug" href="/integrations/gorgias/connect">
    Credentials, webhook URL, and default assignee setup.
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/integrations/gorgias/troubleshooting">
    Webhook not firing, AI not replying, handoff not reassigning.
  </Card>

  <Card title="Gorgias Overview" icon="cart-shopping" href="/integrations/gorgias/overview">
    What the integration does and supported channels.
  </Card>

  <Card title="Autopilot" icon="sliders" href="/handoff/topics">
    Configure which topics the AI handles and which it skips.
  </Card>
</CardGroup>
