External Scripts can be used to call functions from within a page at a chosen point in the flow. Assume that you want to open some other widget on your page. This can be done by adding an async function to the externalScripts
object inside the mavenoid.push
call.
mavenoid.push({
event: "assistant-mount",
client_id: YOUR_CLIENT_ID,
externalScripts: {
async openOtherWidget(input) {
/* Code to initialize the other widget */
return {
formData: [
{
id: "result",
value: {
type: "string",
value: "ok",
},
},
],
};
},
},
});
This function can then be referenced by its key, openOtherWidget
, from an external script node.
The External script function takes an argument which is defined within the Input field of the External script node. This allows us to pass metadata from the assistant to the other widget, assuming the other widget solution supports this. For example, if we want to pass the user’s name, email, and the transcript of the assistant, then we construct the Input object as follows:
{
"name": {{customer-name}},
"email": {{$cusomter-email}},
"transcript": {{$transcript}}
}
This allows the values to be referenced inside the external script function.
externalScripts: {
async openOtherWidget(input) {
var name = input.name;
var email = input.email;
var transcript = input.transcript;
/* Code to initialize the other widget */
The External script function should return a form data object that stores the result of the External script as form data. This form data key can be used in the canvas to display the result of the External script or use a Read data node to branch the flow based on the result of the External script. For example, the following return statement will create a form data key with the key “result” and the value “ok”.
return {
formData: [
{
id: "result",
value: {
type: "string",
value: "ok",
},
},
],
};
The allowed values for the form data type are string, date, boolean, and json.