GPTScript Overview - helixml/demo-recipes

GPTScript is a serverless JavaScript runtime for G Suite automation, extension, and integration. It is based on JavaScript and runs on the cloud, making it easy to publish web apps, build add-ons, and leverage the power of other services. GPTScript is used in the Helix ML project to create scripts that perform various functions.

Types of Scripts

There are different types of scripts that can be created with GPTScript, each with its own function. Here are some examples:

Stand-alone Script

A stand-alone script is a script that is not connected to a single G Suite app such as Docs or Slides. It can be used to automate various tasks and perform several other useful functions. Here is an example of a stand-alone script in GPTScript:

function helloApp() {
// get current document
var doc = DocumentApp.create('created with clasp');

// set footer text
doc.addFooter().appendParagraph(new Date().toDateString());
}

This script creates a new document in Google Docs and sets the footer text to the current date.

GPTScript Integration with Helix ML

GPTScript is integrated with Helix ML to enable developers to create even more powerful features for G Suite products. Here is an example of how GPTScript is used in Helix ML:

const { Helix } = require('helix-ml');

const helix = new Helix();

async function run() {
await helix.init();

const doc = await helix.createDocument();

doc.addFooter().appendParagraph(new Date().toDateString());

await helix.saveDocument(doc);
}

run();

This script uses the Helix ML library to create a new document in Google Docs, set the footer text to the current date, and save the document.

GPTScript Options

GPTScript has several options that can be used to customize the script. Here are some examples:

-v or –verbose

The -v or --verbose option can be used to print verbose output. This option is useful for debugging and troubleshooting. Here is an example of how to use the -v option:

function helloApp() {
// get current document
var doc = DocumentApp.create('created with clasp');

// set footer text
doc.addFooter().appendParagraph(new Date().toDateString());

// print verbose output
console.log('Document created successfully');
}

helloApp();

-h or –help

The -h or --help option can be used to print help information. This option is useful for getting information about the script syntax and options. Here is an example of how to use the -h option:

function helloApp() {
// get current document
var doc = DocumentApp.create('created with clasp');

// set footer text
doc.addFooter().appendParagraph(new Date().toDateString());
}

HelloApp.help = function() {
console.log('Help information goes here');
}

HelloApp.help();

Conclusion

GPTScript is a powerful tool for automating, extending, and integrating with G Suite apps. It is easy to learn and use, and can be customized with various options. By integrating GPTScript with Helix ML, developers can create even more powerful features for G Suite products.