AI Chatbot Hub
HomepageAPI docsDiscordLog inSign up
API docs
API docs
  • API usage guides
    • Getting an API key
    • Create a chatbot
    • Chat with chatbot
    • Uploading data sources
  • Chatbots
    • Chatbot properties
    • Create chatbot
    • Update chatbot
    • Fetch a chatbot
    • Fetch all chatbots
    • Delete chatbot
  • Agents
    • Agent properties
    • Create agent
    • Update agent
    • Fetch all agents
    • Delete agent
  • Chatbot sessions
    • Session properties
    • Create session
    • Fetch a session
    • Fetch all sessions
    • Delete session
  • Session messages
    • Message properties
    • Create message
    • Fetch all messages
    • Delete message
    • Delete multiple messages
  • Data sources
    • Source properties
    • Upload a file
    • Create QA source
    • Create URL source
    • Update source
    • Fetch list of sources
    • Retrain sources
    • Delete source
    • Delete multiple sources
  • Data source tags
    • Create source tag
    • Fetch all source tags
    • Update source tag
    • Delete source tag
Powered by GitBook
On this page
  • Prerequisites
  • Creating a Chat Session
  • Chatting Within a Session
  1. API usage guides

Chat with chatbot

How to start chatting with your chatbot using the AI Chatbot Hub API

Before beginning, please make sure you meet the following prerequisites.

Prerequisites

  • An API key to access the AI Chatbot Hub API.

  • A development environment or tool for making HTTP requests, like Curl or a programming language such as Python.

To chat on specific topics, your chatbot needs relevant data sources uploaded.

Creating a Chat Session

Why Create a Chat Session?

Before you can send messages to the chatbot, it’s essential to create a chat session. A chat session acts as a container that organizes all messages exchanged between you and the chatbot. Here’s why this is important:

  • Message Context: A chat session preserves the conversation’s context, ensuring that the chatbot understands the flow of your questions or statements.

  • Order of Messages: The chat session maintains the sequence of messages, allowing for meaningful and coherent exchanges.

  • State Management: By referencing the session UUID, you can seamlessly continue a conversation, effectively managing the chat's state.

How to Create a Chat Session

To create a chat session, send a POST request to the following API endpoint: https://app.aichatbothub.com/api/v1/chatbot/{chatbot_uuid}/session/create

Make sure to replace {chatbot_uuid} with your specific chatbot's UUID.

Example Request

Here’s an example command for creating a chatbot session using the AI Chatbot Hub API. Replace <token> with your actual API key.

curl --location --request POST 'https://app.aichatbothub.com/api/v1/chatbot/{chatbot_uuid}/session/create' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
import requests

url = 'https://app.aichatbothub.com/api/v1/chatbot/{chatbot_uuid}/session/create'
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <token>'
}


response = requests.post(url,  headers=headers, params=params)

if response.status_code == 200:
    print("Request successful!")
    print(response.json())
else:
    print("Request failed with status code:", response.status_code)
    print(response.text)
const axios = require("axios");

const url =
  "https://app.aichatbothub.com/api/v1/chatbot/{chatbot_uuid}/session/create";
const headers = {
  "Content-Type": "application/json",
  Authorization: "Bearer <token>",
};

axios
  .post(url, { headers, params })
  .then((response) => {
    console.log("Request successful!");
    console.log(response.data);
  })
  .catch((error) => {
    console.error("Request failed:", error);
  });

This API request returns JSON data that can be used for sending messages:

{
  "created_at": "string",
  "modified_at": "string",
  "uuid": "string"
}

The uuid from this response is essential for sending messages within the established chat session and will be used in the next steps.

Chatting Within a Session

Sending Messages

With a chat session created, you can now send messages to your chatbot. Use the following API endpoint to send messages and receive a streamed AI response: https://app.aichatbothub.com/api/v1/session/{session_uuid}/message/stream

Replace {session_uuid} with the UUID from the chat session creation response.

Example Request

Below is an example command for sending a message using the AI Chatbot Hub API. Replace <token> with your actual API key.

curl --location --request POST 'https://app.aichatbothub.com/api/v1/session/{session_uuid}/message/stream' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--data-raw '{"query": "Your query goes here"}'
import requests

url = f"https://app.aichatbothub.com/api/v1/session/{session_uuid}/message/stream"
headers = {
    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
    "Content-Type": "application/json"
}

data = {
    "query": "Your query goes here"
}

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

if response.status_code == 200:
    for line in response.iter_lines(decode_unicode=True):
        # Process streaming response here
        print(line)
else:
    print("Error:", response.status_code)
const xhr = new XMLHttpRequest();
xhr.open(
  "POST",
  `https://app.aichatbothub.com/api/v1/session/{session_uuid}/message/stream`,
  true
);

xhr.setRequestHeader("Authorization", "Bearer YOUR_ACCESS_TOKEN");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

const data = JSON.stringify({ query: "Your query goes here" });

xhr.send(data);

xhr.onprogress = () => {
  const streamingResponse = xhr.responseText;
  console.log(streamingResponse);
};

xhr.onreadystatechange = () => {
  if (xhr.readyState === 4) {
    if (xhr.status === 200) {
      console.log("Streaming completed successfully");
    } else {
      console.error("Error:", xhr.status);
    }
  }
};

That’s it! You’ve now learned how to start a conversation with your chatbot using the AI Chatbot Hub API.

PreviousCreate a chatbotNextUploading data sources

Last updated 6 months ago