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 with your actual app token).

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

ParameterDescriptionDefault
opMUST have the value - "scriptadd"Mandatory
tokenApplication Token obtained from the mesibo consoleMandatory
descriptionScript description for your reference.empty
fileFile field to upload script (.js file)true
sidScript ID if the upload is to replace existing script0

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.

ParameterDescriptionDefault
opMUST have the value - "scriptset" (see example above)Mandatory
tokenApplication Token obtained from the mesibo consoleMandatory
script.idScript ID returned by script add or get operationMandatory
script.addressAddress of the user to attach to the script.Mandatory
script.toExecute scripts when messages are sent to this userfalse
script.fromExecute scripts when messages are sent from this userfalse
script.defMake the script default for the app. Execute scripts when messages are sent by any user of the appfalse

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:

ParameterDescriptionDefault
opMUST have the value - "scriptget" (see example above)Mandatory
tokenApplication Token obtained from the mesibo consoleMandatory
script.idScript ID returned by script add operationMandatory

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:

ParameterDescriptionDefault
opMUST have the value - "scriptdel" (see example above)Mandatory
tokenApplication Token obtained from the mesibo consoleMandatory
script.idScript ID returned by script add operationMandatory

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:

ParameterDescriptionDefault
opMUST have the value - "scriptsget" (see example above)Mandatory
tokenApplication Token obtained from the mesibo consoleMandatory