Webhook 模式
Webhook 模式
GPTBots AI 代理目前支援三種訊息回應模式:blocking、streaming 及 webhook。當開發者使用 webhook 模式接收回應訊息時,無論是「AI 回應」或「人工回應」都會提交至指定的 webhook URL。
| 回應模式 | 支援的訊息類型 |
|---|---|
| blocking | AI 回應 |
| streaming | AI 回應 |
| webhook | 人工回應、AI 回應 |
請求方法
POST
Endpoint
請至 Agent - Integration - API - webhook 頁面設定您的訊息接收地址。
驗證
請參考 API 概覽 以獲取驗證說明。
請求
請求範例
curl -X POST 'YOUR_API_URL' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"create_time": 1679587005,
"conversation_id": "657303a8a764d47094874bbe",
"message_id": "65a4ccfC7ce58e728d5897e0",
"output": [
{
"from_component_branch": "1",
"from_component_name": "Component Name",
"content": {
"text": "Hi, is there anything I can help you?",
"audio": [
{
"audio": "http://gptbots.ai/example.mp3",
"transcript": "The transcribed content of the audio"
}
]
}
}
],
"usage": {
"tokens": {
"total_tokens": 29,
"prompt_tokens": 19,
"prompt_tokens_details":
{
"audio_tokens": 0,
"text_tokens": 0
},
"completion_tokens": 10,
"completion_tokens_details":
{
"reasoning_tokens": 0,
"audio_tokens": 0,
"text_tokens": 0
}
},
"credits": {
"total_credits": 0.0, //prompt + completion
"text_input_credits": 0.0,
"text_output_credits": 0.0,
"audio_input_credits": 0.0,
"audio_output_credits": 0.0
}
}
}'
curl -X POST 'YOUR_API_URL' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"create_time": 1679587005,
"conversation_id": "657303a8a764d47094874bbe",
"message_id": "65a4ccfC7ce58e728d5897e0",
"output": [
{
"from_component_branch": "1",
"from_component_name": "Component Name",
"content": {
"text": "Hi, is there anything I can help you?",
"audio": [
{
"audio": "http://gptbots.ai/example.mp3",
"transcript": "The transcribed content of the audio"
}
]
}
}
],
"usage": {
"tokens": {
"total_tokens": 29,
"prompt_tokens": 19,
"prompt_tokens_details":
{
"audio_tokens": 0,
"text_tokens": 0
},
"completion_tokens": 10,
"completion_tokens_details":
{
"reasoning_tokens": 0,
"audio_tokens": 0,
"text_tokens": 0
}
},
"credits": {
"total_credits": 0.0, //prompt + completion
"text_input_credits": 0.0,
"text_output_credits": 0.0,
"audio_input_credits": 0.0,
"audio_output_credits": 0.0
}
}
}'
此代碼塊在浮窗中顯示
請求標頭
| 欄位 | 類型 | 描述 |
|---|---|---|
| Authorization | Bearer 或 Basic ${token} | 如果啟用了驗證,請使用 Authorization: Bearer 或 Basic ${token} 進行呼叫驗證。若未啟用驗證則為可選。 |
| Content-Type | application/json | 資料類型,設為 application/json。 |
請求主體
層級符號(%%、%%% 等)用於標示 JSON 結構層級,便於閱讀。
| 欄位 | 類型 | 描述 |
|---|---|---|
| conversation_id | string | 對話的唯一識別碼。 |
| message_id | string | 對話中某條訊息的唯一識別碼。 |
| create_time | long | 訊息生成的時間戳。 |
| output | JSON 陣列 | AI 代理回應內容。 |
| from_component_branch | string | FlowAgent 分支。 |
| from_component_name | string | FlowAgent 中的上游元件名稱。 |
| content | object | AI 代理回應訊息內容,目前包含 text(文字)和 audio(音訊)訊息類型。 |
| usage | object | 使用量消耗。 |
| tokens | JSON 陣列 | 該對話中 AI 代理消耗的總 token 數量。 |
| total_tokens | integer | 該對話中輸入 + 輸出的總 token 數量。 |
| prompt_tokens | integer | 該對話中輸入消耗的 token 總數。 |
| completion_tokens | integer | 該對話中輸出消耗的 token 總數。 |
| prompt_tokens_details | object | 該對話中輸入消耗的 token 詳情。 |
| completion_tokens_details | object | 該對話中輸出消耗的 token 詳情。 |
| credits | object | 該對話中 AI 代理消耗的總點數。 |
| text_input_credits | double | 該對話中輸入文字訊息消耗的點數。 |
| text_output_credits | double | 該對話中輸出文字訊息消耗的點數。 |
| audio_input_credits | double | 該對話中輸入音訊訊息消耗的點數。 |
| audio_output_credits | double | 該對話中輸出音訊訊息消耗的點數。 |
回應
回應範例
{
"code": 200, // 狀態碼
"msg": "success" // 狀態訊息
}
{
"code": 200, // 狀態碼
"msg": "success" // 狀態訊息
}
此代碼塊在浮窗中顯示
