Node-RED and Twitter Demo

In this post we are going to see a demo using Node-RED integrated with Sofia2 Platform, we will also use a third-party API, Twitter.

The demo consist of a small device that works as a bot, we will call this service through Twitter, sending a tweet with a weather query about a specific Spanish city. The service, programmed in Node-RED, after consulting the real time weather save the information in Sofia2 Platform, which will trigger the second part of the flow, which consists of the answer from Sofia2 user Twitter whit the weather information.

node1.PNG

As you can see in the image, we have a flow which consist in two parts:

  • First part: triggers when a tweet comes in, it consults the weather of the city and save this information in Sofia2 Platform.
  • Second part: triggers when the information is saved in Sofia2 Platform, the tweet answer is built and sent to Twitter.

We are going to perform a superficial analysis of the nodes used in the flow, we will analyze more in depth those nodes that are proper to Sofia2:

  • Twitter: allows us to listen to the tweets directed to a certain user or those identified with certain hashtags.
  • Process Twitter data: Node of type function that parse the obtained data of the previous node, in concrete we obtain the user who has generated the tweet and hashtags.
  • Openweathermap: node in charge of consulting the meteorological information in real time.
  • Sofia2-kp-insert: It is an own node of Sofia2 Platform that stores the information in an ontology. First, we have to create an ontology and generate the token. The token will be a parameter that we will configure in the node, whereas the ontology and the data that we want to save will be parameters that we will pass through the object msg of the following form:
    • msg.ontology: name of the ontology
    • msg.payload: information that we want to sabe in the ontology, it will always have to be a JSON format and comply with the ontology schema.

node2.PNG

  • Ssap-process-request: it is another own node of Sofia2 Platform that is in charge of monitoring the queries made on an ontology and we configure it as follows:
    • Message direction: it can be input or output, in this case it is input because it is the input of this part of the flow.
    • Message type: here we can choose the message type that we want to monitor, in this case the flow will trigger when it is insert type.
    • Ontology: name of the ontology we want to monitor.
    • KP instance: KP instance.

node3.PNG

  • ParseDatos: Node type function that parse the data obtained from the query and builds the response message to be published on Twitter.
  • Twitter: We end up with another Twitter node, in this case an output one. We post the message on the Twitter account.

Below you can see a video explaining this demo:

Node-RED and Twitter Demo

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s