npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jovo-v4-community-plugin-jexl-output

v0.0.16

Published

A Jovo V4 framework plugin which adds Jexl support for output strings.

Downloads

20

Readme

Jexl Output Plugin for Jovo V4

NPM

Overview

This plugin for the Jovo V4 Framework allows you to use Jexl expressions within your output strings.

What is Jexl you ask? Jexl describes itself as "Javascript Expression Language: Powerful context-based expression parser and evaluator".

To start with a very basic example: Jexl expressions within strings look like "${1+1}". This would be evaluated to a string looking like "2". This looks trivial but when you learn that you can access the Jovo context using variables while support for libraries with Math expressions and Voca is included out of the box you might understand that soon you can do a lot more.

The plugin searches all Jexl expressions within your "message" and "reprompt" entries and will replace those with the evaluated result.

If there is no Jexl expression the string remains unchanged.

The resulting string is the utterance the user will receive from the system.

What does Jexl look like?

As said above Jexl expressions within strings look like "${ some jexl expression }". When using variables which have access to the Jovo context you can do a lot more. You should definitely visit the Jexl Homepage to understand the syntax options and possibilities.

Let us have a look at some examples:

Examples

  • You have access to the complete set of functions of the JavaScript Math Library: "${ Math.max(1,2) }".

  • This includes nested expressions: "Let me throw a dice for you. This time your magic number is ${Math.round(Math.random()*6)+1}."

You have access to the Jovo environment (details further below):

  • Access the input values from the conversation: "You chose color ${$input.text}. Like a ${ $input.text == 'red' ? 'rose' : $input.text == 'green' ? 'cucumber' : 'rainbow'}"

  • Access the Jovo session: "${$session.isNew ? 'Welcome stranger! ' : 'So here we launch again: '}"

  • Access device specific information "${ 'SCREEN' in $device.capabilities ? 'Your device seems to have a screen.' : 'Your device does not have a screen'}",

  • You also have access to the request object: "You seem to be located somewhere near ${$request.timeZone}"

  • Access the user object: "${ $user.createdAt}"

And there is more:

  • Use the power of the Voca string library: "Your utterance read backwards sounds like this: ${Voca.reverse($input.text)}"

List of supported libraries and environment variables

When using Jexl expressions you have access to the following libraries and environment variables:

  Math: Javascript Math Library
  Voca: Javascript Voca String Library
  $component: jovo.$component,
  $data: jovo.$data,
  $device: jovo.$device,
  $entities: jovo.$entities,
  $input: jovo.$input,
  $request: jovo.$request,
  $route: jovo.$route,
  $session: jovo.$session,
  $state: jovo.$state,
  $user: jovo.$user,
  $platform: jovo.$platform

Why should I use Jexl?

Using this plugin your strings become more powerful. The examples above show how to solve simple use cases that would otherwise require coding in your backend.

If you maintain your strings via a Voice CMS you may even be able to change the behaviour of your application without modifications to the code. This may be useful, but there is a warning required: you can shoot yourself in the foot when you decide to give content maintainers access to business logic!

Install

Install the plugin into your Jovo project:

npm install jovo-v4-community-plugin-jexl-output --save

Register the plugin in:

app.js:

const { JexlOutputPlugin } = require("jovo-v4-community-plugin-jexl-output");

app.use(
  // ... base imports
  new JexlOutputPlugin()
);

app.ts:

import { JexlOutputPlugin } from "jovo-v4-community-plugin-jexl-output";
app.use(
  // ... base imports
  new JexlOutputPlugin()
);

How to start

Replace your whatever WELCOME_MESSAGE with something like:

"Your magic number today is ${Math.round(Math.random()*6)+1}".

Now launch your voice app/skill/action multiple times.

Notice the magic?

License

Apache V2