Hermes JavaScript

The Hermes Javascript library provides bindings for the Hermes protocol that Snips components use to communicate together. Hermes Javascript allows you to interface seamlessly with the Snips platform and create voice applications with ease!

Hermes Javascript abstracts away the connection to the MQTT bus and the parsing of incoming and outgoing messages from and to the components of the platform and provides a high-level API as well.

Installation

Prerequisites

To install Hermes Javascript run the following in your terminal:

npm install hermes-javascript

Basic Usage

Hermes Javascript has two ways to interact with the MQTT bus:

  • By sending messages to the Dialogue Manager

  • By subscribing callbacks to events triggered by the Dialogue Manager

Here's a basic code to that listens to the intent myIntent, prints the intent message and use text-to-speech (TTS).

const { withHermes } = require('hermes-javascript')
/*
A small js context manager that sets up an infinite loop to prevent
the process from exiting, and exposes an instance of the Hermes class.
*/
withHermes(hermes => {
// Instantiate a dialog object
const dialog = hermes.dialog()
// Subscribes to intent 'myIntent'
dialog.flow('myIntent', (msg, flow) => {
// Log intent message
console.log(JSON.stringify(msg))
// End the session
flow.end()
// Use text to speech
return `Received message for intent ${myIntent}`
})
})

Video Tutorials

We are working on a end-to-end tutorial of Snips working along with Hermes Javascript. In the meantime, please take advantage of the video tutorials we have prepared 🎥

Writing Action Code

Write Simple Action Code in Javascript

In this video tutorial you will learn how to create simple action code in Javascript using Hermes Javascript.

Prerequisites

Objectives

By the end of the video you will know how to:

  • Initialize your action code folder.

  • Install Hermes Javascript.

  • Listen for a given intent with Hermes Javascript.

  • Access a slot value.

  • Use text-to-speech (TTS).

  • Test your script using the terminal.

Building Interactions

Build a Dialog Flow in Javascript

In order to have more rich interactions with the assistant you need to code the possible dialogs and follow up actions. In this video tutorial you will learn how to do so using Javascript with Hermes Javascript.

Prerequisites

  • Node.js and npm installed.

  • Work on a Raspberry Pi or macOs computer.

  • Have a deployed assistant in your device. Check Create and Deploy a Voice Assistant video tutorial.

  • Have watched Writing Code video tutorial or have basic understanding of Hermes Javascript.

Objectives

By the end of the video you will know how to:

  • Set a simple dialog.

  • Listen for follow-up intents after a recognized intent.

  • Handle not recognized intents

  • Test your script in the terminal

Next Steps

Now that you have a basic comprehension of how Hermes Javascript work, we invite you to check the full documentation in Hermes Javascript documentation. Make sure to check: