Send Message
Last updated:2024-12-22
Send Message
Send a message to the specified conversation ID and get the agent response message. Supports submitting text and/or images as message content .
Request Method
POST
Request URL
https://api.gptbots.ai/v1/conversation/message
Request Authentication
See Overview for authentication details.
Request
Example Request
curl -X POST https://api.gptbots.ai/v1/conversation/message \
-H 'Authorization: Bearer your_apikey' \
-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.gptbots.ai/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.gptbots.ai/v1/conversation/message \
-H 'Authorization: Bearer your_apikey' \
-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.gptbots.ai/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"
]
}
}
}'
This code block in the floating window
Field | Type | Description |
---|---|---|
Authorization | Bearer ${token} | Use Authorization: Bearer ${token} for authentication. Get the key from the API Keys page as token. |
Content-Type | application/json | Data type, set to application/json. |
Request Body
Field | Type | Required | Description |
---|---|---|---|
text | string | Yes | Either text or files must be entered. The user's text message, the length of the text content cannot exceed the token length limit set by the Agent configuration. |
files | JSON Array | No | text and files must have at least one input. Files are used to submit images, audio, and document-type data to the Agent. The Agent supports two file recognition schemes: "System File Recognition" and "LLM File Recognition." Different recognition schemes support different file types. Network paths for file submission are supported, with a maximum of 9 files uploaded. Documents ≤20MB, images ≤10MB, audio ≤5MB. LLM File Recognition |
conversation_id | string | Yes | Conversation ID, pass in to continue previous conversation. |
response_mode | string | Yes | blocking: |
short_term_memory | boolean | No | Does this message send carry short-term memory within the conversation as context? If not filled out, follow the memory settings of the Agent. |
long_term_memory | boolean | No | Does this message send carry long-term memory within the conversation as context? If not filled out, follow the memory settings of the Agent. |
knowledge | object | No | Customize the knowledge retrieval scope for this message. If this field does not exist, the default knowledge configuration of the Agent will be used for retrieval. |
data_ids | array | No | data_ids is an array of knowledge document IDs. If this parameter is an empty array, such as "data_ids": [] , it is considered as not retrieving any knowledge documents. If this parameter has values, retrieval will be limited to the specified knowledge document ID range. |
Response
Example Response
{
"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"
}
This code block in the floating window
Success Response (Blocking)
Field | Type | Description |
---|---|---|
message_id | string | Unique message ID. |
message_type | string | Message type, value: ANSWER, QUESTION. |
text | string | Reply text. |
flow_output | JSON Array | flow agent reply content. |
content | string | flow agent component reply text. |
branch | string | flow agent branch. |
from_component_name | string | flow agent upstream component name. |
create_time | long | Timestamp when reply message was created. |
conversation_id | string | Conversation ID. |
Success Response (Streaming)
Field | Type | Description |
---|---|---|
code | int | Message type code, 3-Text, 10-FlowOutput, 0-End. |
message | string | Message type, value: Text, FlowOutput, End. |
data | object | Reply content. |
Streaming data is returned in multiple chunks:
{"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":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}
This code block in the floating window
Success Response(webhook)
Field | Type | Description |
---|---|---|
message_id | string | Unique message ID. |
message_type | string | Message type, value: ANSWER, QUESTION. |
create_time | long | Timestamp when reply message was created. |
conversation_id | string | Conversation ID. |
Failure Response
Field | Type | Description |
---|---|---|
code | int | Error code. |
message | string | Error details. |
When developers have configured the webhook address, after a successful response, the GPTBots system sends messages from both the Agent and human customer support to the webhook address. For detailed message formats, please refer to Webhook Message Reception.
Error Codes
Code | Message |
---|---|
40000 | Invalid parameter |
40127 | Developer authentication failed |
40356 | Conversation does not exist |
50000 | Internal server error |
40364 | This Agent does not use an LLM that supports image mode |
20059 | Agent deleted |
20040 | Exceeded question limit |
40358 | conversation_id does not match agent or user |
20022 | Credit not enough |