Final Re-Tweet Code for my Node-RED application on BlueMix (updated)

If you have been following my blog and more specifically my Twitter account in the past week you probably noticed an awful lot of re-tweets in the past week. Well, if you just happen to have missed my original video where I created a simple Node-RED application to automatically retweet and promote “bluemix” on Twitter feel free to get some context here and watch the video.

This is the final flow after some debugging and watching the different retweets happening:

 

It wouldn’t be fair if I didn’t give out the flow code so I check it out below. Really, there would be two things you would want to change:

1. The search string in the very first Twitter box to the terms you want to automatically promote – take a look at what I have configured:

Screen Shot 2014-06-30 at 11.56.18 PM

You can see I am pretty much promoting all tweets related to “bluemix” and “node-red”.

2. You will also want to change the filter code in the switch block titles “Doesn’t Contain bobbalfe or RT or band language“, I filter out “bobbalfe” and a few swear words as to not retweet inappropriate language (I am sure there are many more words I should filter out).

Screen Shot 2014-06-30 at 11.57.40 PM

3. Depending on your language, you might also want to change the language filter I have in place. This only lets English through and drops the other tweets:

Screen Shot 2014-07-01 at 12.00.27 AM

Node-RED Flow Code:

[codesyntax lang=”javascript”]

[
   {
      "id":"f385a130.0c7a6",
      "type":"twitter in",
      "twitter":"",
      "tags":"bluemix,#node-red",
      "user":"false",
      "name":"Promote BlueMix",
      "topic":"tweets",
      "x":75,
      "y":105,
      "z":"dcd52062.232ae",
      "wires":[
         [
            "c76ce2bc.38932",
            "de6904d0.2196f8"
         ]
      ]
   },
   {
      "id":"82479b9e.7db868",
      "type":"function",
      "name":"Change to a Retweet",
      "func":"var topic = msg.topic.replace("tweets/","@");nmsg.payload = " RT: " + topic + "-" + msg.payload;nreturn msg;",
      "outputs":1,
      "x":762,
      "y":192,
      "z":"dcd52062.232ae",
      "wires":[
         [
            "90883b1b.6f77c8"
         ]
      ]
   },
   {
      "id":"4d87823c.b2787c",
      "type":"debug",
      "name":"",
      "active":true,
      "console":"false",
      "complete":"false",
      "x":1022,
      "y":423,
      "z":"dcd52062.232ae",
      "wires":[

      ]
   },
   {
      "id":"c387ff63.3c78",
      "type":"switch",
      "name":"Doesn't Contain RT or band language",
      "property":"payload",
      "rules":[
         {
            "t":"cont",
            "v":"RT"
         },
         {
            "t":"cont",
            "v":"shit"
         },
         {
            "t":"cont",
            "v":"fuck"
         },
         {
            "t":"cont",
            "v":"crap"
         },
         {
            "t":"else"
         }
      ],
      "checkall":"true",
      "outputs":5,
      "x":680,
      "y":85,
      "z":"dcd52062.232ae",
      "wires":[
         [

         ],
         [

         ],
         [

         ],
         [

         ],
         [
            "82479b9e.7db868"
         ]
      ]
   },
   {
      "id":"87e6ba96.781948",
      "type":"twitter out",
      "twitter":"",
      "name":"Tweet",
      "x":1025,
      "y":349,
      "z":"dcd52062.232ae",
      "wires":[

      ]
   },
   {
      "id":"9d555875.62aaa8",
      "type":"switch",
      "name":"Less than 140 characters",
      "property":"payload.length",
      "rules":[
         {
            "t":"lt",
            "v":141,
            "v2":0
         },
         {
            "t":"else"
         }
      ],
      "checkall":"true",
      "outputs":2,
      "x":772,
      "y":401,
      "z":"dcd52062.232ae",
      "wires":[
         [
            "4d87823c.b2787c",
            "87e6ba96.781948"
         ],
         [

         ]
      ]
   },
   {
      "id":"b6b4c899.494b38",
      "type":"switch",
      "name":"English Only",
      "property":"lang",
      "rules":[
         {
            "t":"eq",
            "v":"en"
         },
         {
            "t":"else"
         }
      ],
      "checkall":"true",
      "outputs":2,
      "x":452,
      "y":94,
      "z":"dcd52062.232ae",
      "wires":[
         [
            "c387ff63.3c78"
         ],
         [

         ]
      ]
   },
   {
      "id":"c76ce2bc.38932",
      "type":"debug",
      "name":"",
      "active":false,
      "console":"false",
      "complete":"true",
      "x":277,
      "y":243,
      "z":"dcd52062.232ae",
      "wires":[

      ]
   },
   {
      "id":"90883b1b.6f77c8",
      "type":"delay",
      "name":"Only 10 per hour",
      "pauseType":"rate",
      "timeout":"10",
      "timeoutUnits":"hours",
      "rate":"5",
      "rateUnits":"hour",
      "randomFirst":"1",
      "randomLast":"5",
      "randomUnits":"seconds",
      "drop":true,
      "x":755,
      "y":263,
      "z":"dcd52062.232ae",
      "wires":[
         [
            "9d555875.62aaa8"
         ]
      ]
   },
   {
      "id":"de6904d0.2196f8",
      "type":"switch",
      "name":"Doesn't contain bobbalfe ",
      "property":"topic",
      "rules":[
         {
            "t":"cont",
            "v":"bobbalfe"
         },
         {
            "t":"else"
         }
      ],
      "checkall":"true",
      "outputs":2,
      "x":275,
      "y":51,
      "z":"dcd52062.232ae",
      "wires":[
         [

         ],
         [
            "b6b4c899.494b38"
         ]
      ]
   }
]

[/codesyntax]

BlueMixBeta

One thought on “Final Re-Tweet Code for my Node-RED application on BlueMix (updated)

  1. Pingback: (Very simple) Thoughts on Meta-data | Cloudy with SaaS-Shine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s