Sometimes you may need a specific feature according to your needs and you want to build your particular plugin that doesn't exist yet. In order to achieve this, we have to review some important aspects.
- You can create your own plugins to be used locally in your project or as a npm package.
- Each plugin have to implement the methods we describe in this guideline.
Every plugin you create for botonic has to be under a directory named:
In addition, the plugin directory has to be structured in the following way:
The required fields in your package.json must be the following:
- name: we suggest you to put the same name as the directory, for simplicity and maintainability.
- version: the corresponding plugin's version, starting by 0.0.1.
- main: the entry point of your plugin. We suggest you to mantain the structure as it is.
- dependencies: your dependencies, if any.
- devDependencies: your devDependencies, if any.
How to Create a Plugin?
For a better understanding, we will start with the most essential parts our plugin must have.
In order to develop a plugin for Botonic, you will have to create a new directory structured as explained before. Once created, you will have to copy this boilerplate code in your
As can be seen, in our plugin we will have three basic methods:
constructor: which will be used in order to pass to our plugin the necessary options (JS Objects) needed to run our code, such as tokens, authentication keys, etc.
pre: stands for all these kind of operations that we want to preprocess of our input, such as applying NLU to extract intents or entities.
post: stands for all these kind of operations that we want to process ex-post, such as adding a tracking id to our session.
Botonic will look for pre and post methods and will execute them before or after the input is processed, correspondingly.
Note: It's crucial that
post methods are declared with the async keyword for an expected behaviour.
Let's take a closer look at Botonic LUIS Plugin:
That's all! Once you have implemented your plugin, you are ready to use it.