Userdesk
Ask or search…
K
Links
Comment on page

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

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?