> ## 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.

# AI Chat Widget in Dynamics 365

> Route web chat conversations from the AI Chat Widget into Dynamics 365 Omnichannel for Customer Service as live work items.

Widget conversations hand off as <Tooltip tip="A Dataverse record (entity: oc_liveworkitem) that Omnichannel for Customer Service picks up and routes to a rep's Omnichannel Agent app.">Omnichannel live work items</Tooltip>, not incidents. When the AI hands off a chat, your rep picks it up as a real-time chat inside the **Omnichannel Agent** app — no case opened, no ticket queue.

## Pre-requisites

<Warning>
  **Install the AI Chat Widget on your site first.** Dynamics handoff has nothing to route until the widget is live — start with [Install Widget](/widget/install-widget) and come back here.
</Warning>

* **Widget installed and reachable** — see [Install Widget](/widget/install-widget).
* **Dynamics 365 credentials saved** — see [Connect to OpenCX](/integrations/dynamics-365/connect).

## How conversations land in Dynamics 365

```mermaid theme={"dark"}
flowchart LR
  A[Visitor opens widget] --> B[AI answers]
  B --> C{AI can resolve?}
  C -- Yes --> D[Visitor closes chat]
  C -- No --> E[Handoff triggers]
  E --> F[oc_liveworkitem created]
  F --> G[Rep picks up in Omnichannel Agent]
```

## Setting up

<Steps>
  <Step title="Confirm the widget is live">
    Open the page where the widget is embedded and send a test message. You should see the AI respond. If not, walk through [Install Widget](/widget/install-widget) first.
  </Step>

  <Step title="Confirm Dynamics is connected">
    In your [OpenCX dashboard](https://platform.open.cx/settings/integrations), the **Dynamics 365** card should show **Active**. If it doesn't, re-run Test & Save in [Connect to OpenCX](/integrations/dynamics-365/connect).
  </Step>

  <Step title="Set a default workstream (optional but recommended)">
    The Omnichannel live work item routes to the workstream you pass as `workstreamId`. OpenCX uses your `default_queue_id` setting for that. Copy the workstream GUID from **Omnichannel admin center → Workstreams** and paste it into `default_queue_id` in the OpenCX Dynamics settings.
  </Step>

  <Step title="Trigger a test handoff">
    Say *"I want to talk to a human"* in the widget. The AI should hand off. Open the **Omnichannel Agent** app and accept the incoming chat.
  </Step>
</Steps>

<Tip>
  If the handoff lands as an **incident** instead of a live work item, the session's `channel` isn't `web`. See the troubleshooting scenario on routing below.
</Tip>

## What the rep sees

* A **live chat in the Omnichannel Agent app**, not a case in the Customer Service app.
* The AI's session summary as the **conversation subject**.
* `sessionId` and `channel: web` in the work item's <Tooltip tip="Key-value pairs OpenCX attaches to every live work item. Routing rules on your side can branch on these.">context variables</Tooltip> — `sessionId` is the trace key back to OpenCX.
* Customer name, email, and phone pre-filled on the work item from the session.
* OpenCX records `dynamics365_chat_id` on the OpenCX session for audit.

## Channel-specific details

<AccordionGroup>
  <Accordion title="Omnichannel routing rules apply on the Dynamics side" icon="route">
    OpenCX creates the `oc_liveworkitem` with a `workstreamId`; Dynamics's **Workstream → Routing rules → Assignment method** decide which queue and which rep picks it up. Align `default_queue_id` with a workstream that has routing rules you actually want.
  </Accordion>

  <Accordion title="Anonymous vs authenticated widget visitors" icon="shield-check">
    When the widget passes a verified email via [widget authentication](/widget/authentication), OpenCX links the existing Dynamics contact on that email. Anonymous visitors land with no contact linked on the work item — reps can link one manually.
  </Accordion>

  <Accordion title="Widget custom components still render on the visitor side" icon="bolt">
    When an AI action returns data rendered by a [custom component](/widget/custom-components), the visitor sees the richer UI. The rep in Omnichannel Agent sees the underlying text — write copy that reads well in both surfaces.
  </Accordion>

  <Accordion title="Rep replies in Omnichannel don't sync back to the widget today" icon="triangle-exclamation">
    Reps should continue the conversation inside the Omnichannel Agent app. OpenCX marks the session as handed off once the live work item is created; messages the rep sends in Dynamics stay in Dynamics.
  </Accordion>
</AccordionGroup>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="AI Chat Widget" icon="messages" href="/widget/introduction">
    Install, configure, authenticate the widget itself.
  </Card>

  <Card title="Conversations in Dynamics 365" icon="diagram-project" href="/integrations/dynamics-365/conversations">
    Routing rules, live work item payload, observability.
  </Card>

  <Card title="Connect to OpenCX" icon="plug" href="/integrations/dynamics-365/connect">
    Paste credentials and verify the connection.
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/integrations/dynamics-365/troubleshooting">
    Live work item never appears, handoff lands as incident instead.
  </Card>
</CardGroup>
