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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yetanotherapi.com/uchat-webhook-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
