Send a message
Send a message to your Chatbot and get an AI generated response
This endpoint allows you to send a message to your Chatbot, if you haven’t started a conversation one will be created, and the conversationId
will be returned.
POST
https://api.userdesk.io/v1/chatbot/<chatbot_id>/message
The fields marked with *
are mandatory
Headers
Authorization*
String
Bearer <your_chatbot_api_key>
Request Body
message*
String
Your message for the Chatbot
stream
Boolean
Enable streaming response
conversationId
String
Conversation id
userName
String
Name of the user
userEmail
String
Email of the user
{
"success": true,
"conversationId": "ea74ba3d-6645-4a88-92d1-7f78b1f83688",
"response": "The average distance from the Earth to the Moon is about 238,855 miles (384,400 kilometers)."
}
Continue a conversation
If the field conversationId
is set to true
in the request body, the message will be added to the same conversation.
Streaming responses
If the field stream
is set to true
in the request body, the response will be streamed returning partial message deltas.
This allows the implementation of the ChatGPT-like experience, in which the response from the Chatbot is shown progressively. This usually provides a better user experience, as they don't have to wait until the full response is provided.
This is an example of NodeJS code to use the streaming response:
const response = await fetch("https://api.userdesk.io/v1/chatbot/123456/message", {
headers: {
Authorization: "Bearer 1234567890",
}
});
// Stream response
if (!response.body) throw new Error("No response body");
const reader = response.body.getReader();
let message = ""
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = new TextDecoder("utf-8").decode(value);
message += text;
// progressive message
console.log(message)
}
// message complete
Interested in Userdesk?
Last updated
Was this helpful?