# 對話與訊息回覆（串流/同步）

向 AI 助理發送訊息並取得回應。

```bash
curl -X POST \
  'https://api.maiagent.ai/api/v1/chatbots/{chatbot_id}/completions/' \
  -H 'Authorization: Api-Key YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "conversation": "string|null",
    "message": {
      "content": "string",
      "attachments": []
    },
    "is_streaming": boolean
  }'
```

**參數：**

* `chatbot_id` (路徑參數)：對話機器人 ID
* `conversation` (請求內容)：可選的對話 ID，用於延續對話
* `message.content` (請求內容)：要發送的訊息內容
* `message.attachments` (請求內容)：附件陣列（如果有的話）
* `is_streaming` (請求內容)：是否使用串流回應

**回應（非串流）：**

```json
{
  "content": "string",
  "conversationId": "string"
}
```

**回應（串流）：**

伺服器發送事件格式如下：

```
data: {
  "content": "string",
  "conversation_id": "string",
  "done": boolean
}
```

注意事項：

* 對於串流回應，伺服器會發送多個包含部分內容的事件，直到回應完成
* 回應中返回的對話 ID 可用於後續請求中延續對話

## 串接成果

{% embed url="<https://drive.google.com/file/d/1sCIoxxASZ-SnHPAmkjDT270B3dz0LyHo/view?usp=sharing>" %}


---

# 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.maiagent.ai/tech/api-integration/dui-hua-yu-xun-xi-hui-fu-chuan-liu-tong-bu.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.
