Skip to content

Custom nodes

Klervi edited this page Jul 3, 2019 · 5 revisions


Best practices for developers using VISEO Bot Maker.

Naming and Scope

  • All packages should be named node-red-contrib-viseo-* to scope and find libraries.
  • Packages should define a big features (like a MongoDB Node) or set of REST Services (like Microsoft Cognitive Services)

The implementation between Microsoft Computer Vision and Microsoft LUIS is really close whereas Google Computer vision is far from Microsoft implementation. So node-red-contrib-viseo-microsoft and node-red-contrib-viseo-google is better than node-red-contrib-viseo-computervision

Input / Ouputs

Nodes properties should be dynamic and set/get the data from the flow. Node Helper library provides setByString() and getByString() function to work with deep data.

  let property = helper.getByString(data, 'path.to[3].property', 'default')

Node Message from BotBuilder package has improved features (see marshall()) :

  • search/replace all message {with.properties} text using helper.resolve()
  • translate all properties in curent bot language
  • use Mustache some {{{mustach code}}} here

Versioning

There are several reasons why you would want to version your project. It enables you to keep track of the history of your flow and nodes, it acts as a backup and it will facilitate publishing actions.

We currently use a Git server but you could use any other type of versioning system.

cd pathtomybot
git init
git remote add origin user@gitserver.com:yourrepository.git

The command line above assumes you have ssh access to the git server "gitserver.com" with the username "user" (On GitHub, it would be git@github.com:myaccount/myrepository.git).

You should set git to ignore automatically generated/downloaded files. Create the .gitignore file and insert the following lines:

node_modules

data/.*
data/*.db
data/*.log

Now you can add your files to your repository and push to the server.

git add .
git commit -m "Initial commit"
git push -u origin master

Environment based configuration

You might want your configurations to adapt to the environment your project runs under. For example if you use NLP nodes, you would want all your NLP nodes to use the same NLP configuration but this configuration should be different from DEV to PROD to avoid conflicts between versions.

To handle that we take advantage of the credentials feature of Node-RED. Credentials are loaded in their own file (not flows.json) and the VISEO Bot Maker choses this file depending on the NODE_ENV environment variable.

Let's say you have run your project under dev and prod, you should find in your data directory:

  • flows_cred_dev.json
  • flows_cred_prod.json

Any new environment you would want to run your project under, a new empty file will be created for credentials and you will need to write it through the Node-RED web interface.

Node that these credentials will be encrypted using your credential secret and we advise you to use a different secret for each environment

Please read the documentation for credentials in Node-RED for further explanation about credentials specificities.

Getting Started

Clone this wiki locally