ScriptForge¶
Developer ScriptForge
Use ConnexCS ScriptForge to write ECMAScript 2015 (ES6) (aka JavaScript) and execute it in a secure sandbox on the server. It's designed to have low latency and high throughput.
It's made for scripts and small applications. Any larger applications are best executed on external hardware through ScriptForge.
A fair-usage policy applies, and if there is unnecessary resource use or if there are any attempts to break the sandbox, your script may not function as expected.
It's designed to work as FaaS (Functions as a Service), and our redundant infrastructure handles your application's auto scaling needs.
Developer Documentation¶
ConnexCS offers several libraries specifically for use with ConnexCS. Developer API Documentation is available here.
Available Modules¶
You can include some more modules (from npm), available for applications and drivers only.
The purpose is to keep the sandbox lightweight and include only the necessary modules:
Modules | |||
---|---|---|---|
axios | axios-cookiejar-support | card-validator | csv-parse/lib/sync |
data-forge | decompress-zip | elasticemail-webapiclient | fast-csv |
fast-toml | ftp | helpscout-2.0 | moment |
rss-parser | soap | stripe | tough-cookie |
Sample Scripts¶
You can find sample scripts in our GitHub repository > example applications. Below is a list of some use cases. But with a Turing Complete language, the possibilities are endless.
- Do Not Call Lists
- Custom Fraud Detection
- Internal Automations
- Capture and process the Control Panel and Customer Portal forms
- Inbound and Outbound Call Filtering
- Class 5 Programmable Voice Applications
- DID Drivers
- Time of Day Restrictions
Coding Basics¶
Scripts and Apps typically start in the main()
function and expect to return a promise. The first parameter is typically an object called data
.
Throwing Errors (Class 4)¶
Follow the following format; [SIP code] :space: [Error Message], for throwing errors.
For example, to throw a 404 Not Found, you can use the following
throw new Error('404 Not Found');
(SIP: Session Initiation Protocol, DID:* Direct Inward Dialing)
Class 4 Routing (Routes and Direct Inward Dial)¶
After the routing engine has executed its main function, the system will run the custom ScriptForge script.
This presents data as the output to the routing engine and expects the same object structure.
function main (data = {}) {
// data.routing contains the same data you will find in the Logs
// in the Raw Data Section
return data;
}
Class 5 Programmable Voice¶
You can use Programmable Voice to write smart voice applications controlled in modern JavaScript.
The call and the Programmable Voice script are both executed simultaneously, simplifying the entire process. This means that (for example) you would initially run an await answer()
, it would not progress to the next line until the platform has finished executing the operation.
See the ConnexCS ScriptForge documents for more JavaScript examples.
Second parameter is a ctx object
function main (data = {}, ctx) {
// ctx contains class 5 ctx object
}
Potential Sync Issues
To avoid the system losing synchronisation with your script and the connection crashing, execute ALL async functions with await
.
If it isn't implemented correctly, it affects thatbilling and call stability.
Form Submission¶
Used to receive data from Form Builder in ConnexCS.
You can view it in the control panel or customer portal.
function main (data = {}) {
// data contains object containing key/value pairs from the form.
}
Driver¶
A driver is a module export that may contain several pre-defined functions dependent on the integration; flow is an example for a DID Driver.
module.export = {
search: async function ({number}) {
// Returns Array of Objects, e.g [{did:'1234'}]
},
allocate: async function ({did}) {
// The information returned by this function will be passed to
// https://api-docs.connexcs.com/#api-Did-Create
},
release: async function ({did}) {
// Returns True / False
},
list: async function () {
// Returns Array of Objects, e.g [{did:'1234'}]
}
}
Configuration¶
Build Script¶
- To add a script, click .
- Specify the script Name.
- Select the Type:
Script
- This is the fastest way to execute custom code and is "synchronous" execution. This is mainly used for manipulations or calculations. It can't use libraries or work with Promises.App
- Feature rich applications which can include a preset (whitelist) of available modules, the penalty of the extra features is a slightly higher latency.-
Driver
- A driver works as an intermediary between ConnexCS and any external system. You can write drivers to bridge the ConnexCS DID provisioning system to a provider of your choice or build more complicated alerts. -
Click
Save
.Script
- This is the fastest way to execute custom code and is "synchronous" execution. This is mainly used for manipulations or calculations. It can't use libraries or work with Promises.App
- As a penalty, feature-rich applications with a predefined list (allow list) of available modules have slightly higher latency.Driver
- A driver works as an intermediary between ConnexCS and any external system. You can write drivers to bridge the ConnexCS DID provisioning system to a provider of your choice or build more complicated alerts.
-
Click
Save
. -
Select your script from the list.
- Enter the code of your script.
- Click the green arrow to
Save and Run
. - You can view the results onscreen.
If script shows an error, add this and then run the script again:
{"routing":{}}
Assign the Script to a Customer¶
- Select Management Customer [Customer Name] Routing
-
Select a Rate Card from Ingress Routing.
-
Go to ScriptForge
- Select the script.
- Set the Timeout to specify the duration you want it to run before it times out.
- Enter the Timeout Action manually and format it as
[sip response code] [sip response message]
. - Click
Save
.
Assign the script to other functions¶
ScriptForge was initially designed to run from the routing-engine only, but it's available for the following scenarios:
Class 4 Routing (Termination) - (App or Script): Management Customer [Your Customer] Routing [Your Route] ScriptForge
Class 4 Routing (Origination) - (App or Script): Management Customer [Your Customer] DID [Your DID] ScriptForge
Class 5 Programmable Voice - (App only)
Drivers - (App only): Currently available for Alert & DID