Learn how to write your own Jovo Plugin. In this tutorial, we are creating a custom logger plugin for voice apps built with the Jovo Framework.
You can find the full code example of this tutorial here: jovo-templates/tutorials/plugin.
Or download it using the Jovo CLI:
- Introduction to Jovo Plugins
- How Jovo Plugins Work
- Creating a Custom Logger
We added the Jovo Plugin feature in order to allow our users to customize the framework to their needs as well as to build features, which other members of our community can benefit from.
Plugins allow you to easily extend the Jovo Framework without having to mess with its core code and architecture. You can, for example, integrate your own analytics API or create a custom logger.
The plugins work with middlewares, which all combined handle the complete request execution. As soon as the execution reaches the middleware your plugin is connected to, it will run your specified function. Learn more about the Jovo framework architecture here.
||First initialization of
||Raw JSON request from platform gets processed. Can be used for authentication middlewares.|
||Determines which platform (e.g.
||Natural language understanding (NLU) information gets extracted for built-in NLUs (e.g.
||Request gets routed through external NLU (e.g.
||Initialization of user object. User data is retrieved from database.|
||Request and NLU data (intent, input, state) is passed to router. intentMap and inputMap are executed. Handler path is generated.|
||Handler logic is executed. Output object is created and finalized.|
||User gets finalized, DB operations.|
||Platform response JSON gets created from output object.|
||Response gets sent back to platform.|
||Errors get handled if applicable.|
Since plugins feature is tailored for more advanced users, I will skip the creation of a Jovo project and jump right into the code example. The plugin we're going to create will be a simple logger to track Google's
Default Fallback Intent.
jovo-integrations folder, which are all plugins as well:
To build our own plugin we have to create a class:
Inside that class we will add a constructor, which will be empty for now:
Next up is the core part of the plugin. The
install() method is the place, where you connect to the middlewares:
The first middleware we want to connect to, is the
platform.output middleware, to log our app's response as well as the state prior to the utterance of our user, which triggered the
Default Fallback Intent. Every time the request execution gets to the
platform.output middleware, our
saveOutput() function will be executed as well.
Our function will have a single input, the
handleRequest object, which every function connected to a middleware will get. It has the following interface:
We will need the
jovo object, which is the same object we access using
this inside we handler.
The first thing we will check for is, if the request came from the
After that we get both the speech and, if it exists, the reprompt string and delete their
After that we also save the state and add everything to the
output string, which we will add to the
That's all we need to do here. Next up, is to check the incoming requests for the
Default Fallback Intent and log our saved output with the user's utterance.
To do that we connect our plugin to the
platform.nlu middleware, which will execute the
log() function we check for the platform, the
Default Fallback Intent,add the user's utterance to the output, log the whole string and reset it back to and empty string.
At the end our plugin looks like this:
Last but not least, we add the plugin to our app using the
app.use() function, which we can find at the top of our
We at Jovo are really excited to see, which kind of plugins our community comes up with. By the way, the first ever Jovo plugin was created by Cellular.