# Tweet Dashboard Example

## About this flow&#x20;

In this flow you can visualize the sentiment score of tweets :&#x20;

![](https://1168127261-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ll8Hv_n0TDEU2wd8dWK%2F-Llmqz2ABBVDILMEP6Fo%2F-LlmrP4hhm2FGa4VifPX%2FScreen%20Shot%202019-08-08%20at%204.12.21%20PM.png?alt=media\&token=b2932903-ee47-4968-85d9-a5195d16a1f4)

![](https://1168127261-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ll8Hv_n0TDEU2wd8dWK%2F-Llmqz2ABBVDILMEP6Fo%2F-LlmrRk9FQVk4rl8ydwI%2FScreen%20Shot%202019-08-08%20at%204.12.32%20PM.png?alt=media\&token=159766a2-d34e-4f21-98c8-9279b932a597)

In this flow you will need to configure your twitter API Credentials&#x20;

### Steps to Configure Twitter : &#x20;

The Twitter input node needs an active Twitter ID to gather tweets as data input&#x20;

Double click on the twitter node when you insert it into node red and you will see something like this :&#x20;

![](https://1168127261-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ll8Hv_n0TDEU2wd8dWK%2F-Lm7fz8JhoTRgyIknJto%2F-Lm7t5v5RO0FsXzlMOf4%2FScreen%20Shot%202019-08-12%20at%2010.52.38%20PM.png?alt=media\&token=b72419e7-727f-4147-b830-72e6699134a5)

To set up a new twitter ID click on the pencil button on the side of Twitter ID&#x20;

![](https://1168127261-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ll8Hv_n0TDEU2wd8dWK%2F-Lm7fz8JhoTRgyIknJto%2F-Lm7tBUFsNiGHwJQDF5_%2FScreen%20Shot%202019-08-12%20at%2010.52.56%20PM.png?alt=media\&token=51cd772e-7653-4fa5-abf6-3dd84bd4917d)

You will need an active twitter account and the API Key, API secret key , Access token and Access token secret to set up your account&#x20;

### Go to : [How to create a Twitter application](https://docs.inboundnow.com/guide/create-twitter-application/) to get your keys for Twitter node&#x20;

Once you have your keys from your twitter app you can add the associated info into the Twitter input node!

### Import flow from here :&#x20;

```
[
   {
      "id":"f2ce3087.ee968",
      "type":"tab",
      "label":"Tweet Language ",
      "disabled":false,
      "info":""
   },
   {
      "id":"3b13170a.8b5ba8",
      "type":"inject",
      "z":"f2ce3087.ee968",
      "name":"Happy test",
      "topic":"",
      "payload":"{\"text\":\"every one is awesome\"}",
      "payloadType":"json",
      "repeat":"",
      "crontab":"",
      "once":false,
      "onceDelay":"",
      "x":160,
      "y":140,
      "wires":[
         [
            "1ccd705b.07ca2"
         ]
      ]
   },
   {
      "id":"1ccd705b.07ca2",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"",
      "rules":[
         {
            "t":"set",
            "p":"tweet",
            "pt":"msg",
            "to":"payload",
            "tot":"msg"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":380,
      "y":180,
      "wires":[
         [
            "19037133.924c87"
         ]
      ]
   },
   {
      "id":"62a9afb1.aa101",
      "type":"inject",
      "z":"f2ce3087.ee968",
      "name":"Sadness test",
      "topic":"",
      "payload":"{\"text\":\"This is miserable and sad\"}",
      "payloadType":"json",
      "repeat":"",
      "crontab":"",
      "once":false,
      "onceDelay":"",
      "x":170,
      "y":200,
      "wires":[
         [
            "1ccd705b.07ca2"
         ]
      ]
   },
   {
      "id":"60cfb004.afcc18",
      "type":"inject",
      "z":"f2ce3087.ee968",
      "name":"Angry test",
      "topic":"",
      "payload":"{\"text\":\"I hate this demo\"}",
      "payloadType":"json",
      "repeat":"",
      "crontab":"",
      "once":false,
      "x":180,
      "y":260,
      "wires":[
         [
            "1ccd705b.07ca2"
         ]
      ]
   },
   {
      "id":"e87cc8f9.0d3b1",
      "type":"watson-text-to-speech",
      "z":"f2ce3087.ee968",
      "name":"text to speech",
      "lang":"en-US",
      "langhidden":"en-US",
      "langcustom":"NoCustomisationSetting",
      "langcustomhidden":"",
      "voice":"en-US_AllisonVoice",
      "voicehidden":"es-ES_EnriqueVoice",
      "format":"audio/wav",
      "password":"Go3dEL-Escher-B@ch-climB-0ak5!",
      "apikey":"YptiEGxP7PZK71dQVZq96jBmZZ7Y9KxJcDwYO9Kt5WWp",
      "payload-response":false,
      "default-endpoint":true,
      "service-endpoint":"https://stream.watsonplatform.net/text-to-speech/api",
      "x":840,
      "y":380,
      "wires":[
         [
            "2b50d466.c015dc"
         ]
      ]
   },
   {
      "id":"19037133.924c87",
      "type":"function",
      "z":"f2ce3087.ee968",
      "name":"Remove URLS and replace #",
      "func":"var tweet = msg.tweet.text;\nvar newtweet = tweet.replace(/#/g, \" Hash tag \");\n\n// regex from https://stackoverflow.com/questions/1500260/detect-urls-in-text-with-javascript\nmsg.payload = newtweet.replace( /(([a-z]+:\\/\\/)?(([a-z0-9\\-]+\\.)+([a-z]{2}|biz|com|co|edu|gov|info|net|org|ly))(:[0-9]{1,5})?(\\/[a-z0-9_\\-\\.~]+)*(\\/([a-z0-9_\\-\\.]*)(\\?[a-z0-9+_\\-\\.%=&amp;]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\\s+|$)/gi, \"see short URL \" );\nreturn msg;",
      "outputs":1,
      "noerr":0,
      "x":640,
      "y":160,
      "wires":[
         [
            "7e5ec0f9.bbb5a8",
            "37cf1c8a.bf4d54"
         ]
      ]
   },
   {
      "id":"7e5ec0f9.bbb5a8",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"",
      "active":true,
      "tosidebar":true,
      "console":false,
      "tostatus":false,
      "complete":"false",
      "x":870,
      "y":140,
      "wires":[

      ]
   },
   {
      "id":"dffc23d5.a9663",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"Tone categories",
      "active":true,
      "console":"false",
      "complete":"payload",
      "x":880,
      "y":320,
      "wires":[

      ]
   },
   {
      "id":"9a0f3aa8.923ad",
      "type":"function",
      "z":"f2ce3087.ee968",
      "name":"High Score",
      "func":"var emotions = [];\nemotions = msg.response.document_tone.tone_categories\n                .filter(function(c){\n                    if (c.category_id == \"emotion_tone\")\n                    {return c; }\n                    })[0].tones;\n                    \nvar myscore =  0;\nfor (var i=0; i<emotions.length; i++) {\n    if(emotions[i].score > myscore) {\n        msg.payload = emotions[i].score;\n        msg.topic = emotions[i].tone_name;\n        myscore = emotions[i].score;\n    }\n}\n\nreturn msg;",
      "outputs":1,
      "noerr":0,
      "x":170,
      "y":360,
      "wires":[
         [
            "16df6bd0.9e3004",
            "1f4d73c0.0f3c14"
         ]
      ]
   },
   {
      "id":"16df6bd0.9e3004",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"Score",
      "active":true,
      "console":"false",
      "complete":"topic",
      "x":370,
      "y":360,
      "wires":[

      ]
   },
   {
      "id":"677da65d.953ad8",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"Print msg.response",
      "active":true,
      "console":"false",
      "complete":"response",
      "x":630,
      "y":260,
      "wires":[

      ]
   },
   {
      "id":"37cf1c8a.bf4d54",
      "type":"watson-tone-analyzer-v3",
      "z":"f2ce3087.ee968",
      "name":"Analyze Tone",
      "tones":"emotion",
      "sentences":"true",
      "contentType":"false",
      "tone-method":"generalTone",
      "interface-version":"2016-05-19",
      "default-endpoint":true,
      "service-endpoint":"",
      "x":390,
      "y":280,
      "wires":[
         [
            "9a0f3aa8.923ad",
            "677da65d.953ad8",
            "1d5a2d93.b33b62"
         ]
      ]
   },
   {
      "id":"1d5a2d93.b33b62",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"tone_categories",
      "rules":[
         {
            "t":"set",
            "p":"payload",
            "pt":"msg",
            "to":"response.document_tone.tone_categories",
            "tot":"msg"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":660,
      "y":320,
      "wires":[
         [
            "dffc23d5.a9663"
         ]
      ]
   },
   {
      "id":"1f4d73c0.0f3c14",
      "type":"switch",
      "z":"f2ce3087.ee968",
      "name":"Select Emotion",
      "property":"topic",
      "propertyType":"msg",
      "rules":[
         {
            "t":"eq",
            "v":"Joy",
            "vt":"str"
         },
         {
            "t":"eq",
            "v":"Fear",
            "vt":"str"
         },
         {
            "t":"eq",
            "v":"Sadness",
            "vt":"str"
         },
         {
            "t":"eq",
            "v":"Anger",
            "vt":"str"
         },
         {
            "t":"eq",
            "v":"Disgust",
            "vt":"str"
         }
      ],
      "checkall":"true",
      "repair":false,
      "outputs":5,
      "x":180,
      "y":460,
      "wires":[
         [
            "8b9bb215.7ed26"
         ],
         [
            "3513595e.e6cf3e"
         ],
         [
            "b9003d45.14ee"
         ],
         [
            "6066fca0.647f8c"
         ],
         [
            "554595a.813296c"
         ]
      ]
   },
   {
      "id":"3513595e.e6cf3e",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"Fear",
      "rules":[
         {
            "t":"set",
            "p":"payload",
            "pt":"msg",
            "to":"0,255,0",
            "tot":"str"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":350,
      "y":460,
      "wires":[
         [
            "6328f1ea.22058"
         ]
      ]
   },
   {
      "id":"6066fca0.647f8c",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"Anger",
      "rules":[
         {
            "t":"set",
            "p":"payload",
            "pt":"msg",
            "to":"255,0,0",
            "tot":"str"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":390,
      "y":540,
      "wires":[
         [
            "6328f1ea.22058"
         ]
      ]
   },
   {
      "id":"b9003d45.14ee",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"Sadness",
      "rules":[
         {
            "t":"set",
            "p":"payload",
            "pt":"msg",
            "to":"0,0,255",
            "tot":"str"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":400,
      "y":500,
      "wires":[
         [
            "6328f1ea.22058"
         ]
      ]
   },
   {
      "id":"8b9bb215.7ed26",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"Joy",
      "rules":[
         {
            "t":"set",
            "p":"payload",
            "pt":"msg",
            "to":"255,255,0",
            "tot":"str"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":350,
      "y":420,
      "wires":[
         [
            "6328f1ea.22058"
         ]
      ]
   },
   {
      "id":"554595a.813296c",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"Disgust",
      "rules":[
         {
            "t":"set",
            "p":"payload",
            "pt":"msg",
            "to":"221,160,221",
            "tot":"str"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":360,
      "y":580,
      "wires":[
         [
            "6328f1ea.22058"
         ]
      ]
   },
   {
      "id":"6328f1ea.22058",
      "type":"template",
      "z":"f2ce3087.ee968",
      "name":"Score tweet",
      "field":"payload",
      "fieldType":"msg",
      "format":"handlebars",
      "syntax":"mustache",
      "template":"This tweet expresses {{topic}} - {{tweet.text}}",
      "output":"str",
      "x":530,
      "y":440,
      "wires":[
         [
            "ea37a6d8.dd75d",
            "a60e5015.580b68"
         ]
      ]
   },
   {
      "id":"ea37a6d8.dd75d",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"",
      "active":true,
      "console":"false",
      "complete":"false",
      "x":590,
      "y":500,
      "wires":[

      ]
   },
   {
      "id":"a60e5015.580b68",
      "type":"watson-translator",
      "z":"f2ce3087.ee968",
      "name":"",
      "action":"translate",
      "basemodel":"en-tr",
      "domain":"general",
      "srclang":"en",
      "destlang":"es",
      "password":"pmistry@us.ibm.com",
      "apikey":"PF2WfTPM5NuU0ab5DcMJa7t6wqRP3UXu2hlhoFOnFryv",
      "custom":"",
      "domainhidden":"general",
      "srclanghidden":"en",
      "destlanghidden":"es",
      "basemodelhidden":"en-tr",
      "customhidden":"",
      "filetype":"forcedglossary",
      "trainid":"",
      "lgparams2":true,
      "neural":false,
      "default-endpoint":false,
      "service-endpoint":"",
      "x":630,
      "y":380,
      "wires":[
         [
            "e439f7a5.967798",
            "e87cc8f9.0d3b1"
         ]
      ]
   },
   {
      "id":"e439f7a5.967798",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"",
      "active":true,
      "tosidebar":true,
      "console":false,
      "tostatus":false,
      "complete":"payload",
      "targetType":"msg",
      "x":750,
      "y":460,
      "wires":[

      ]
   },
   {
      "id":"2b50d466.c015dc",
      "type":"change",
      "z":"f2ce3087.ee968",
      "name":"",
      "rules":[
         {
            "t":"set",
            "p":"payload",
            "pt":"msg",
            "to":"speech",
            "tot":"msg"
         }
      ],
      "action":"",
      "property":"",
      "from":"",
      "to":"",
      "reg":false,
      "x":1020,
      "y":380,
      "wires":[
         [
            "66c156b2.7d6878"
         ]
      ]
   },
   {
      "id":"66c156b2.7d6878",
      "type":"play audio",
      "z":"f2ce3087.ee968",
      "name":"",
      "voice":"",
      "x":1190,
      "y":380,
      "wires":[

      ]
   },
   {
      "id":"ca3a3fc7.8605d8",
      "type":"twitter in",
      "z":"f2ce3087.ee968",
      "twitter":"",
      "tags":"",
      "user":"false",
      "name":"Listen to twitter feed",
      "inputs":1,
      "x":190,
      "y":60,
      "wires":[
         [
            "edec68ad.93c13",
            "3cef19cd.214e16",
            "19037133.924c87"
         ]
      ]
   },
   {
      "id":"edec68ad.93c13",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"msg.tweet details",
      "active":true,
      "console":"false",
      "complete":"tweet",
      "x":570,
      "y":20,
      "wires":[

      ]
   },
   {
      "id":"3cef19cd.214e16",
      "type":"debug",
      "z":"f2ce3087.ee968",
      "name":"",
      "active":true,
      "console":"false",
      "complete":"tweet.text",
      "x":560,
      "y":60,
      "wires":[

      ]
   },
   {
      "id":"77693eef.07ad08",
      "type":"comment",
      "z":"f2ce3087.ee968",
      "name":"Pick a #hashtag to follow",
      "info":"",
      "x":200,
      "y":20,
      "wires":[

      ]
   }
]
```

####


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nodered-dashboards.gitbook.io/node-red-dashboards/workshop/tweet-dashboard-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
