Submit templates for repl.it/templates here.

← Back to all posts
Virtual Assistant Template Using Adapt
AmazingMech2418 (910)

Intro

So, I saw @AdCharity 's Voice Assistant Template and I remembered that I had created myself everything needed to create an even better template using a natural language processor based on Adapt. Of course, @AdCharity 's version has a better UI, but in my opinion, something like this would likely be integrated into something else and a different UI might be wanted.

About Adapt

Adapt is designed to be a flexible programming language, mainly for the purpose of developing new programming languages. To create commands with the virtual assistant, however, you just need to program basic commands, not a full programming language, although, it is possible to use this virtual assistant to work like a voice-based programming language.

Native Functions

To declare what each command dones, you need to create a native function. To do this, go to language.adapt and use this format to declare your function:

native function function_name_here
  (ARGS) => {
    // Code here
  }

In the native function declaration, you cannot use tabs and must use two spaces. Additionally, the ARGS parameter is an object containing the arguments for your function.

Constructors

Now, you need to add constructors, or in other words, templates to convert voice commands to Adapt-readable commands. Use this format to create a constructor:

constructor function_name_here ({template_here},{[argument_maps_here]},{[]})

The last set of brackets should not be used for a basic virtual assistant, but is simply an array of the parameters that should be re-evaluated.

Constructor Templates

Constructor templates are simply the templates for the voice commands. Use the $ character followed by another character (number or letter preferred) to declare a parameter. For example do something $1 will declare the variable mapped to 1 (see section on argument maps) where the template says $1.

Argument Maps

Argument maps allow you to use the parameters in your Adapt command in your native function declaration through the ARGS parameter. The argument maps are items that are arrays in an array using JSON where the first index (index 0) is the character surrounded by quotes and the second index (index 1) is the parameter name that this maps to surrounded in quotes.

Example:

constructor open ({open website $1},{[["1","site"]]},{[]})

This example adds a constructor to the open function with the template of open website $1. It also maps the parameter 1 to the argument site in the ARGS parameter of the native function declaration.

Credits

All code here is by me with the exception of jQuery which is used for requests to the language.adapt file. SpeakJS is a library I created a while ago for speech recognition. Adapt is a programming language I developed recently (also my programming language template) designed for flexibility.

I would also like to credit @AdCharity for inspiring this template since this template is inspired by @AdCharity 's template, although it uses no code from it.