Code <--> Qreli interoperability
The Qreli runtime interprets and executes your steps, calls your APIs, appliess variable definitions etc. Underneath, at some point it executes Javascript code on the client-side (e.g. front-end).
Say you ask AI to write some code, or you write it yourself. Inside this, you want to call some API function defined in your Qreli app, or pull up the value of various fields or variables.
To do so, we buit QAPI.Compute
, which can be called after submit. You would use it in your code editor, like so:
QAPI.Compute functions
These are the functions you can use:
getAllVariables
return QAPI.Compute.getAllVariables();
This returns the values of all the variables you defined in your app.
getVariableValue
QAPI.Compute.getVariableValue('<variable name>')
This returns the value of a specific variable.
Example: return API.Compute.getVariableValue('V.flowers');
returns the value of the flowers variable defined in your flow.
getAllUserData
return QAPI.Compute.getAllUserData();
This returns the values of all the user-entered fields defined in your app (text boxes, drop-downs selectors etc.) — the interface elements users enter data in.
getUserData
return QAPI.Compute.getUserData('<field_name>');
This returns the value of a specific user data field.
Example: return QAPI.Compute.getUserData('first_name');
returns the value of the first_name user-entered field.
getAllEnvironments
return QAPI.Compute.getAllEnvironments();
This returns all the environment data — information about app, visitor, location, duration etc:
If called as QAPI.Compute.getAllEnvironments(false);
it will return the information in a non-hierarchical way:
getEnvironment
return QAPI.Compute.getEnvironment('<key>');
This returns the value of a specific environment property.
Example: return QAPI.Compute.getEnvironment('E.visitor.id');
returns the value of the visitor id running the app.
runApi
async () => {
return await QAPI.Compute.runAPIVar('<var_name_without_V>', <bool>);
}
This executes a specific API call. Note that if the API variable where it was defined is, say V.ask_ai, you would call it simply as QAPI.Compute.runAPIVar('ask_ai')
The optional parameter (default false) is used whether you wish to show the preloader/spinner animation associated with the API call. It's by default false as when running headless you would not need this.
listData
async () => {
return await QAPI.Compute.listData();
}
This retrieves all the keys for custom data stored in your app.
If used as QAPI.Compute.listData(true);
it returns the full data (keys and values).
storeData
async () => {
return await QAPI.Compute.storeData('<key>', <value>);
}
This stores custom app data under your defined key.
getData
async () => {
return await QAPI.Compute.getData('<key>');
}
This retrieves the custom app data stored for that specific key.
removeData
async () => {
return await QAPI.Compute.removeData('<key>');
}
This removes from the custom app data storage the item with that specific key.
Likewise, we created QAPI.Navigation to make it easy to transition to different steps directly from code, skipping and interface or AFTER calculations.
QAPI.Navigation
nextStep()
Proceed to the next step, as if you clicked the "Next" button, but skipping the current calculations.
prevStep()
Proceed to the next step, as if you clicked the "Back" button, but skipping the current calculations.
gotoStep(name)
Go to a specific, named step.
Also supports jumping back and forward on special values "__PREV__" and “__NEXT__”.