> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/tech/maiagent-tech-en/api-integration/webhook.md).

# Webhook

Developers need to provide an API endpoint to receive and process incoming webhook requests. After the integration party creates a message, MaiAgent will send the AI assistant's response back to this Webhook endpoint.

**Webhook Flow:**

{% @mermaid/diagram content="sequenceDiagram
participant C as Developer
participant M as MaiAgent

```
C->>M: Call MaiAgent Create Message API
M->>C: Return Receipt (without message response)
Note right of M: AI Assistant
M->>C: Webhook calls developer-provided API to notify response result (JSON format)" fullWidth="false" %}
```

**Endpoint:** `https://<your-api-domain>/maiagent/webhook` (designed by developer)

**Request Method:** `POST`

### Request Format

```json
{
    "id": "string",
    "conversation": "string",
    "sender": {
        "id": "number",
        "name": "string",
        "avatar": "string"
    },
    "type": "string",
    "content": "string",
    "feedback": "null | object",
    "created_at": "string",
    "attachments": "array",
    "citations": "array"
}
```

### Request Parameters

| Parameter     | Type           | Required | Description                               |
| ------------- | -------------- | -------- | ----------------------------------------- |
| id            | string         | Yes      | Message unique identifier (UUID format)   |
| conversation  | string         | Yes      | Conversation identifier                   |
| sender        | object         | Yes      | Sender information                        |
| sender.id     | string         | Yes      | Sender ID                                 |
| sender.name   | string         | Yes      | Sender user ID                            |
| sender.avatar | string         | Yes      | Sender avatar URL                         |
| type          | string         | Yes      | Message type (e.g., outgoing)             |
| content       | string         | Yes      | Message content                           |
| feedback      | null \| object | No       | Feedback                                  |
| createdAt     | string         | Yes      | Message creation timestamp (milliseconds) |
| attachments   | array          | Yes      | Attachments list                          |
| citations     | array          | Yes      | Referenced files list                     |

### Citations Object Parameters

| Parameter | Type   | Required | Description                            |
| --------- | ------ | -------- | -------------------------------------- |
| id        | string | Yes      | File unique identifier                 |
| filename  | string | Yes      | File name                              |
| file      | string | Yes      | File URL                               |
| fileType  | string | Yes      | File type (e.g., jsonl)                |
| size      | number | Yes      | File size (bytes)                      |
| status    | string | Yes      | File status                            |
| document  | string | Yes      | Document identifier                    |
| createdAt | string | Yes      | File creation timestamp (milliseconds) |

### Request Example

```bash
curl -X POST \\
  -H "Content-Type: application/json" \\
  -d '{
    "id": "msg123",
    "conversation": "conv456",
    "sender": {
        "id": 789,
        "name": "Test User",
        "avatar": "<https://example.com/avatar.jpg>"
    },
    "type": "outgoing",
    "content": "This is a webhook test message",
    "feedback": null,
    "created_at": "1728219442000",
    "attachments": [],
    "citations": []
  }' \\
  https://<your-api-domain>/maiagent/webhook
```

### Response Format

### Successful Response

Please return 200 to let MaiAgent know the Webhook was successful, otherwise MaiAgent's Retry Webhook mechanism will be activated

```json
{
    "message": "Webhook received successfully"
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/tech/maiagent-tech-en/api-integration/webhook.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
