Scripts
InSkill Scripts are the way to connect to external systems for integration, or to run custom logic to process your data.
Scripts are javascript code that can be run
- at the beginning of a task or GPT conversation (context augmentation) usually to gather information from an IoT system, historian, etc.
- at the end of a task (session finished) usually to send results of the task to another system, or email to support, etc.
You can edit and test scripts without making them active. When they are active, they will automatically run when tasks execute.
To develop a script, choose the event (eg. Session Finished) that will trigger the script. Below the script is json data of a task. You can edit this to reflect any data you want the script to process. Or you can Select Task from History to choose an existing task that has already run, to populate the json data. This way you are testing with the exact data set of a previous task.
When you click the Run Script button, the script runs and the result is displayed below. This allows testing without saving each time, but remember to Save when you want to keep your changes.
For security reasons, all scripts run in a safe sandbox that limits the actions in a script. There are some predefined objects that represent the task context, optionally the asset if one is associated with this task, and some other objects. You cannot install additional packages.
console.log() prints information in the result area when you test. (Automatically run scripts don't print anything)
Reference:
Inskill.GPT
ask(question, { data={}, references=[], visible=true })
var question = `
summarize the likely issue based on the provided error codes and suggest recommended next steps.
format: "Error Codes: '...' (bullet list)
Likely Issue: '...'
Recommended Actions: '...'"`;
/** ask question */
Inskill.GPT.ask(question);
/** ask "hidden" question */
Inskill.GPT.ask(question, { visible: false });
/** ask question & provide additional references */
var references = [{ title: '...', content: '...' }];
Inskill.GPT.ask(question, { references });Inskill.Session
Properties
- task - the name of the task
- start - timestamp when the task started. unix style seconds since time began in 1970. Use the package moment to format into readable string, etc.
- end - timestamp when the task ended (optional, if task has ended)
- data - the raw set of data as an object
- code - handoff code (optional)
- language - the language used, in 2 letter code eg "en", "fr", "ch"
- step_count - the number of steps used in the task. Will be 0 for context augmentation
hasData(key)
ds.hasData(key) - where key refers to the name of a variable in the data set. Use to test if the key has a value
if (Inskill.Session.hasData("pressure")) {
// do something with Inskill.Session.getData("pressure")
}getData(key)
safely get the value of a variable, or null
setData(key, value)
set a variable in the task's data
removeData(key)
remove an existing variable
getOwner()
hasAsset()
url([navcode, portal])
sendEmail(email, [body, subject])
send email to the to address. Default is json of the task. Include the body and subject to format the email to be readable
Inskill.Session.sendEmail("[email protected]");
let body = `Support escalation \n asset ${Inskill.Session.asset.sn}`;
Inskill.Session.sendEmail("[email protected]", body, "Escalation"); userLog(message)
writes the message into userlog, can log escalations, tasks with problem conditions, etc.
createAsset(sn, [name])
Inskill.Session.asset
Properties:
- sn
- name
- product_id
- data
- url
- notes
- groups
hasData(key)
ds.hasData(key) - where key refers to the name of a variable in the data set. Use to test if the key has a value
if (Inskill.Session.Asset.hasData("pressure")) {
// do something with Inskill.Session.Asset.getData("pressure")
}getData(key)
safely get the value of a variable, or null
setData(key, value)
set a variable in the task's data
removeData(key)
remove an existing variable
Inskill.Utils
empty(obj)
getData(path, obj)
setData(path, value, obj)
webRequest(options)
var options = {
method: 'GET' // GET, POST, PATCH, DELETE
url: 'https://weather.com/' + Inskill.Session.getData('zipcode'),
headers: {
'X-API-Key':'XUQJbhZGL1DnOWygBg5nati0NDzFuD26Aw_LtrHssX_0k6GbVsWY11R46cCg'
},
data: {}
}
/** AWAIT */
var { error, body, response } = await Inskill.Utils.webRequest(options);
console.log(body);
session.done();
/** JS PROMISE */
Inskill.Utils.webRequest(options).then(function({ error, response, body }) {
console.log(body);
session.done();
});Libraries:
The following packages are included:
- moment - convert timestamps into date and time
- moment_timezone - timezone aware
- crypto - functions to sign requests, etc.
- mqtt
crypto
function generateHMAC(data, secret) {
const hmac = crypto.createHmac('sha256', secret);
hmac.update(data);
return hmac.digest('hex');
}
function generateHash(data) {
const hash = crypto.createHash('sha256');
hash.update(data);
return hash.digest('hex');
}
// HMAC Example
let data = 'myDataToHMAC';
let secret = 'mySecretKey';
let hashedData = generateHash(data);
let hmacResult = generateHMAC(data, secret);
console.log(hashedData);list of all the available crypto commands
console.log(Object.keys(crypto));Updated 29 days ago
