HTTP Blocks

BotStar enables bot to connect to external API servers. Scripting is not the only way to do it, you can access external API servers via our built-in interface HTTP blocks and query HTTP actions.

HTTP Blocks will help you send an HTTP Request to external servers using the parameters configured by you. Upon the request is responded by the server, depending on your configuration, the system can render one or many messages or save the returned content as a variable for later usages.

It can be accessed from within our Library panel in the Bot Buider.


The difference between HTTP block and Query HTTP action is that the HTTP block will render a message based on the return value from the server, while Query HTTP action only executes actions without rendering any messages to the user.

BotStar requires JSON format to render messages from the HTTP block. Learn more about JSON format via this link.

Note: You can render more than one message from a JSON API block.

Configuration for HTTP

Access to the Bot Buider, then select the HTTP block or Query HTTP action, you can customize the block from the right menu of Editor:

  • API EndPoint: URL of the target API server
  • JSON Payload: Data is included in HTTP request to the server.
  • HTTP Method: Protocol interacts with the server API.
  • HTTP Header: Header is included in *TTP request to the server.

HTTP response

The data returned from the server API must be in the following form:

{
'messages': [
....
],
'actions': [
....
]
}

In which,

  • messages: Array of block (message) contents to be rendered. There can be multiple blocks rendered per JSON API. Please see how to use block JSON formats here
  • actions: Array of actions upon the request is responded. There can be multiple actions per request. Please see the specification here.

Example

Set up the server API

Suppose that you have an API server at:

https://botstar.free.beeceptor.com/api

This API will be like below:

{
"messages": [
{
"text": "Hello World"
}
],
"actions": [
{
"type": "set_variable",
"data": {
"userName": "BotStar Demo",
"userPhone": "+123456789"
}
}
]
}

You can learn more about the sample Code PHP for this example here

Create Block HTTP

Go to Bot Builder, you can easily find Block JSON API in Advanced Blocks

Set up and test

Reconfigure the EndPoint API of HTTP Block to the server that you prepared in the previous step.

In this example, you can add a Text block to test the values ​​of the two "userName" and "userPhone" variables.

From the above returned data, the system renders a message with the content "Hello World" and simultaneously assigns values ​​to the two variables "userName" and "userPhone". You can easily use "userName" and "userPhone" in the next block as a saved variable from the user's response.