View Categories

Message a Chatbot

2 min read

The chat.smarterbot.ai API enables you to generate an AI response based on the user’s question by sending a POST request to the /chat/Chat/ClientAsk endpoint.

Endpoint #

Request URL: https://chat.smarterbot.ai/chat/Chat/ClientAsk

Method: POST

Request Headers #

The API request must include the following headers:

  • Authorization: <Your-Secret-Key> – string, required – The secret key for authenticating the API request
  • Content-Type: application/json – string, required – The content type of the request payload (must be application/json)

Request Body #

The request body should contain the following parameters:

{
// integer, required - The session ID obtained from the Create Chat Session API
"sessionID": 123,
// string, required - The question or message from the user
"content": "hello"
}
  • sessionID – integer, required – The session ID obtained from the Create Chat Session API
  • content – string, required – The question or message from the user

Example Request #

JavaScript (Fetch API) #

const res = await fetch('https://chat.smarterbot.ai/chat/Chat/ClientAsk', {
method: 'POST',
headers: {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
},
body: JSON.stringify({
"sessionID": 123,
"content": "hello"
})
});

const data = await res.json();
console.log(data);

Python (Requests Library) #

import requests
import json

url = 'https://chat.smarterbot.ai/chat/Chat/ClientAsk'
headers = {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
}
data = {
"sessionID": 123,
"content": "hello"
}

response = requests.post(url, headers=headers, json=data)
data = response.json()
print(data)

cURL #

curl 'https://chat.smarterbot.ai/chat/Chat/ClientAsk' \
-X POST \
-H 'Authorization: <Your-Secret-Key>' \
-H 'Content-Type: application/json' \
-d '{"sessionID":123,"content":"hello"}'

HTTP Request #

POST /chat/Chat/ClientAsk HTTP/1.1
Host: chat.smarterbot.ai
Authorization: <Your-Secret-Key>
Content-Type: application/json

{
"sessionID": 123,
"content": "hello"
}

Response #

The API response will be a JSON object with the following structure:

{
"Data": {
"messageid": 375561,
"content": "I'm here to help you with appointments and reservations. If you have any questions related to that, feel free to ask!",
"totalToken": 4337
},
// string - API version
"Version": "1.0.0",
// boolean - Operation success status
"Success": true,
// integer - HTTP status code
"Code": 200,
// string - Error message if any
"Message": ""
}

Error Handling #

If the request fails, you should: 1. Check the HTTP status code for network-level errors 2. Examine the `Code` and `Message` fields in the response for business-level errors 3. The `Message` field will contain detailed error information

Leave a Reply

Your email address will not be published. Required fields are marked *