> For the complete documentation index, see [llms.txt](https://docs.saleschat.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.saleschat.pro/getting-started/webhooks.md).

# Webhooks

This page lists all the web hooks that we push to the web hook URL configured for your organisation

## Contact Assigned

Version 1.0

```json
{
	"type": CONTACT_ASSIGNED,
	"version":<double>,
	"payload": {
		"contact_id": <string>,
		"user_id": <string>,
		"is_handover": <boolean>,
		"is_assigned" : <boolean>
	}
}
```

## Chatroom Creation

Version 1.0 & 1.1

```json
{
	"type": CHATROOM_CREATED,
	"version":<double>,
	"payload": {
		"chatroom_id": <string>,
		"external_ref_id": <string>,
		"chatroom_type": <enum CONTACT | AFFILIATE >,
		"is_inbound" : <boolean>
	}
}
```

## Chatroom Status Update (Active/Deactive/Expired)

Version 1.0 & 1.1

```json
{
	"type": CHATROOM_ACTIVATED | CHATROOM_DEACTIVATED | CHATROOM_EXPIRED,
	"version":<double>,
	"payload": {
		"chatroom_id": <string>,
		"chatroom_type": <enum CONTACT | AFFILIATE >,
		"status_update_ts": timestamp
	}  
}
```

## Contact Expired

Version 1.0 & 1.1

```json
{
	"type": CONTACT_EXPIRED,
	"version":<double>,
	"payload": {
		"contact_id": <string>
	}  
}
```

## Send Template Message

Version 1.0 & 1.1

```json
{
	"type": SEND_TEMPLATE_MESSAGE_STATUS,
	"version":<double>,
	"payload": {
		"request_id": <string>,
		"chatroom_id": <string>,
		"remote_phone_id": <string>,
		"remote_waba_id": <string>,
		"remote_template_id": <string>,
		"status": <enum PERMANENTLY_FAILED | DELIVERED>,
		"err_code": <String>,
		"err_reason": <String>
	}  
}
```

## Media Received

Version 1.0 & 1.1

> This webhook will be retried for a maximum of 3 days before being marked as failed.

```json
{
	"type": MEDIA_FILE,
	"version":<double>,
	"payload": {
		"phone_number": <e164_format string>,
		"file_name": <string>,
		"mime_type": <string>,
		"remote_phone_id": <string>,
		"remote_waba_id": <string>,
		"chatroom_id": <string>,
		"org_id": <string>,
		"media_id": <String>
	}  
}
```

## Media Received with Classification

Version 1.0 & 1.1

```json
{
	"type": MEDIA_FILE_WITH_CLASSIFICATION,
	"version":<double>,
	"payload": {
		"phone_number": <e164_format string>,
		"file_name": <string>,
		"mime_type": <string>,
		"remote_phone_id": <string>,
		"remote_waba_id": <string>,
		"chatroom_id": <string>,
		"org_id": <string>,
		"media_id": <String>,
		"classification": {
			"suggested_labels": list<string>,
			"suggested_labels_status": <enum ACCEPTED | REJECTED>,
			"user_input_labels": list<string>
		}
	}  
}
```

## Contact Opt Out Webhook

Version 1.0 & 1.1

```json
{
    "type": CONTACT_OPT_OUT,
    "version":<double>,
    "payload": {
        "phone_number": <e164_format string>,
        "chatroom_id": <string>,
        "opt_out_ts": <timestamp>,
        "opt_out_source": {
            "type": <enum TEMPLATE_BUTTON>,
            "template_id" : <string>,
            "button_id": <string>
        }
    }
}
```

## Lead Opted Out

Version 1.0

Sent when a lead is opted out of messages. While a lead is opted out, SalesChat sends them no messages until `opted_out_until`, unless they write in or are opted in first. The payload carries the lead's ids, never their phone number.

```json
{
    "type": LEAD_OPTED_OUT,
    "version": <double>,
    "payload": {
        "event": "LEAD_OPTED_OUT",
        "lead_id": <string>,
        "crm_id": <string>,
        "opt_out": {
            "opted_out": true,
            "opted_out_at": <timestamp>,
            "opted_out_until": <timestamp>,
            "opted_out_by_type": <enum AI | USER | API | SUPPORT | SYSTEM>
        },
        "reason": <string | null>,
        "occurred_at": <timestamp>
    }
}
```

* `opted_out_by_type` says who opted the lead out: the AI agent, a user, an API caller, SalesChat support, or the system.
* `reason` is the text entered with the opt-out, if any. It is `null` for an opt-out by the AI agent.
* Timestamps are Unix epoch seconds.

## Lead Opted In

Version 1.0

Sent when an opted-out lead is opted back in: by a user, an API caller or SalesChat support, or by the lead writing in.

```json
{
    "type": LEAD_OPTED_IN,
    "version": <double>,
    "payload": {
        "event": "LEAD_OPTED_IN",
        "lead_id": <string>,
        "crm_id": <string>,
        "opt_out": {
            "opted_out": false,
            "opted_out_at": null,
            "opted_out_until": null,
            "opted_out_by_type": <enum USER | API | SUPPORT | SYSTEM>
        },
        "reason": <string | null>,
        "occurred_at": <timestamp>
    }
}
```

* `opted_out_by_type` says who opted the lead back in. `SYSTEM` means the lead wrote in.
* No webhook is sent when an opt-out ends because its window passed.

## Analytics Dump

Version 1.0 & 1.1

Note that the file format may vary based on webhook version.

For more details refer to [Metric Dumps](https://docs.saleschat.pro/application/metric-dumps.md)

```json
{
    "type": ANALYTICS_DUMP_FILE,
    "version" : <double>
    "payload": {
        "metric_type": <string>,
        "granualarity": <enum DAILY | WEEKLY>,
        "start_time": <timestamp>,
        "file_id": <string>
    }
}
```

For downloading the file use the [download signed URL API](https://docs.saleschat.pro/api-documentation/media.md) with the above obtained *file\_id*

Analytics Metric Type:

* MESSAGE\_DUMP
* AGENT\_ANALYTICS
