ส่งข้อความ
ส่งข้อความ
ส่งข้อความไปยัง Conversation ID ที่ระบุและรับข้อความตอบกลับจาก Agent รองรับการส่งข้อความทั้งแบบข้อความและ/หรือรูปภาพเป็นเนื้อหาข้อความ
วิธีการร้องขอ
POST
URL สำหรับร้องขอ
https://api-${endpoint}.gptbots.ai/v1/conversation/message
การยืนยันตัวตนในการร้องขอ
ดูรายละเอียดการยืนยันตัวตนใน Overview
การร้องขอ
ตัวอย่างการร้องขอ
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/conversation/message' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"text": "HI!",
"conversation_id": "xxxxxx",
"response_mode": "streaming",
"short_term_memory": true,
"long_term_memory": false,
"files":[
{
"url": "https://res.srcgptbots.com/ailab/botchat/file/38f13465ad5246190b759b3289ecba51.jpg",
"name": "something.jpg",
"width": 200,
"height": 200
},
{
"base64_content": "Your_file_base64_content",
"name": "something.pdf"
}
],
"knowledge": {
"data_ids": [
"48c70da0403cc812641b934f",
"48c70da0403cc812641df35k"
]
}
}'
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/conversation/message' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"text": "HI!",
"conversation_id": "xxxxxx",
"response_mode": "streaming",
"short_term_memory": true,
"long_term_memory": false,
"files":[
{
"url": "https://res.srcgptbots.com/ailab/botchat/file/38f13465ad5246190b759b3289ecba51.jpg",
"name": "something.jpg",
"width": 200,
"height": 200
},
{
"base64_content": "Your_file_base64_content",
"name": "something.pdf"
}
],
"knowledge": {
"data_ids": [
"48c70da0403cc812641b934f",
"48c70da0403cc812641df35k"
]
}
}'
บล็อกโค้ดนี้ในหน้าต่างลอย
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
| Authorization | Bearer ${token} | ใช้ Authorization: Bearer ${token} สำหรับการยืนยันตัวตน รับคีย์จากหน้า API Keys เพื่อใช้เป็น token |
| Content-Type | application/json | ประเภทข้อมูล กำหนดเป็น application/json |
Request Body
| ฟิลด์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
| text | string | ใช่ | ต้องกรอกอย่างน้อย text หรือ files ข้อความของผู้ใช้ ความยาวข้อความต้องไม่เกินขีดจำกัด token ที่กำหนดโดย Agent |
| files | JSON Array | ไม่ | ต้องมี input อย่างน้อย 1 รายการระหว่าง text และ files ใช้สำหรับส่งรูปภาพ, เสียง และไฟล์เอกสารให้กับ Agent โดย Agent รองรับ 2 รูปแบบการรู้จำไฟล์: "System File Recognition" และ "LLM File Recognition" ซึ่งแต่ละแบบรองรับไฟล์ต่างกัน รองรับการส่งไฟล์ผ่าน URL สูงสุด 9 ไฟล์ เอกสาร ≤20MB, รูปภาพ ≤10MB, เสียง ≤5MB LLM File Recognition |
| conversation_id | string | ใช่ | Conversation ID สำหรับสนทนาต่อเนื่อง |
| response_mode | string | ใช่ | blocking: |
| short_term_memory | boolean | ไม่ | ข้อความนี้จะนำ short-term memory ของการสนทนาไปใช้เป็น context หรือไม่ หากไม่ระบุจะใช้ตามการตั้งค่าของ Agent |
| long_term_memory | boolean | ไม่ | ข้อความนี้จะนำ long-term memory ของการสนทนาไปใช้เป็น context หรือไม่ หากไม่ระบุจะใช้ตามการตั้งค่าของ Agent |
| knowledge | object | ไม่ | กำหนดขอบเขตการดึงข้อมูลความรู้สำหรับข้อความนี้ หากไม่ระบุจะใช้การตั้งค่าความรู้ของ Agent ตามปกติ |
| data_ids | array | ไม่ | data_ids คือ array ของ Knowledge Document ID หากเป็น array ว่าง เช่น "data_ids": [] หมายถึงไม่ดึงข้อมูลความรู้ใด ๆ หากมีค่า จะดึงเฉพาะ ID ที่ระบุเท่านั้น |
การตอบกลับ
ตัวอย่างการตอบกลับ
{
"message_id": "65a4ccfC7ce58e728d5897e0",
"message_type": "ANSWER",
"text": "Hi, is there anything I can help you?",
"flow_output": [
{
"content": "Hello",
"branch": "1",
"from_component_name": "User Input"
}
],
"create_time": 1679587005,
"conversation_id": "657303a8a764d47094874bbe"
}
{
"message_id": "65a4ccfC7ce58e728d5897e0",
"message_type": "ANSWER",
"text": "Hi, is there anything I can help you?",
"flow_output": [
{
"content": "Hello",
"branch": "1",
"from_component_name": "User Input"
}
],
"create_time": 1679587005,
"conversation_id": "657303a8a764d47094874bbe"
}
บล็อกโค้ดนี้ในหน้าต่างลอย
การตอบกลับสำเร็จ (Blocking)
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
| message_id | string | รหัสข้อความที่ไม่ซ้ำกัน |
| message_type | string | ประเภทข้อความ: ANSWER, QUESTION |
| text | string | ข้อความตอบกลับ |
| flow_output | JSON Array | เนื้อหาตอบกลับของ flow agent |
| content | string | ข้อความตอบกลับของ flow agent component |
| branch | string | สาขาของ flow agent |
| from_component_name | string | ชื่อ component ต้นทางของ flow agent |
| create_time | long | เวลาสร้างข้อความตอบกลับ (timestamp) |
| conversation_id | string | Conversation ID |
การตอบกลับสำเร็จ (Streaming)
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
| code | int | รหัสประเภทข้อความ: 3-Text, 10-FlowOutput, 0-End |
| message | string | ประเภทข้อความ: Text, FlowOutput, End |
| data | object | เนื้อหาตอบกลับ |
ข้อมูลแบบ Streaming จะถูกส่งกลับเป็นชุดข้อมูลย่อยหลายชุด:
{"code":11,"message":"MessageInfo","data":{"message_id":"6785dba0f06d872bff9ee347"}}
{"code":3,"message":"Text","data":"I"}
{"code":3,"message":"Text","data":"can"}
{"code":3,"message":"Text","data":"help"}
{"code":3,"message":"Text","data":"you"}
{"code":3,"message":"Text","data":"?"}
{"code":10,"message":"FlowOutput","data":[{"content":"Hello","branch":null,"from_component_name":"User Input"}]}
{"code":0,"message":"End","data":null}
{"code":11,"message":"MessageInfo","data":{"message_id":"6785dba0f06d872bff9ee347"}}
{"code":3,"message":"Text","data":"I"}
{"code":3,"message":"Text","data":"can"}
{"code":3,"message":"Text","data":"help"}
{"code":3,"message":"Text","data":"you"}
{"code":3,"message":"Text","data":"?"}
{"code":10,"message":"FlowOutput","data":[{"content":"Hello","branch":null,"from_component_name":"User Input"}]}
{"code":0,"message":"End","data":null}
บล็อกโค้ดนี้ในหน้าต่างลอย
การตอบกลับสำเร็จ (webhook)
เมื่อผู้พัฒนาตั้งค่า webhook ไว้ ระบบ GPTBots จะส่งข้อความจาก Agent และเจ้าหน้าที่ไปยัง webhook ที่ตั้งค่าไว้ สามารถดูรูปแบบข้อความโดยละเอียดได้ที่ Webhook Mode
การตอบกลับล้มเหลว
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
| code | int | รหัสข้อผิดพลาด |
| message | string | รายละเอียดข้อผิดพลาด |
รหัสข้อผิดพลาด
| รหัส | ข้อความ |
|---|---|
| 40000 | พารามิเตอร์ไม่ถูกต้อง |
| 40127 | การยืนยันตัวตนของผู้พัฒนาไม่สำเร็จ |
| 40356 | ไม่พบการสนทนา |
| 50000 | ข้อผิดพลาดภายในเซิร์ฟเวอร์ |
| 40364 | Agent นี้ไม่รองรับโหมดภาพ |
| 20059 | Agent ถูกลบแล้ว |
| 20040 | เกินขีดจำกัดการถามคำถาม |
| 40358 | conversation_id ไม่ตรงกับ agent หรือผู้ใช้ |
| 20022 | เครดิตไม่เพียงพอ |
