logo
开发者文档
搜索
Webhook 模式

Webhook 模式

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

响应模式 该模式所支持的消息回复类型
blocking Agent回复消息
streaming Agent回复消息
webhook 人工客服回复消息、Agent回复消息

发送消息 API 响应消息到 webhook

请求方式

POST

调用地址

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

鉴权方式

支持 Basic鉴权和 Bearer 鉴权两种方式,开发者可根据自身情况选择合适的鉴权方式,并在 Agent - 集成 - API - webhook 页面进行配置。

  • 当集成webhook地址时,开发者如果只填写webhook 用户名,那么 GPTBots 向开发者 webhook URL 发起请求时,会默认使用 Bearer 鉴权方式,值为开发者填写的webhook用户名
  • 当集成webhook地址时,开发者如果填写webhook用户名webhook秘钥,那么 GPTBots 向开发者 webhook URL 发起请求时,会使用 basic 鉴权方式,用户名为开发者填写的webhook用户名,密码为开发者填写的webhook秘钥

请求示例

curl -X POST 'YOUR_API_URL' \ -H 'Authorization: Bearer ${API Key}' \ -H 'Content-Type: application/json' \ -d '{ "istest": false, "create_time": 1679587005, "user_id": "65a4ccfc7ce58e728d5897e0", "anonymous_id": "device_abcdef123456", "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 '{
    "istest": false,
    "create_time": 1679587005,
    "user_id": "65a4ccfc7ce58e728d5897e0",
    "anonymous_id": "device_abcdef123456",
    "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
        }
    }
}'

                    
此代码块在浮窗中显示

请求参数

字段 类型 描述
istest boolean 是否为 webhook 可用性检测请求。true=检测/测试请求,开发者不应作为真实业务处理false=真实业务请求(默认)。
user_id string 开发者绑定的用户 ID,未绑定用户时为 null。
anonymous_id string 匿名用户(设备)ID。
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 所消耗的积分。

响应规范

当开发者的 webhook 服务成功接收到消息后,需返回 HTTP 状态码 200,且响应体返回 JSON 格式的成功标识。

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

                    
此代码块在浮窗中显示