Skip to main content

Node-RED LinTO Framework

LinTO-Components repository contains the framework code for building LinTO Bricks that would plug into Node-Red. It enables its users to develop LinTO compatible skills, leveraging a set of base Node JS classes inside their own code.

Here's a list of the main types of components

  • Nodes : Default classes for a desired type of Node-red node (CoreNode, DictionaryNode, SkillNode...)
  • Components : Utility toolbox for LinTO (classes, inheritance...)
  • Connect : Defferents means of feeding LinTO Node-Red nodes with Events, Wires...
  • Exception : Exceptions related to linto-components
tip

This documentation is pretty rough, you might dig in the code of provided LinTO-skills, templates and examples to understand how it works

Installation

danger

Eventhough this NPM module can be installed in any Node-Red instance with npm i @linto-ai/linto-components -s, you're much rather willing to install a complete LinTO platform server in order to use the provided features.

Nodes

The component Nodes regroups specific nodes for LinTO, those will be available in the LinTO-Admin Node-Red interface as palette drag'n drop bricks.

Here's a list of all type of Node-red nodes offered by the linto-components package :

  • Node
  • Core-Node
  • Core-Event-Node
  • Dictionary-Node
  • Skill-Node

Node types :

LinTO-Node is the classic Node-RED's style drag'n dropable node, loaded for LinTO needs.
const  LintoNode = require('linto-components').nodes.lintoNode
class MyLintoNode extends LintoNode {
constructor(RED, node, config) {
super(node, config)
...
}
}

Payload toolboxes

Those are generic utility tools to use within your custom skills and work with specific LinTO Typed payloads into Node-Red

Components specs and usage :

Toolbox that provide utility function to read the payload generated by the node linto-red-event-emitter

const { payloadAction } = require('linto-components').components
...
//In constructor class
this.payloadAction = payloadAction

Methods

extractEntityFromPrefix
Search the first entity in the payload matching the searched prefix

Arguments :

{Object} payload : input message
{String} searchedPrefix : searched prefix
{Object} : Return, extracted entity from the payload, else undefined

extractEntityFromName
Search the first entity in the payload matching the searched name

Arguments :

{Object} payload : input message
{String} searchedName : searched name entity
{Object} : Return, extracted entity from the payload, else undefined

checkEntitiesRequire
Check if all required entities are provided by the payload

Arguments :

{Object} payload : input message
{Array{string}} requireEntities : required entities
{Boolean} : Return, true if required entities are found in the payload, else false

checkEntityRequire
Check if one entity required is provided by the payload

Arguments :

{Object} payload : input message
{Array{string}} searchedPrefix : required prefix of entities
{Boolean} : Return, true if one entity require are find, else false

Connect

Component allowing different external communication

Connect specs and usage :

Toolbox that handle different MQTT functionalities

const { mqtt } = require('linto-components').connect
...
// In constructor class
this.mqtt = new mqtt(this)
...
// After component initialisation, mqtt config can be found if the flow has setup a linto-config node
let mqttConfig = this.getFlowConfig('confMqtt')

Methods

connect
Connect to the specified host:port

Arguments :

{Object} flowMqttConfig : MQTT information (host, port, user, password)
{Promise} : Return, mqtt client connected.

onMessage
Trigger the handled function on the desired topic when a mqtt message has been receive

Arguments :

{Object} handler : Function to trigger on mqtt message
{String} topicFilter : Topic to trigger on mqtt message
publish
Publish a message to a desired mqtt topic

Arguments :

{String} topic : Topic to publish
{Object} payload : Json payload to send
subscribeToLinto
Subscribe to a LinTO topic

Arguments :

{String} topicScope : Scope to subscribe
{Array{string}} ids : List of ids to subscribe (can be + for all LinTO)
{String} topicActi

Exceptions

Exception raised by Connect component

const { HostUndefined, TopicScopeUndefined, WrongFormat } = require('linto-components').exception.connectException
...
throw new HostUndefined(exceptionMessage)
throw new TopicScopeUndefined(exceptionMessage)
throw new WrongFormat(exceptionMessage)