About Selanim Chat Bot API

The Selanim Chat Bot API is a powerful, AI-driven solution designed to enhance your business with intelligent, adaptive chatbot capabilities. Our API allows seamless integration into your applications, enabling your bot to learn user behavior, adapt from interactions, and be customized to meet your specific business needs. Whether you're building for a single application or scaling to multiple platforms, Selanim provides flexible pricing and robust features to empower your customer engagement.

Pricing Plans

Selanim Chat Bot API is a paid service with the following packages:

Package Price (TZS) Duration Description
Free Trial 0 1 Month Try our API for free for one month
Single Application TZS: 100,000/= 1 Year Access for one application
10 Applications TZS: 500,000/= 1 Year Access for up to 10 applications
Unlimited Applications TZS: 1,000,000/= 1 Year Unlimited application access

Features: Our bot learns user behavior, adapts from interactions, and can be trained based on your business needs.

Contact Us

Reach out to us for support, inquiries, or to learn more about integrating the Selanim Chat Bot API into your business.

API Endpoints

POST /chat

Chat with the bot for a specific application. Send a message and receive the bot's response.

Request

Parameter Type Required Description
message string Yes The message to send to the chatbot
session_id string No Unique session identifier for maintaining conversation context

Response

{
    "status": "success",
    "user_message": "Hello",
    "bot_response": "Hi there! How can I help you?",
    "session_id": "abc123xyz"
}
POST /teach

Teach the bot a new response for a specific application. This helps customize the bot's knowledge base.

Request Body

Field Type Required Description
question string Yes The question to teach the bot
answer string Yes The answer for the question
context string No Optional context for when this response should be used

Response

{
    "status": "success",
    "message": "Chatbot has learned the new response!",
    "question": "how are you",
    "answer": "I'm doing well, thanks!",
    "timestamp": "2023-10-15T12:34:56Z"
}
GET /knowledge

Get knowledge base for current application. This returns all the custom responses the bot has learned.

Query Parameters

Parameter Type Required Description
search string No Search term to filter knowledge
limit integer No Maximum number of results to return (default: 10, max: 50)
page integer No Page number for pagination (default: 1)
GET /conversations

Get recent conversations for current application. Useful for analyzing interactions.

Query Parameters

Parameter Type Required Description
limit integer No Maximum number of results to return (default: 10, max: 50)
session_id string No Filter conversations by specific session
date_from string No Filter conversations from this date (YYYY-MM-DD)
date_to string No Filter conversations to this date (YYYY-MM-DD)

Client Implementation Guides

Flutter
React JS
React Native
Java
Go

Flutter Implementation

  1. Install Flutter SDK from flutter.dev
  2. Create new project: flutter create chatbot_app
  3. Add http package: flutter pub add http
  4. Implement API calls:

Example: Chat Endpoint

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<Map<String, dynamic>> sendMessage(String message, {String? sessionId}) async {
  final url = Uri.parse('https://your-api.com/chat');
  final headers = {'Content-Type': 'application/json'};
  final body = json.encode({
    'message': message,
    if (sessionId != null) 'session_id': sessionId,
  });

  try {
    final response = await http.post(url, headers: headers, body: body);
    if (response.statusCode == 200) {
      return json.decode(response.body);
    } else {
      throw Exception('Failed to get bot response');
    }
  } catch (e) {
    throw Exception('Network error: $e');
  }
}

Example: Teach Endpoint

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> teachBot(String question, String answer, {String? context}) async {
  final url = Uri.parse('https://your-api.com/teach');
  final headers = {'Content-Type': 'application/json'};
  final body = json.encode({
    'question': question,
    'answer': answer,
    if (context != null) 'context': context,
  });

  try {
    final response = await http.post(url, headers: headers, body: body);
    if (response.statusCode != 200) {
      throw Exception('Failed to teach bot');
    }
  } catch (e) {
    throw Exception('Network error: $e');
  }
}

React JS Implementation

  1. Create React app: npx create-react-app chatbot-frontend
  2. Install axios: npm install axios
  3. Create API service file:

Example: apiService.js

import axios from 'axios';

const API_BASE_URL = 'https://your-api.com';

export const chatWithBot = async (message, sessionId = null) => {
  try {
    const response = await axios.post(`${API_BASE_URL}/chat`, {
      message,
      ...(sessionId && { session_id: sessionId })
    });
    return response.data;
  } catch (error) {
    console.error('Chat error:', error);
    throw error;
  }
};

export const teachBot = async (question, answer, context = null) => {
  try {
    await axios.post(`${API_BASE_URL}/teach`, {
      question,
      answer,
      ...(context && { context })
    });
  } catch (error) {
    console.error('Teaching error:', error);
    throw error;
  }
};

export const getKnowledge = async (search = '', limit = 10, page = 1) => {
  try {
    const response = await axios.get(`${API_BASE_URL}/knowledge`, {
      params: { search, limit, page }
    });
    return response.data;
  } catch (error) {
    console.error('Knowledge error:', error);
    throw error;
  }
};

React Native Implementation

  1. Create React Native app: npx react-native init ChatbotApp
  2. Install axios: npm install axios
  3. Implement API service:

Example: apiService.js

import axios from 'axios';
import { Alert } from 'react-native';

const API_BASE_URL = 'https://your-api.com';

const handleError = (error) => {
  console.error('API Error:', error);
  Alert.alert('Error', error.message || 'Something went wrong');
  throw error;
};

export const chatWithBot = async (message, sessionId = null) => {
  try {
    const response = await axios.post(`${API_BASE_URL}/chat`, {
      message,
      ...(sessionId && { session_id: sessionId })
    });
    return response.data;
  } catch (error) {
    return handleError(error);
  }
};

export const teachBot = async (question, answer, context = null) => {
  try {
    const response = await axios.post(`${API_BASE_URL}/teach`, {
      question,
      answer,
      ...(context && { context })
    });
    Alert.alert('Success', 'Bot learned successfully!');
    return response.data;
  } catch (error) {
    return handleError(error);
  }
};

Java Implementation

  1. Add OkHttp and Gson dependencies to your build.gradle or pom.xml
  2. Create API client class:

Example: ChatbotApiClient.java

import okhttp3.*;
import com.google.gson.Gson;
import java.io.IOException;

public class ChatbotApiClient {
    private final OkHttpClient client = new OkHttpClient();
    private final Gson gson = new Gson();
    private final String baseUrl = "https://your-api.com";

    public ChatResponse chat(String message, String sessionId) throws IOException {
        ChatRequest request = new ChatRequest(message, sessionId);
        RequestBody body = RequestBody.create(
            gson.toJson(request), 
            MediaType.parse("application/json")
        );
        
        Request httpRequest = new Request.Builder()
            .url(baseUrl + "/chat")
            .post(body)
            .build();

        try (Response response = client.newCall(httpRequest).execute()) {
            if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
            return gson.fromJson(response.body().string(), ChatResponse.class);
        }
    }

    public TeachResponse teach(String question, String answer, String context) throws IOException {
        TeachRequest request = new TeachRequest(question, answer, context);
        RequestBody body = RequestBody.create(
            gson.toJson(request), 
            MediaType.parse("application/json")
        );
        
        Request httpRequest = new Request.Builder()
            .url(baseUrl + "/teach")
            .post(body)
            .build();

        try (Response response = client.newCall(httpRequest).execute()) {
            if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
            return gson.fromJson(response.body().string(), TeachResponse.class);
        }
    }

    // Request and response classes
    private static class ChatRequest {
        String message;
        String session_id;

        ChatRequest(String message, String sessionId) {
            this.message = message;
            this.session_id = sessionId;
        }
    }

    private static class TeachRequest {
        String question;
        String answer;
        String context;

        TeachRequest(String question, String answer, String context) {
            this.question = question;
            this.answer = answer;
            this.context = context;
        }
    }

    public static class ChatResponse {
        public String status;
        public String user_message;
        public String bot_response;
        public String session_id;
    }

    public static class TeachResponse {
        public String status;
        public String message;
        public String question;
        public String answer;
        public String timestamp;
    }
}

Go Implementation

  1. Initialize a Go module: go mod init chatbot
  2. Create API client package:

Example: chatbot/client.go

package chatbot

import (
    "bytes"
    "encoding/json"
    "errors"
    "net/http"
)

type Client struct {
    BaseURL    string
    HTTPClient *http.Client
}

func NewClient(baseURL string) *Client {
    return &Client{
        BaseURL:    baseURL,
        HTTPClient: &http.Client{},
    }
}

type ChatRequest struct {
    Message   string `json:"message"`
    SessionID string `json:"session_id,omitempty"`
}

type ChatResponse struct {
    Status      string `json:"status"`
    UserMessage string `json:"user_message"`
    BotResponse string `json:"bot_response"`
    SessionID   string `json:"session_id"`
}

func (c *Client) Chat(message, sessionID string) (*ChatResponse, error) {
    reqBody := ChatRequest{
        Message:   message,
        SessionID: sessionID,
    }
    
    resp, err := c.doRequest("/chat", reqBody)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    if resp.StatusCode != http.StatusOK {
        return nil, errors.New("unexpected status code")
    }

    var chatResp ChatResponse
    if err := json.NewDecoder(resp.Body).Decode(&chatResp); err != nil {
        return nil, err
    }

    return &chatResp, nil
}

type TeachRequest struct {
    Question string `json:"question"`
    Answer   string `json:"answer"`
    Context  string `json:"context,omitempty"`
}

func (c *Client) Teach(question, answer, context string) error {
    reqBody := TeachRequest{
        Question: question,
        Answer:   answer,
        Context:  context,
    }
    
    resp, err := c.doRequest("/teach", reqBody)
    if err != nil {
        return err
    }
    defer resp.Body.Close()

    if resp.StatusCode != http.StatusOK {
        return errors.New("teaching failed")
    }

    return nil
}

func (c *Client) doRequest(endpoint string, body interface{}) (*http.Response, error) {
    jsonBody, err := json.Marshal(body)
    if err != nil {
        return nil, err
    }

    req, err := http.NewRequest("POST", c.BaseURL+endpoint, bytes.NewBuffer(jsonBody))
    if err != nil {
        return nil, err
    }

    req.Header.Set("Content-Type", "application/json")
    return c.HTTPClient.Do(req)
}