Last active
April 18, 2016 14:37
-
-
Save g00glen00b/bd9277d79df24939b0d4 to your computer and use it in GitHub Desktop.
Node-RED Slack bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "1525b4f4.eada4b", | |
"type": "function", | |
"name": "Chuck Norris Slack message", | |
"func": "var text = {\n text: msg.payload,\n username: \"Chuck Norris\",\n icon_url: \"http:\/\/static-files1.modthesims2.com\/customavatars\/avatar7265094_1.gif\"\n};\nreturn {\n payload: JSON.stringify(text)\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 1110.6667137146, | |
"y": 589.99998188019, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"ef2b5caa.10d4a" | |
] | |
] | |
}, | |
{ | |
"id": "6afaa4c6.95055c", | |
"type": "http in", | |
"name": "Slack HTTP in", | |
"url": "\/slack", | |
"method": "post", | |
"x": 139, | |
"y": 20, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"bb728427.448d78", | |
"5afd2d0b.a502d4" | |
] | |
] | |
}, | |
{ | |
"id": "5afd2d0b.a502d4", | |
"type": "debug", | |
"name": "Debug messages", | |
"active": true, | |
"console": "false", | |
"complete": "true", | |
"x": 879, | |
"y": 44, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
] | |
}, | |
{ | |
"id": "e28c7f8c.1d738", | |
"type": "watson-question-answer", | |
"name": "Travel agent", | |
"output": "top", | |
"corpus": "travel", | |
"x": 579.66664886475, | |
"y": 161.66666221619, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"b945d492.46ba28" | |
] | |
] | |
}, | |
{ | |
"id": "cd79b018.32865", | |
"type": "function", | |
"name": "Real payload filter", | |
"func": "var msg = msg.payload.text;\nreturn {\n payload: msg.replace(\/^!travel\\s*\/, \"\")\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 340, | |
"y": 158, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"e28c7f8c.1d738" | |
] | |
] | |
}, | |
{ | |
"id": "ef2b5caa.10d4a", | |
"type": "http request", | |
"name": "Slack response", | |
"method": "POST", | |
"ret": "txt", | |
"url": "https:\/\/hooks.slack.com\/services\/<OBTAIN YOUR OWN WEBHOOK>", | |
"x": 1453, | |
"y": 202, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
] | |
] | |
}, | |
{ | |
"id": "b945d492.46ba28", | |
"type": "function", | |
"name": "Watson Slack message", | |
"func": "var text = {\n text: msg.payload,\n username: \"Watson\",\n icon_url: \"http:\/\/cdgd.com\/img\/uploads\/work\/corporate\/watson\/cdetorres_hero_05.png\"\n};\nreturn {\n payload: JSON.stringify(text)\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 1237, | |
"y": 201, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"ef2b5caa.10d4a" | |
] | |
] | |
}, | |
{ | |
"id": "bb728427.448d78", | |
"type": "switch", | |
"name": "Command parser", | |
"property": "payload.text", | |
"rules": [ | |
{ | |
"t": "regex", | |
"v": "^!travel" | |
}, | |
{ | |
"t": "regex", | |
"v": "^!personality" | |
}, | |
{ | |
"t": "regex", | |
"v": "^!sentiment" | |
}, | |
{ | |
"t": "regex", | |
"v": "^!chuck" | |
}, | |
{ | |
"t": "regex", | |
"v": "^!yoda" | |
}, | |
{ | |
"t": "regex", | |
"v": "^!coin" | |
}, | |
{ | |
"t": "else" | |
} | |
], | |
"checkall": "false", | |
"outputs": 7, | |
"x": 87.5, | |
"y": 183, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"cd79b018.32865" | |
], | |
[ | |
"c4d448e2.3b2bb8" | |
], | |
[ | |
"ee8a9000.11757" | |
], | |
[ | |
"d2d7d559.2d2828" | |
], | |
[ | |
"519ce6dc.ae6318" | |
], | |
[ | |
"4b7ecb72.b48134" | |
], | |
[ | |
"14c1340f.eb3ecc" | |
] | |
] | |
}, | |
{ | |
"id": "14c1340f.eb3ecc", | |
"type": "cloudant out", | |
"service": "testslackbluemix-cloudantNoSQLDB", | |
"cloudant": "", | |
"name": "Store messages", | |
"database": "messages", | |
"payonly": true, | |
"operation": "insert", | |
"x": 131.25, | |
"y": 724.75, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
] | |
}, | |
{ | |
"id": "c4d448e2.3b2bb8", | |
"type": "function", | |
"name": "Find by user", | |
"func": "return {\n payload: \"username:\" + msg.payload.username\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 324.25, | |
"y": 202, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"90cd2210.6f32e" | |
] | |
] | |
}, | |
{ | |
"id": "90cd2210.6f32e", | |
"type": "cloudant in", | |
"service": "testslackbluemix-cloudantNoSQLDB", | |
"cloudant": "", | |
"name": "Find messages of user", | |
"database": "messages", | |
"search": "_all_", | |
"design": "", | |
"index": "", | |
"x": 497.50003051758, | |
"y": 240.5, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"f19e332c.0e61d" | |
] | |
] | |
}, | |
{ | |
"id": "7c3c21ad.83c3e", | |
"type": "watson-personality-insights", | |
"name": "", | |
"x": 886.5, | |
"y": 310.75, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"9f0fa104.60f06" | |
] | |
] | |
}, | |
{ | |
"id": "f19e332c.0e61d", | |
"type": "function", | |
"name": "Messages to payload", | |
"func": "var messagesStr = \"\";\nif (msg.payload != null) {\n for (var idx = 0; idx < msg.payload.length; idx++) {\n messagesStr += msg.payload[idx].text;\n messagesStr += \" \";\n }\n}\nreturn {\n payload: messagesStr\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 698.25, | |
"y": 274.75, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"7c3c21ad.83c3e" | |
] | |
] | |
}, | |
{ | |
"id": "9f0fa104.60f06", | |
"type": "function", | |
"name": "Insights message payload", | |
"func": "function getInsights(insights, min) {\n var data = {\n personality: \"\",\n needs: \"\",\n values: \"\"\n };\n for (var idx = 0; idx < insights.length; idx++) {\n var insight = insights[idx];\n if (insight.percentage != null && insight.percentage > min && insight.percentage < 1) {\n data[insight.category] += insight.name + \": \" + Math.round(insight.percentage * 100, 0) + \"%, \";\n }\n if (insight.children != null) {\n var children = getInsights(insight.children, min); \n data.personality += children.personality;\n data.needs += children.needs;\n data.values += children.values;\n }\n }\n return data;\n}\n\nvar data = getInsights(msg.insights.children, 0.5);\nvar msg = \"*Personality*:\\r\\n \" + data.personality.substring(0, data.personality.length - 2);\nmsg += \"\\r\\n*Needs*:\\r\\n \" + data.needs.substring(0, data.needs.length - 2);\nmsg += \"\\r\\n*Values*:\\r\\n \" + data.values.substring(0, data.values.length - 2);\n\nreturn {\n payload: msg\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 1081, | |
"y": 359, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"b945d492.46ba28" | |
] | |
] | |
}, | |
{ | |
"id": "ee8a9000.11757", | |
"type": "function", | |
"name": "Find by user", | |
"func": "return {\n payload: \"username:\" + msg.payload.username\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 312, | |
"y": 302, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"70ca2053.8f35e" | |
] | |
] | |
}, | |
{ | |
"id": "70ca2053.8f35e", | |
"type": "cloudant in", | |
"service": "testslackbluemix-cloudantNoSQLDB", | |
"cloudant": "", | |
"name": "Find messages of user", | |
"database": "messages", | |
"search": "_all_", | |
"design": "", | |
"index": "", | |
"x": 482, | |
"y": 366, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"f46c4346.0b93c" | |
] | |
] | |
}, | |
{ | |
"id": "f46c4346.0b93c", | |
"type": "function", | |
"name": "Messages to payload", | |
"func": "var messagesStr = \"\";\nif (msg.payload != null) {\n for (var idx = 0; idx < msg.payload.length; idx++) {\n messagesStr += msg.payload[idx].text;\n messagesStr += \" \";\n }\n}\nreturn {\n payload: messagesStr\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 688, | |
"y": 408, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"ad6f09f2.5290f8" | |
] | |
] | |
}, | |
{ | |
"id": "ad6f09f2.5290f8", | |
"type": "sentiment", | |
"name": "", | |
"x": 876, | |
"y": 452, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"22f05a35.dd0fa6" | |
] | |
] | |
}, | |
{ | |
"id": "22f05a35.dd0fa6", | |
"type": "function", | |
"name": "Sentiment message formatter", | |
"func": "return {\n payload: \"Sentiment score: \" + msg.sentiment.score\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 1086, | |
"y": 494, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"b945d492.46ba28" | |
] | |
] | |
}, | |
{ | |
"id": "d2d7d559.2d2828", | |
"type": "http request", | |
"name": "Random Chuck Norris quote", | |
"method": "GET", | |
"ret": "obj", | |
"url": "http:\/\/api.icndb.com\/jokes\/random", | |
"x": 368, | |
"y": 476, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"6bfec463.94013c" | |
] | |
] | |
}, | |
{ | |
"id": "6bfec463.94013c", | |
"type": "function", | |
"name": "Chuck Norris message formatter", | |
"func": "return {\n payload: msg.payload.value.joke\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 644, | |
"y": 524, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"1525b4f4.eada4b" | |
] | |
] | |
}, | |
{ | |
"id": "519ce6dc.ae6318", | |
"type": "function", | |
"name": "Real payload filter", | |
"func": "var msg = msg.payload.text;\nreturn {\n payload: msg.replace(\/^!yoda\\s*\/, \"\")\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 308, | |
"y": 572, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"6db1d8a1.924e28" | |
] | |
] | |
}, | |
{ | |
"id": "bed9d64f.412628", | |
"type": "http request", | |
"name": "Yoda speak", | |
"method": "use", | |
"ret": "txt", | |
"url": "", | |
"x": 754, | |
"y": 652, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"bc8fe2ed.43702" | |
] | |
] | |
}, | |
{ | |
"id": "6db1d8a1.924e28", | |
"type": "function", | |
"name": "Yoda speak HTTP converter", | |
"func": "return {\n url: \"https:\/\/yoda.p.mashape.com\/yoda?sentence=\" + encodeURIComponent(msg.payload),\n method: \"GET\",\n headers: {\n \"X-Mashape-Key\": \"<REPLACE WITH REAL KEY>\",\n \"Content-Type\": \"text\/plain\",\n \"Accept\": \"text\/plain\"\n }\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 532, | |
"y": 624, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"bed9d64f.412628" | |
] | |
] | |
}, | |
{ | |
"id": "bc8fe2ed.43702", | |
"type": "function", | |
"name": "Yoda Slack converter", | |
"func": "var text = {\n text: msg.payload,\n username: \"Yoda\",\n icon_url: \"http:\/\/www.forumbiodiversity.com\/image.php?u=10281&dateline=1353837210\"\n};\nreturn {\n payload: JSON.stringify(text)\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 1050, | |
"y": 686, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"ef2b5caa.10d4a" | |
] | |
] | |
}, | |
{ | |
"id": "4b7ecb72.b48134", | |
"type": "function", | |
"name": "Real payload filter", | |
"func": "return {\n payload: Math.random() >= 0.5 ? \"Heads\" : \"Tails\"\n};", | |
"outputs": 1, | |
"valid": true, | |
"x": 355, | |
"y": 93.33332824707, | |
"z": "2faebfdf.d0514", | |
"wires": [ | |
[ | |
"b945d492.46ba28" | |
] | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment