Intent action over MQTT for JavaScript usage

#1

Hello,

I created some intents and now I need to add some actions. The issue is that currently, you only can write some Python2/Python3 code.

I like to write JavaScript/NodeJs stuff like this:
https://snips.gitbook.io/tutorials/t/technical-guides/listening-to-intents-over-mqtt-using-javascript

So how do I create an action that just sends the data through the network via MQTT so I can run some listening script (like in the article) to do some actions.

How simpler: How can I avoid to write Python (no idea of that language) and just use something like NodeJs?

#2

It sounds like hermes-javascript is what you’re looking for.

#3

Hi comparat,

I suggest you to use this tool to develop an app in Node or this one to develop in Typescript. This will allow you to generate a basic template, which already includes hermes-javascript.

If you want an example, I’m developing an app in Typescript right now. Be careful though, it’s really WIP.

#4

Does anyone use Node-Red to program Apps ???

1 Like
#5

We are talking about Node.js and TypeScript :wink:

#6

sorry if I’m off topic, but as Node-RED is based on NodeJS I did not think off topic … so I leave you to your topic

#7

It’s a bit confusing like this what you’re actually asking :slight_smile: Maybe you should have opened a separate topic for your question about Node-RED.

I can find at least one person that tried to have Node-RED talking to Snips.

#8

ok i do that… thanks…

#9

Well. I hope I understand this correctly.

I want my speech assistent in the same network and it get’s automatically distributed via MQTT?

Or easier: Do I need to add an action inside the Snips Console or is it enough to just use the hermes-javascript library?

I want this system (the seeed kit) in my local network and on my Mac, I want to use JavaScript to handle all the input from the kit. How would I do this?

#10

Hi,

I refer you to the documentation on actions. You can develop actions for your intents using many different languages, including Javascript (Node). Forget about writing actions inside the console, it’s only for Python (Python snippets).

#11

Ok. So inside the Console, I set actions to None.

And then I install something like MQTT.js on my Mac and run it and it should listen to anything, as long as the Kit and my Mac are on the same network?

Do I understand this correctly?

#12

Exactly, you set the actions to none in the console, and your node app embedding hermes-javascript (what we call the action code) will listen for MQTT messages.

If both the assistant and the app are running on a Raspberry or on your Mac, that’s it, as the MQTT broker is local. If you want to install the assistant on your Raspberry Pi and the app on your Mac, the latter should listen to an external MQTT broker. In this case, provide the address option when initializing the Hermes object. Have a look at the Hermes class section !

#13

Thanks for the answers!

Whats the difference between hermes-javascript package and MQTT.js?

#14

hermes-javascript is a library written by Snips. It abstracts away the connection to the MQTT bus and provides the protocol used to communicate with the platform (named Hermes). I let you read the README to get an overview of all the features!

#15

Hi comparat and Thomas

Sorry for hijacking this thread but it seemed relevant to my problem. I’m on windows and trying to install / get working the Hermes-javascript npm package with no luck. It creates various files in the temp release directory but not the file it needs - libhermes_mqtt_ffi.dll

Any help would be greatly appreciated.
Peter

#16

Hi @TheFusionWorks,

[edit: answered in another thread ]

Windows is an unsupported platform at the moment. Here is the link to the documentation that explains the behaviour in this case: https://github.com/snipsco/hermes-protocol/tree/develop/platforms/hermes-javascript#️-unsupported-platforms--architectures

The post-install script will try to download the sources in the temp directory and build the library. As written in the doc., you’ll need to have rust and git installed in order for this step to complete successfully.

Is there any line printed in the logs related to your issue while running npm i hermes-javascript? If so, could you share them?

#17

@elbywan - thanks for answering in:

1 Like