We're happy to announce that our chat-bot will be available for Open-source users. We are integrating Botpress on erxes. Moreover, this guide will give you the general knowledge the functions and the features of the chat-bot.
Content type
The content type specifies the structure to which the bot is sent and specifies how to render the content. Content comes in plain text, single-choice, card, image, and carousel.
Text
Text is suitable for simple conversations. You can see down below an example of a simple conversation :
"id": "builtin_text-u7JtKB",
"formData": {
"markdown $ en": false,
"typing $ en": false,
"text $ en": "Hello World",
"variations $ en": []
},
"createdBy": "admin",
"createdOn": "2020-10-01T10: 09: 06.672Z",
"modifiedOn": "2020-10-01T10: 09: 06.672Z"
}}
Single-choice
Single-choice offers users answers, and when you choose one, the other options disappear. It is designed to provide an instant response
You can see the example of a single-choice:
“Value”: “CA”
},
{
“Title”: “Massachusetts”
“Value”: “MA”
}}
],
"markdown $ en": true,
"typing $ en": true,
“Text $ sen”: “In which state do you live”
},
"createdBy": "admin",
"createdOn": "2020-10-20T10: 21: 11.393Z",
"2020-10-20T10: 21: 11.393Z"
}
Image
Image is used to send an image content
"formData": {
"typing $ en": true,
"image $ en": "/api/v1/bots/erxes-test/media/2v3q8jyuquj1mlnfynls-114692700_186356069513291_6090381358721157989_n.jpg"
},
"createdBy": "admin",
"createdOn": "2020-10-20T10: 25: 07.132Z",
"modifiedOn": "2020-10-20T10: 25: 07.132Z"
Carousel
Carousel is used for sending multiple cards
Dialog Engine
Dialog Engine is used for organizing conversions of the Botpress. It is responsible for everything that is related to the chat-bot and it moderates both the customer’s input and the response of the chat-bot.
Flows
Flows is used to demonstrate the logic of the chat-bot, it consists of several Nodes which helps to complete the developer’s guidance. Moreover, nodes can perform and complete an action in accordance with the developer’s code. In addition, both presses have their own defined functions.
Flow Lifecycle
Flows always start from startNode. Dialog engine will be processed to the endNode after the first unit has been processed.
Storage
Flows are stored as JSON files in bot * \ data \ bots \ (yourBot) \ flows in two types: ui.json and flow.json.
Flows are saved as JSON files
- * .ui.json retains the visual properties of the flows in the GUI.
- * .flow.json stores the logical information of the flows.
- .ui.json uses the view feature in the flow GUI.
Node Life - cycle
When onEnter note is called the functions will be performed are:
onReceive is a list of functions that can be performed after receiving a node message while the node is active. These will automatically wait for the user to enter.
onNext is a condition that specifies the next transition instruction for a node after an onEnter or onReceive execution. Also called Transition.
Transitional possibilities:
- A different Node
- A different Flow
- The previous flow
- Its own Node
Action and Hooks
Action is a server-side function performed by a bot as part of a flow. Action has the ability to do many things. These include:
- Action is a part of flow
- Change the state of the conversion
- Send a customized message
- You can run any code, such as calling an API or storing data in a database
When an action is called by the Dialog Manager, the following arguments are passed
- user: Includes all user properties
- session: Includes all variables stored during the session
- temp: Contains only the variables contained in the Flow
- bot: An object that contains the global variables of the bot
- event: The last event received from a user in Conversation
- args: Arguments passed from Visual Flow Builder to action
- process: sandboxed Variables starting with EXPOSED_ contained in a virtual machine
Hooks
Hooks are very useful for performing actions when signaling an open event.
These hooks are defined by a global javascript file in the data / global / hooks / $ {hookName} folder.
After Server Starts
The event is loaded once all modules and both are loaded and the bot is ready to allow incoming connections.
Location: data / global / hooks / after_server_start
Parameters: bp
After Bot Mount
This event is loaded each time the bot is defined, either when the server is turned on or when a new bot is added during operation.
Location: data / global / hooks / after_bot_mount
Parameters: bp, botId
After Bot Unmount
This event is loaded each time the bot is deleted. Usually used to clean Memory.
Location: data / global / hooks / after_bot_unmount
Parameters: bp, botId
Before Incoming Middleware
This hook is loaded before any shared application when receiving the event. It is possible to change the properties of the event.
Location: data / global / hooks / before_incoming_middleware
Parameters: bp, event
After Incoming Middleware
This hook is loaded immediately after all incoming shared applications have processed the event, but before that the dialog Engine starts processing it.
Location: data / global / hooks / after_incoming_middleware
Parameters: bp, event
Before Outgoing Middleware
The hook is loaded before sending a response to the user
Location: data / global / hooks / before_outgoing_meddleware
Parameters: bp, event
Before Session Timeout
This hook is loaded before the user passes on the node.
Location: data / global / hooks / before_session_timeout
Parameters: bp, event
Memory
User questions and answers may need to be used later in the conversation.
Variables
Botpress has 4 types of memory that differ in duration and scope.
- user memory is stored forever for the connected user.
- session memory is stored for the duration of the session.
- The temp memory is stored only for the duration of the flow.
- bot memory is the same value for all users of the same bot.
Setting and accessing variables
The above variables can be set and declared using Set Variable action or code.
See the figure below for an example of using Set Variable action :
An example of declaring by code: temp.user_name = “Billy”
Tutorials
Converse API
The Converse API is an easy way to integrate Botpress with any application or other channel. This API allows you to talk to your bot and get answers synchronously.
Public API
POST / api / v1 / bots / {botId} / converse / {userId}, where userId is a unique Id to identify the user who is chatting with your bot (botId). You can use any string in userId, or assign application / json to the Content-Type HTTP header.
Request body
"type": "Text",
"text": "hello!"
}}
API Response
"responses": [
{
"type": "typing",
"value": true,
},
{
"type": "text",
"markdown": "true,
"text": "hello!"
}}
],
Call API
The Flow API allows for easy loading
Request Body
The request body should be adjusted here.
Request headers
Request headers can be configured here and should be in JSON format.
Examples of headers
every email message needs a header indicating the sender's identity and address
Response
We use memory to store Response. Botpress saves temp.response by default. However, the developer can save it to other memories.
Calling an API in Custom Action
One of the most common uses of Actions is to load an API, retrieve some data, and use it in Flow.
In this tutorial, we’ll look at an example of sending a request to an API using the detected response in our flow.
Create an action
We will use axios as the http client. Write the code in the data / bots / {your_bot_name} / actions / {your_action_name.js} file.
Server-side :

The example above is a server using Javascript Express, which returns the data needed to build a botpress carousel in the correct format when the name object in the body of the incoming request is "start".
Client Side:
const myAction = async (name, value) => {
let doc
await axios.post ('https://fc43ff37499e.ngrok.io', {name}). then (function (response) {
doc = response.data
})
const {card} = doc
const {text} = doc
const payload1 = await bp.cms.renderElement ('builtin_text', {text: `$ {text}`}, event)
const payload = await bp.cms.renderElement ('builtin_card', card [0], event)
bp.events.replyToEvent (event, payload)
bp.events.replyToEvent (event, payload2)
}}
return myAction (args.name)
The example above is to create a card and text element using the response sent to the API request
Botpress users are sending a reply message.
These include:
Request body:
{“Name”: “Start”}
Response:
