Middleware hooks are the easiest way to extend certain parts of the Jovo Framework. You can see them as a lightweigt version of Jovo Plugins.
Watch the video here:
Jovo Hooks allow you to "hook" into
middlewares of the Jovo Architecture.
Here is how a hook could look like:
Here is a list of all available middlewares:
||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.|
Each middleware hook contains of a specified
middleware and an anonymous function that is called with the following parameters:
undefined unless the
fail middleware is used.
error property has the following interface:
The second property is the
host object (Lambda, Azure, ExpressJS, etc.), which has the following interface:
jovo object is the third property, which is the same object you reference inside your handler using
Depending on the middleware you use, the object can be
undefined, since the initialization happens inside the
Each middleware can eiher be accessed by using its name (e.g.
platform.output), or by prepending
after.platform.output) to specify when in the order the hook should be triggered.
For example, the order of
platform.output and the following
response middlewares looks like this:
The anonymous function that you pass into the hook is then called when is is reached in the stack of middlewares.
If you need to do API calls and await them in your hooks, use