> For the complete documentation index, see [llms.txt](https://docs.yetanotherapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yetanotherapi.com/uchat-webhook-system.md).

# UChat Webhook System

### Overview

The Bot Webhook API provides functionality to manage user interactions in a messaging system, including user creation, field updates, and flow management. This API integrates with uChat's backend API services.

**Important Notes:**

* This API is FREE and will continue to remain free.
* **IMPORTANT**: Authentication process will be updated in future releases.
* Currently works best for whatsapp bots. We plan to expend this to support multiple channels.
* For support contact: <hey@manojlk.work>

Endpoint URL: `https://api.yetanotherapi.com/bot-webhook`

### Authentication

All API requests require Bearer token authentication.

```http
Authorization: Bearer <your_api_token>
```

Your API token can be obtained from the UChat account settings.

### Endpoints

#### Send Bot Webhook

`POST /bot-webhook`

Handles user management and flow distribution in the messaging system.

**Request**

**Headers:**

* `Content-Type: application/json` (Required)
* `Authorization: Bearer <token>` (Required)

**Body Parameters:**

```json
{
    "phone_number": string,     // Required: User's phone number
    "flow_ns": string,         // Required: Flow namespace identifier
    "user_fields": {           // Optional: Custom user fields
        "field_name": "value"
    }
}
```

**Response**

**Success Response (200 OK)**

```json
{
    "user_ns_retrieval": {
        "success": true,
        "message": string,
        "user_ns": string
    },
    "custom_fields_update": {
        "success": true,
        "message": string,
        "details": [
            {
                "field": string,
                "status": string
            }
        ]
    },
    "flow_sent": {
        "success": true,
        "message": string
    },
    "request_id": string
}
```

**Partial Success Response (206 Partial Content)** Returned when some operations succeed but others fail.

**Error Responses:**

* `400 Bad Request`: Missing required fields or invalid JSON
* `404 Not Found`: User not found and creation failed
* `500 Internal Server Error`: Server-side error

Each response includes a unique `request_id` in both the response body and header (`X-Request-ID`).

**Example Request**

```bash
curl --location 'https://api.yetanotherapi.com/bot-webhook' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your_token>' \
--data '{
    "phone_number": "917406796004",
    "flow_ns": "f105713s755621",
    "user_fields": {
        "scheme_name": "test",
        "transaction_code": "test"
    }
}'
```

### Error Handling

The API implements a robust error handling system with:

* Input validation
* Retry mechanism (max 3 retries) for user retrieval
* Detailed error messages in responses
* Comprehensive error logging

### Logging and Monitoring

All API interactions are logged with:

* Request details
* API call traces
* Execution timestamps
* Response data
* Error information

Each request can be tracked using its unique `request_id`.

### Support

For any queries or support, please contact: <hey@manojlk.work>
