Mesibo Backend APIs - Scripting and Chatbot Configuration
This section describes how to upload and manage scripts for the mesibo scripting and chatbot feature using the Backend APIs. For in-depth details on how to use mesibo scripting and chatbot features, refer to the mesibo Scripting and Chatbot Documentation.
If you are using the mesibo on-premise server, you must use the Backend APIs to upload and manage scripts. This also ensures complete privacy of your scripts.
If you are using the mesibo cloud service, you can use either the Console or the Backend APIs.
Uploading a Script
To upload a script, you can use an HTML form or make an HTTP POST request to the Backend API endpoint. Here's an example HTML form to upload your script (replace
<form action="https://api.mesibo.com/backend" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="text" name="op" value="scriptadd">
<input type="text" name="token" value="<app token>">
<input type="text" name="description" value="my script">
<input type="submit" value="Upload" name="submit">
</form>
If you're using the mesibo on-premise server, change the action URL to your on-premise backend server URL.
Following are the request parameters, most of them are OPTIONAL unless the Default value is mentioned as Mandatory.
Parameter | Description | Default |
---|---|---|
op | MUST have the value - "scriptadd" | Mandatory |
token | Application Token obtained from the mesibo console | Mandatory |
description | Script description for your reference. | empty |
file | File field to upload script (.js file) | true |
sid | Script ID if the upload is to replace existing script | 0 |
Ensure that the JavaScript file has no errors and implements the mesibo.on_message()
function as described in the Scripting and Chatbot Documentation.
Using an HTTP POST Request
You can also upload a script by making an HTTP POST request to the Backend API endpoint with the script file in the request body. Here's an example using curl:
curl -X POST \
https://api.mesibo.com/backend \
-H 'Content-Type: multipart/form-data' \
-F op=scriptadd \
-F token=<app token> \
-F description='my script' \
-F file=@/path/to/script.js
Replace <app token>
with your actual app token and /path/to/script.js
with the path to your script file.
Attach Users to a script
You can attach users to a script so that the script gets executed for messages sent and received by these users. You generally attach scripts to users designated as chatbots. You can attach the same or different scripts to be executed when a user sends or receives messages. A script can be attached to multiple users.
To attach users to a script, send a JSON request to the Backend API.
{
"op": "scriptset",
"token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
"script": {
"id": 35145,
"address": "ai.chatbot",
"to": true,
"from": false
"def": false,
}
}
Following are the request parameters, most of them are OPTIONAL unless the Default value is mentioned as Mandatory.
Parameter | Description | Default |
---|---|---|
op | MUST have the value - "scriptset" (see example above) | Mandatory |
token | Application Token obtained from the mesibo console | Mandatory |
script.id | Script ID returned by script add or get operation | Mandatory |
script.address | Address of the user to attach to the script. | Mandatory |
script.to | Execute scripts when messages are sent to this user | false |
script.from | Execute scripts when messages are sent from this user | false |
script.def | Make the script default for the app. Execute scripts when messages are sent by any user of the app | false |
Getting a Script and Attached Users
To get a script and all attached users, send the following JSON request to the Backend API:
{
"op": "scriptget",
"token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
"script": {
"id": 35145,
}
}
Following are the request parameters:
Parameter | Description | Default |
---|---|---|
op | MUST have the value - "scriptget" (see example above) | Mandatory |
token | Application Token obtained from the mesibo console | Mandatory |
script.id | Script ID returned by script add operation | Mandatory |
Deleting a Script and Attached Users
To delete a script and all attached users, send the following JSON request to the Backend API:
{
"op": "scriptdel",
"token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
"script": {
"id": 35145,
}
}
Following are the request parameters:
Parameter | Description | Default |
---|---|---|
op | MUST have the value - "scriptdel" (see example above) | Mandatory |
token | Application Token obtained from the mesibo console | Mandatory |
script.id | Script ID returned by script add operation | Mandatory |
Getting All Scripts
To get all scripts, send the following JSON request to the Backend API:
{
"op": "scriptsget",
"token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
}
Following are the request parameters:
Parameter | Description | Default |
---|---|---|
op | MUST have the value - "scriptsget" (see example above) | Mandatory |
token | Application Token obtained from the mesibo console | Mandatory |