NAV Navbar
Curl Ruby NodeJs Python

Introduction

API Reference

BotStar allows you to interact with API Server via HTTP Requests, so it works with any language that has an HTTP library, such as cURL and node. Base URL

http://docs.botstar.com/api

Welcome to BotStar API Reference. API is needed when you have to build sophisticated chatbots and in need of developing your own middleware for your chatbot.

We will expand the capacity of our API gradually in the future. If you have any feedbacks or requests, feel free to contact us.

Authentication

BotStar authenticate calls to our API via API Access Token to identify which bot are being referred to. Please obtain this token in Settings page of your bot.

Access token

API

Send Messeage

Send messages to a specific user.

 curl -X POST \
  'https://api2.botstar.com/broadcast?token=BotStar_Access_Token' \
  -H 'Content-Type: application/json' \
  -d '{
    "messages": [{
      "text": "Hello",
    }],
   "userId": "UserId"
  }'
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://api2.botstar.com/broadcast?token=BotStar_Access_Token")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request.body = JSON.dump({
  "messages" => [
    {
      "text" => "Hello"
    }
  ],
  "userId" => "UserId"
})

req_options = {
  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end
var https = require('https');

var postData = JSON.stringify({
   "messages": [
     {
       "text": "Hello"
     }
   ],
   "userId": "UserId"
 });
var options = {
  hostname: 'api2.botstar.com',
  path: '/broadcast?token=BotStar_Access_Token',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  }
};

var req = https.request(options, (res) => {
  res.on('data', (d) => {
    try {
      const data = JSON.parse(d);
      if(data.statusCode === 200) {
        // request success
      } else {
        // request error
      }
    } catch (error) {
      // request error
    }
  });
});

req.on('error', (e) => {
  // request error
});
req.write(postData);
req.end();
import requests
headers = {
    'Content-Type': 'application/json',
}
params = (
    ('token', 'BotStar_Access_Token'),
)
data = '{ "messages": [{ "text": "Hello World" }], "userId": "UserId" }'

response = requests.post('https://api2.botstar.com/broadcast', headers=headers, params=params, data=data)

The command will return a JSON response like below

{
    "statusCode": 200,
    "body": "[
      {
        \"recipient_id\": \"2027434403966085\",
        \"message_id\":\"m_Dt9p4pLTi_s2nWHNeVnFjOi8IqsZymK6d5ib351V2jXdJke58SgdDXC9z_WPTMSy3vW7BsPLw-BtQjUNHqMeig\"
      }
    ]"
}

Please use statusCode in the return body for sure the command has been executed

HTTP Request

POST https://api2.botstar.com/broadcast

Query Parameters

Parameter Description
token API Access token

Request Body

Parameter Description
message An array of messages that will be sent to user. Learn more about how to form messages with BotStar Blocks via JSON Formats.
userId A string that contains user ID of the recipient. Please learn how obtain a user ID from BotStar Here.