Creating a Custom Logger as a Jovo Plugin

Learn how to add a custom logger using the Jovo Plugin feature.

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

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.

See example plugins here.

How Jovo Plugins Work

The plugins work with listeners, which get triggered by certain events. These events range from requests your app gets to image cards you send out as a response. As soon as the listeners gets triggered its code block gets executed.

The events you can create a listener for always have the Jovo object as an argument, which gives you access to all the methods you were able to use inside your handlers. In addition to that you also get specific information for the respective event. The tell event for example comes with the speech String you used. Here’s a list of all the events:

Category Name Method Arguments
Routing request'request') jovo
response'response') jovo
followUpState'followUpState') jovo, state
removeState'removeState') jovo
toIntent'toIntent') jovo, intent
toStateIntent'toStateIntent') jovo, state, intent
toStatelessIntent'toStatelessIntent') jovo, intent
endSession'endSession') jovo
Output tell'tell') jovo, speech
ask'ask') jovo, speech, repromptSpeech
showSimpleCard'showSimpleCard') jovo, title, content
showImageCard'showImageCard') jovo, title, content, imageUrl
showAccountLinkingCard'showAccountLinkingCard') jovo
Error handlerError'handlerError') jovo, error
responseError'responseError') jovo, error

Creating a Custom Logger

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.

To begin with we have to import the plugin class in our app.js file:

To build our own plugin we have to create a class, which extends the base plugin class:

Inside that class we will add a constructor, which will call the parent class' constructor:

Next up is the core part of the plugin. The init() method is the place, where you define the listener functions:

To add a listener we use the following structure:

The first thing we want to log is if the user triggered the Default Fallback Intent as well as how they did it, i.e. the current state and utterance. The request event comes in handy for that. To access the requested intent's name and the user's utterance we can use the getIntentName() and getRawText() functions:

To comprehend how the Default Fallback Intent was triggered we will also log our applications output. But we don't want to log every output, so instead of directly logging to the console everytime the ask event occurs, we will save the content of it to a variable instead, which we define in init():

We can now modify the request listener to log the content of output as well, by adding the stuff we wanted to log in request to output:

That's our logger. The last thing left to do is the registration of the plugin:

You can test the plugin either locally, where it will we logged to your console, or on Lambda, which stores the logs on Cloudwatch. Here's an example how the logs might look like:

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.

Any questions? Please let us know in the comments below 👇. You can also reach us on Twitter or Slack.

Kaan Kilic

Technical Content Marketing Associate at Jovo

Comments and Questions

Any specific questions? Just drop them below. Alternatively, you can also fill out this feedback form. Thank you!

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.