Set up HTTP block inside your chatbot

BotStar can enable the chatbot 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 Builder.


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 Builder, 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: The header is included in HTTP request to the server. You can leave the Header empty or use the JSON format for the this field.

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 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.

If you have any concerns, please feel free to leave a comment below or contact us through support@botstar.com. For more details on how we have helped our customers grow their business, you can view our use cases, blogs or join our BotStar community to learn and share new things 😊


Did you find it helpful?   Yes   No