โหมด Webhook

โหมด Webhook

ขณะนี้ GPTBots Agent รองรับโหมดการตอบกลับข้อความ 3 แบบ ได้แก่ blocking, streaming และ webhook เมื่อนักพัฒนาเลือกใช้โหมด webhook เพื่อรับข้อความตอบกลับ ทั้ง AI responses และ human responses จะถูกส่งไปยัง URL webhook ที่กำหนดไว้

โหมดการตอบกลับ ประเภทข้อความที่รองรับ
blocking AI responses
streaming AI responses
webhook Human responses, AI responses

วิธีการร้องขอ

POST

Endpoint

โปรดกำหนด URL สำหรับรับข้อความของคุณในหน้า Agent - Integration - API - webhook

การตรวจสอบสิทธิ์

ดูรายละเอียดวิธีตรวจสอบสิทธิ์ได้ที่ API Overview

ตัวอย่างการร้องขอ

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
        }
    }
}'

                    
บล็อกโค้ดนี้ในหน้าต่างลอย

Request Headers

ฟิลด์ ประเภท คำอธิบาย
Authorization Bearer หรือ Basic ${token} หากเปิดใช้งานการตรวจสอบสิทธิ์ ให้ใช้ Authorization: Bearer หรือ Basic ${token} สำหรับยืนยันการเรียกใช้งาน หากไม่ได้เปิดใช้งาน สามารถข้ามได้
Content-Type application/json ประเภทข้อมูล ให้ตั้งค่าเป็น application/json

Request Body

ฟิลด์ ประเภท คำอธิบาย
conversation_id string รหัสเฉพาะของการสนทนา
message_id string รหัสเฉพาะของข้อความแต่ละรายการในบทสนทนา
create_time long เวลาที่สร้างข้อความ (timestamp)
output JSON Array เนื้อหาการตอบกลับของ AI Agent
from_component_branch string สาขาของ FlowAgent
from_component_name string ชื่อคอมโพเนนต์ต้นทางใน FlowAgent
content object เนื้อหาข้อความตอบกลับของ AI Agent รองรับทั้ง text และ audio
usage object ข้อมูลการใช้งานและการบริโภคทรัพยากร
tokens JSON Array จำนวนโทเคนที่ Agent ใช้ในบทสนทนานี้ทั้งหมด
total_tokens integer จำนวนโทเคนที่ใช้สำหรับ input + output ในบทสนทนานี้ทั้งหมด
prompt_tokens integer จำนวนโทเคนที่ใช้สำหรับ input ในบทสนทนานี้ทั้งหมด
completion_tokens integer จำนวนโทเคนที่ใช้สำหรับ output ในบทสนทนานี้ทั้งหมด
prompt_tokens_details object รายละเอียดโทเคนที่ใช้สำหรับ input
completion_tokens_details object รายละเอียดโทเคนที่ใช้สำหรับ output
credits object เครดิตที่ Agent ใช้ในบทสนทนานี้ทั้งหมด
text_input_credits double เครดิตที่ใช้สำหรับข้อความ input
text_output__credits double เครดิตที่ใช้สำหรับข้อความ output
audio_input_credits double เครดิตที่ใช้สำหรับข้อความเสียง input
audio_output_credits double เครดิตที่ใช้สำหรับข้อความเสียง output

การตอบกลับ

ตัวอย่างการตอบกลับ

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

                    
บล็อกโค้ดนี้ในหน้าต่างลอย