Replacer scripts
The Replacer Script lets you swap out core actions with your custom script.
You must be very exact with both input and returned data. With the replacer scripts the input data and the returned data is different for every script. however there are several common aspects
All Replacer scripts will be based in a data
block that will contain specific information. You will also find the current company available on the bbCore library.
Setup
A script is setup in the manifest of a script with :
{
"name":"TestAdminScript",
"description":"An example script",
"type":"Replacer",
"actions": ["UrlShortener"],
"log_type": "Tail",
"enabled": true,
"handler": "shorten"
}
On Success
On successfully running, your script is expect to return any expects results in a result
params. The result object may be a simple text string, an array, or a complex object, depending on the function, for example:
callback(null, {result: 'My returned text'})
Is the action has no data required as a result, i.e. it is a fire-and-forget action, you should instead just pass back an success value
callback(null, {success: true})
On Failure Fallback
If you scripts fails for some reason, you can choose to fall back the default action, which is also what will happen if your scripts errors unexpectadly
callback(null, {fallback: true});
Script types
Script Action | Description | Input Params (data) | Response Values |
---|---|---|---|
UrlShortener | A custom URL shortener, pass in the the URL to shorten and expected to return the new URL to use | url: text | result: text |
SMSSender | A request to a send an SMS to a mobile number | message: text, recipient: text | success: bool |
Examples
Some example apps that demonstrate Replace scripts
- TextLocal SMS Sender: https://github.com/jrni-platform/textlocal
- Bitly URL Shortner: https://github.com/jrni-platform/bitly
Updated over 4 years ago