Webhook 模式
最新更新:2025-03-19

Webhook 模式

当前 GPTBots Agent 的消息响应模式支持:blocking,streamingwebhook三种方式。当开发者使用 webhook 模式 接收响应消息时, 会将Agent 或 人工客服所回复的消息内容提交到指定的 webhook 地址。

请求方式

POST

调用地址

请在 Agent - 集成 - API - webhook 页面配置你的消息接收地址

调用验证

详情参见 API 概述的鉴权方式说明。

请求

请求示例

curl -X POST YOUR_API \ -H 'Authorization: Bearer your_apikey' \ -H 'Content-Type: application/json' \ -d '{ "create_time": 1679587005, "conversation_id": "657303a8a764d47094874bbe", "message_id": "65a4ccfC7ce58e728d5897e0", "output": [ { "from_component_branch": "1", "from_component_name": "组件名称", "content": { "text": "Hi, is there anything I can help you?", "audio": [ { "audio": "http://gptbots.ai/example.mp3", "transcript": "音频所转录的文字内容" } ] } } ], "usage": { "tokens": { "total_tokens": 29, //prompt + completion "prompt_tokens": 19, //prompt "prompt_tokens_details": { "audio_tokens": 0, "text_tokens":0 }, "completion_tokens": 10, //completion "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 \ 
  -H 'Authorization: Bearer your_apikey' \ 
  -H 'Content-Type: application/json' \ 
  -d '{
    "create_time": 1679587005,
    "conversation_id": "657303a8a764d47094874bbe",
    "message_id": "65a4ccfC7ce58e728d5897e0",
    "output": [
        {
            "from_component_branch": "1",
            "from_component_name": "组件名称",
            "content": {
                "text": "Hi, is there anything I can help you?",
                "audio": [
                    {
                        "audio": "http://gptbots.ai/example.mp3",
                        "transcript": "音频所转录的文字内容"
                    }
                ]
            }
        }
    ],
    "usage": {
        "tokens": {
           "total_tokens": 29,  //prompt + completion
            "prompt_tokens": 19, //prompt
            "prompt_tokens_details": {  
                "audio_tokens": 0,
                "text_tokens":0
            },
            "completion_tokens": 10, //completion
            "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 or Basic ${token} 使用 Authorization: Bearer OR Basic ${token}进行调用验证,请在 API 密钥页面获取密钥作为 token。
Content-Type application/json 数据类型,取值为 application/json。

请求体

字段 类型 描述
conversation_id string 对话的唯一标识符
message_id string 一条对话中,某条消息的唯一标识符。
create_time long 回复的这条消息产生的时间戳。
output JSON Array AI Agent 回复内容。
from_component_branch string FlowAgent 分支。
from_component_name string FlowAgent 上游组件名称。
content object AI Agent回复的消息内容,当前包含了textaudio 2 个类型的消息。
usage object 使用消耗。
tokens JSON Array 本次对话该 Agent 所消耗的总 tokens。
total_tokens integer 本次对话 input + output 所消耗的总 tokens。
prompt_tokens integer 本次对话 input 所消耗的总 tokens。
completion_tokens integer 本次对话 output 所消耗的总 tokens。
prompt_tokens_details object 本次对话 input Token 消耗明细。
completion_tokens_details object 本次对话 output Token 消耗明细。
credits object 本次对话该 Agent 所消耗的总积分。。
text_input_credits double 本次对话 input text message 所消耗的积分。
text_output__credits double 本次对话 output text message 所消耗的积分。
audio_input_credits double 本次对话 input audio message 所消耗的积分。
audio_output_credits double 本次对话 input audio message 所消耗的积分。

响应

响应示例

{ "code": 200, "msg": "success" }
          {
  "code": 200,
  "msg": "success"
}

        
此代码块在浮窗中显示