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

# Chat Taken

> Fires when an agent takes (is assigned) a chat

ubscribe to receive a notification when a chat is **taken by an agent**. The payload includes the full chat plus a narrowed agent object - useful for syncing ownership to your CRM.

**Event name:** `chatAssigned`\\

**Required token scopes:**

* `Create scenarios`
* `Manage scenarios on behalf of user`

see [Authentication](/he/api-reference/authentication)

## Subscribe

Send the body below to [Import Subscription](/he/api-reference/subscribe-to-events/import-subscription-subscribe-to-an-event). You only need to change:

* **`url`** *(required)* - Located under `data.actions[0].params.url`. Replace `{{yourWebhookURL}}` with the destination URL that should receive the events.
* **`asStatus`** - Keep `"active"` to enable the subscription immediately, or `"inactive"` to save it as an inactive revision.

```json Import body [expandable]  theme={null}
{
  "data": {
    "version": "v1",
    "name": "(SUB) Chat Assigned",
    "description": "Sends a webhook when a chat is assigned, with full chat data and a narrowed agent object.",
    "triggerEvents": [
      "domain.chat.assigned"
    ],
    "loaders": {},
    "conditions": [],
    "actions": [
      {
        "name": "request",
        "params": {
          "url": "{{yourWebhookURL}}",
          "method": "post",
          "json": true,
          "data": {
            "eventName": "chatAssigned",
            "eventData": {
              "chat": {
                "##provide": {
                  "provider": "chat",
                  "key": "chat"
                }
              },
              "agent": {
                "id": {
                  "##provide": {
                    "provider": "agent",
                    "key": "_id"
                  }
                },
                "crmId": {
                  "##provide": {
                    "provider": "agent",
                    "key": "crmId"
                  }
                },
                "email": {
                  "##provide": {
                    "provider": "agent",
                    "key": "email"
                  }
                },
                "displayName": {
                  "##provide": {
                    "provider": "agent",
                    "key": "displayName"
                  }
                },
                "roles": {
                  "##provide": {
                    "provider": "agent",
                    "key": "roles"
                  }
                }
              }
            }
          }
        },
        "confidentialData": false
      }
    ],
    "options": {
      "unorderedActions": false
    }
  },
  "asStatus": "active"
}
```

<Note>
  A `201` response returns your new subscription - save its `_id` to manage it later. You can also add an optional `authorUid` root field (a Texter user UID) to attribute the subscription to a specific user.
</Note>

## Payload

When the event fires, your URL receives an HTTP `POST` with `eventName: "chatAssigned"` and the following `eventData`:

<ResponseField name="chat" type="Chat">
  The chat that was taken. See the [Chat object](/he/api-reference/objects/chat) for all fields.
</ResponseField>

<ResponseField name="agent" type="object">
  A narrowed agent object: `id`, `crmId`, `email`, `displayName`, `roles`.
</ResponseField>

```json Example payload  theme={null}
{
  "eventName": "chatAssigned",
  "eventData": {
    "chat": {
      "_id": "69062b15262e17ab3033f886",
      "displayName": "Josh Dun",
      "...": "..."
    },
    "agent": {
      "id": "333aed7a-b3ea-4e5c-acbc-d8499be509c3",
      "crmId": "alex1999",
      "email": "agent@example.com",
      "displayName": "Alex",
      "roles": [
        "admin"
      ]
    }
  }
}
```

## Manage this subscription

| Action             | Endpoint                                                                                 |
| ------------------ | ---------------------------------------------------------------------------------------- |
| List subscriptions | [List All Subscriptions](/he/api-reference/subscribe-to-events/list-all-subscriptions)   |
| Pause              | [Inactivate Subscription](/he/api-reference/subscribe-to-events/inactivate-subscription) |
| Resume             | [Activate Subscription](/he/api-reference/subscribe-to-events/activate-subscription)     |
| Delete             | [Delete Subscription](/he/api-reference/subscribe-to-events/delete-subscription)         |
| Debug executions   | [List Scenario Runs](/he/api-reference/scenarios-advanced/list-scenario-runs)            |
