Start Chatting with Chatbot #
In this section, we will guide you on how to start chatting with your chatbot using the Chatsistant API. Before you begin, please ensure you meet the following prerequisites:
Prerequisites #
- An API key for accessing the Chatsistant API.
- A development environment or tool for making HTTP requests, such as Curl or a programming language like Python.
Why Create a Chat Session? #
Before sending messages to the chatbot, it’s essential to create a chat session. A chat session acts as a container that holds all the messages exchanged between you and the chatbot. Here’s why creating a chat session is necessary:
- Message Context: A chat session allows you to maintain context throughout a conversation. It ensures that the chatbot understands the context of your questions or statements.
- Order of Messages: The chat session helps in maintaining the order of messages. This is crucial for having meaningful and coherent conversations with the chatbot.
- State Management: The chat session allows you to manage the state of the conversation. You can continue a conversation seamlessly by referencing the session UUID.
Create a Chat Session #
To create a chat session, you need to use a POST request to the API endpoint: https://app.chatsistant.com/api/v1/chatbot/{uuid}/session/create
. Make sure to replace {uuid}
with the UUID of your chatbot.
Example Request #
Here’re example commands to create a chat session using the Chatsistant API:
Curl #
curl --location --request POST 'https://app.chatsistant.com/api/v1/chatbot/{uuid}/session/create' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>'
Python #
import requests
url = 'https://app.chatsistant.com/api/v1/chatbot/{uuid}/session/create'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <token>'
}
response = requests.post(url, headers=headers)
if response.status_code == 200:
print("Request successful!")
print(response.json())
else:
print("Request failed with status code:", response.status_code)
print(response.text)
JavaScript (Axios) #
const axios = require('axios');
const url = 'https://app.chatsistant.com/api/v1/chatbot/{uuid}/session/create';
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <token>'
};
axios.post(url, { headers })
.then(response => {
console.log('Request successful!');
console.log(response.data);
})
.catch(error => {
console.error('Request failed:', error);
});
Send Messages #
Now that you’ve created a chat session, you can send messages to your chatbot. Use the following API endpoint to send messages: https://app.chatsistant.com/api/v1/session/{uuid}/message/stream
. Make sure to replace {uuid}
with the UUID of the created session.
Example Request #
Curl #
curl --location --request POST 'https://app.chatsistant.com/api/v1/session/{uuid}/message/stream' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--data-raw '{"query": "Your query goes here"}'
Python #
import requests
url = 'https://app.chatsistant.com/api/v1/session/{uuid}/message/stream'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
data = {
'query': 'Your query goes here'
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
print("Message sent successfully!")
print(response.json())
else:
print("Failed to send message. Status code:", response.status_code)
print(response.text)
JavaScript (Axios) #
const axios = require('axios');
const url = 'https://app.chatsistant.com/api/v1/session/{uuid}/message/stream';
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
};
const data = {
query: 'Your query goes here'
};
axios.post(url, data, { headers })
.then(response => {
console.log('Message sent successfully!');
console.log(response.data);
})
.catch(error => {
console.error('Failed to send message:', error);
});
That’s it! You’ve now learned how to chat with your own chatbot using the Chatsistant API.