General and Google skills of NodeRed script
1.
[{
"id": “3cb91f3b.f9bc”,
"type": “http in”,
"z": “29256dfb.490d62”,
"name": “wiktionary”,
"url": “/api/wiktionary”,
"method": “get”,
"swaggerDoc": “”,
"x": 65,
"y": 146,
"wires": [
[“1e126883.5e8d87”]
]
}, {
"id": “1e126883.5e8d87”,
"type": “function”,
"z": “29256dfb.490d62”,
"name": “Wiktionary”,
"func": “var word = msg.payload.word;\nmsg.url = "https://en.wiktionary.org/api/rest_v1/page/definition/"+word;\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 179,
"y": 77,
"wires": [
[“470d0af2.550e24”]
]
}, {
"id": “470d0af2.550e24”,
"type": “http request”,
"z": “29256dfb.490d62”,
"name": “”,
"method": “GET”,
"ret": “txt”,
"url": “”,
"x": 215,
"y": 203,
"wires": [
[“fc99eaf1.42a158”]
]
}, {
"id": “1b4bfa7.ac8d806”,
"type": “http response”,
"z": “29256dfb.490d62”,
"name": “”,
"x": 754,
"y": 72,
"wires": []
}, {
"id": “c4d0f8a2.29d088”,
"type": “function”,
"z": “29256dfb.490d62”,
"name": “getMeaning”,
"func": “var defineWord=msg.req.query.word;\n\nvar attachment = {\n "template": {\n "type": "generic",\n "content": [{\n "h5": "Wiktionary Details"\n },\n {\n "title": {\n "text": "Wiktionary",\n "link": ""\n }\n },\n {\n "table": {\n "headers": [\n defineWord\n ],\n "rows": []\n }\n }\n ]\n }\n}\n\nvar data = msg.payload;\nvar meaningOfWord = [];\nif (data.en !== undefined) {\n var defineArray = [];\n for (var i = 0; i < data.en.length; i++) {\n var counter = data.en[i];\n meaningOfWord.push(counter.partOfSpeech + ’\n’);\n for (var j = 0; j < counter.definitions.length; j++) {\n var counter1 = counter.definitions[j];\n var define = counter1.definition;\n meaningOfWord.push(’ ’+define+’\n’);\n }\n }\n\n var wordInString = meaningOfWord.join("").toString();\n var stripped = wordInString.replace(/(<([^>]+)>)/ig, " ");\n attachment.template.content[2].table.rows.push([stripped]);\n attachment.template.content[1].title.link = "https://en.wiktionary.org/wiki/"+defineWord;\n\n} else {\n attachment.template.content[2].title.rows.push(["No Meaning"]);\n}\n\nmsg.payload._attachment = attachment;\nnode.send(msg);”,
"outputs": 1,
"noerr": 0,
"x": 442,
"y": 57,
"wires": [
[“4139ff34.e927e”]
]
}, {
"id": “fc99eaf1.42a158”,
"type": “json”,
"z": “29256dfb.490d62”,
"name": “”,
"x": 351,
"y": 157,
"wires": [
[“c4d0f8a2.29d088”]
]
}, {
"id": “4139ff34.e927e”,
"type": “json”,
"z": “29256dfb.490d62”,
"name": “”,
"x": 591,
"y": 78,
"wires": [
[“1b4bfa7.ac8d806”]
]
}]
=============================================
2.
[
{
"id": “cadca2ab.a33d2”,
"type": “http in”,
"z": “dc2174f7.361408”,
"name": “wikipedia”,
"url": “/api/wikipedia”,
"method": “get”,
"swaggerDoc": “”,
"x": 66,
"y": 167,
"wires": [
[
"c98a1cdf.e5e2a"
]
]
},
{
"id": “c98a1cdf.e5e2a”,
"type": “function”,
"z": “dc2174f7.361408”,
"name": “wikipediaApi”,
"func": “var wikiPage = msg.payload.wikiPage;\nmsg.url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles="+wikiPage;\nreturn msg; \n”,
"outputs": 1,
"noerr": 0,
"x": 168,
"y": 81,
"wires": [
[
"dab0cca9.50963"
]
]
},
{
"id": “365ebb60.9600e4”,
"type": “http response”,
"z": “dc2174f7.361408”,
"name": “wikipediaResponse”,
"x": 637,
"y": 207,
"wires": []
},
{
"id": “dab0cca9.50963”,
"type": “http request”,
"z": “dc2174f7.361408”,
"name": “”,
"method": “GET”,
"ret": “txt”,
"url": “”,
"tls": “”,
"x": 269,
"y": 196,
"wires": [
[
"cd42fc1c.a943"
]
]
},
{
"id": “f2dc25f4.c5fb48”,
"type": “function”,
"z": “dc2174f7.361408”,
"name": “extractWikiPage”,
"func": “var data = msg.payload;\nvar extractData = [];\nvar titleName;\n\n\nif (data !== undefined) {\n for (var pageId in data.query.pages) {\n if (data.query.pages.hasOwnProperty(pageId)) {\n extractData.push(data.query.pages[pageId].extract);\n titleName = data.query.pages[pageId].title;\n }\n }\n\n if (extractData.toString().length !== 0) {\n //msg.payload = titleName.toString();\n var wikipediaUrl = "https://en.wikipedia.org/wiki/" + titleName;\n/* var wikipediaLink = "<a href=’" + wikipediaUrl + "’>"+wikipediaUrl+"</a>";\n var r = /\\u([\d\w]{4})/gi;\n wikipediaLink = wikipediaLink.replace®*/\n msg.payload = wikipediaUrl;\n } else {\n msg.payload = "No such Wikipedia with " + titleName.toString() + " ";\n }\n} else {\n msg.payload = "Invalid Wikipedia";\n}\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 392,
"y": 58,
"wires": [
[
"c1a1a54f.cb57a8"
]
]
},
{
"id": “cd42fc1c.a943”,
"type": “json”,
"z": “dc2174f7.361408”,
"name": “”,
"x": 322,
"y": 128,
"wires": [
[
"f2dc25f4.c5fb48"
]
]
},
{
"id": “c1a1a54f.cb57a8”,
"type": “template”,
"z": “dc2174f7.361408”,
"name": “wikipediaTemplate”,
"field": “payload”,
"fieldType": “msg”,
"format": “json”,
"syntax": “mustache”,
"template": “{\n "_attachment": {\n "template": {\n "type": "generic",\n "content": [\n {\n "h5": "Wikipedia Details"\n },\n {\n "title": {\n "text": "{{payload}}",\n "link": "{{payload}}"\n }\n }]\n }\n }\n}”,
"x": 526,
"y": 136,
"wires": [
[
"365ebb60.9600e4"
]
]
}
]
====================
3.
[{
"id": “d216d0d1.b5067”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “add”,
"func": “var numArray = msg.payload.params.split(" ");\nvar result = 0;\nfor (var i in numArray) \nresult = context.global.math.add(result, numArray[i]);\nmsg.payload = result;\nreturn msg;\n\n”,
"outputs": 1,
"noerr": 0,
"x": 361.20001220703125,
"y": 24.199996948242188,
"wires": [
[“379899a.4b7dd66”, “b0fd12e.f061af”]
]
}, {
"id": “435db751.6a85b8”,
"type": “switch”,
"z": “457f5faa.7fb0b”,
"name": “Route”,
"property": “payload.cmd”,
"propertyType": “msg”,
"rules": [{
"t": “eq”,
"v": “add”,
"vt": “str”
}, {
"t": “eq”,
"v": “sub”,
"vt": “str”
}, {
"t": “eq”,
"v": “mul”,
"vt": “str”
}, {
"t": “eq”,
"v": “div”,
"vt": “str”
}, {
"t": “eq”,
"v": “avg”,
"vt": “str”
}, {
"t": “eq”,
"v": “sqrt”,
"vt": “str”
}, {
"t": “eq”,
"v": “log”,
"vt": “str”
}, {
"t": “eq”,
"v": “round”,
"vt": “str”
}, {
"t": “eq”,
"v": “median”,
"vt": “str”
}, {
"t": “eq”,
"v": “max”,
"vt": “str”
}, {
"t": “eq”,
"v": “min”,
"vt": “str”
}, {
"t": “eq”,
"v": “pow”,
"vt": “str”
}, {
"t": “eq”,
"v": “floor”,
"vt": “str”
}, {
"t": “eq”,
"v": “eval”,
"vt": “str”
}],
"checkall": “true”,
"outputs": 14,
"x": 163.20001220703125,
"y": 297.20001220703125,
"wires": [
[“d216d0d1.b5067”],
[“e1c7828c.18be6”],
[“bb745666.0aace8”],
[“6d08bfeb.79d46”],
[“6b35a3c0.8bcc0c”],
[“7ec9dece.cbe31”],
[“c65b79c5.3d0428”],
[“161ea455.efd4cc”],
[“abf1005a.85bd1”],
[“2fdd6d30.f68312”],
[“fdfd0ac8.860118”],
[“44ead8f2.269fb8”],
[“8d91b689.32b078”],
[“29543ce4.4090a4”]
]
}, {
"id": “6d08bfeb.79d46”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “div”,
"func": “var numArray = msg.payload.params.split(" ");\nvar result =1;\nvar count=1\nfor (var i in numArray)\n{\n if(count==1)\n {\n result = context.global.math.divide(numArray[i],result); \n count++\n }\n else\n result = context.global.math.divide(result,numArray[i]);\n msg.payload=result;\n}\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 361.20001220703125,
"y": 148.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “161ea455.efd4cc”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “round”,
"func": “ var numArray = msg.payload.params.split(" ");\n var arr = [];\n for (var i in numArray) {\n var result = context.global.math.round(numArray[i]);\n arr.push(result);\n }\n console.log(arr);\n msg.payload = arr.toString();\n return msg;\n”,
"outputs": 1,
"noerr": 0,
"x": 362.20001220703125,
"y": 311.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “bb745666.0aace8”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “mul”,
"func": “var numArray = msg.payload.params.split(" ");\nvar result = 1;\nfor (var i in numArray) \nresult = context.global.math.multiply(result,numArray[i]);\nmsg.payload = result;\nreturn msg;\n”,
"outputs": 1,
"noerr": 0,
"x": 368.20001220703125,
"y": 109.19999694824219,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “e1c7828c.18be6”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “sub”,
"func": “var numArray = msg.payload.params.split(" ");\nvar result = 0;\nvar count=1\nfor (var i in numArray)\n{\n if(count==1)\n {\n result = context.global.math.subtract(numArray[i],result); \n count++\n }\n else\n result = context.global.math.subtract(result,numArray[i]);\n msg.payload=result;\n}\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 363.20001220703125,
"y": 68.19999694824219,
"wires": [
[“379899a.4b7dd66”, “b0fd12e.f061af”]
]
}, {
"id": “7ec9dece.cbe31”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “sqrt”,
"func": “var numArray = msg.payload.params.split(" ");\nif(numArray.length==1)\n{\nresult= context.global.math.sqrt(numArray[0]);\nmsg.payload= result;\n} \nelse{\n msg.payload="Give only one number";\n}\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 365.20001220703125,
"y": 233.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “c65b79c5.3d0428”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “log”,
"func": “var numArray = msg.payload.params.split(" ");\nfor (var i in numArray) \nresult= context.global.math.log(numArray[i],10);\nmsg.payload= result;\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 363.20001220703125,
"y": 273.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “6b35a3c0.8bcc0c”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “avg”,
"func": “var numArray=msg.payload.params.split(" ");\nvar result=0;\nfor(var i in numArray)\nresult = context.global.math.add(result, numArray[i]);\nmsg.payload= result/(numArray.length);\nreturn msg;\n”,
"outputs": 1,
"noerr": 0,
"x": 364.20001220703125,
"y": 192.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “abf1005a.85bd1”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “median”,
"func": “var numArray = msg.payload.params.split(" ");\nvar median = 0;\nif (numArray.length % 2 == 0){ \n median =numArray[(numArray.length)/2];\n}\nelse{\n median=(numArray[numArray.length/2-0.5]);\n}\nmsg.payload=median;\nreturn msg;\n”,
"outputs": 1,
"noerr": 0,
"x": 361.20001220703125,
"y": 349.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “2fdd6d30.f68312”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “max”,
"func": “var numArray = msg.payload.params.split(" ");\nvar max =numArray[0];\nfor(var i=1;i<numArray.length;i++)\n{\n if(numArray[i]>max)\n max=numArray[i];\n}\nmsg.payload= max;\nreturn msg;\n”,
"outputs": 1,
"noerr": 0,
"x": 359.20001220703125,
"y": 390.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “fdfd0ac8.860118”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “min”,
"func": “var numArray = msg.payload.params.split(" ");\nvar min =numArray[0];\nfor(var i=1;i<numArray.length;i++)\n{\n if(numArray[i]<min)\n min=numArray[i];\n}\nmsg.payload= min;\nreturn msg;\n”,
"outputs": 1,
"noerr": 0,
"x": 366.20001220703125,
"y": 428.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “44ead8f2.269fb8”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “pow”,
"func": “var numArray = msg.payload.params.split(" ");\n//for(var i in numArray) \nvar result = context.global.math.pow(numArray[0],numArray[1]);\nmsg.payload= result;\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 362.20001220703125,
"y": 468.20001220703125,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “8d91b689.32b078”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “floor”,
"func": “ var numArray = msg.payload.params.split(" ");\nvar arr=[];\nfor(var i in numArray) \n{\nvar result= context.global.math.floor(numArray[i]);\narr.push(result);\n}\nconsole.log(arr);\nmsg.payload= arr.toString();\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 363.20001220703125,
"y": 514.2000122070312,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}, {
"id": “de76fdaf.0b0df”,
"type": “http in”,
"z": “457f5faa.7fb0b”,
"name": “Calculator”,
"url": “/api/calculator”,
"method": “get”,
"swaggerDoc": “”,
"x": 86.5,
"y": 77.39999389648438,
"wires": [
[“435db751.6a85b8”]
]
}, {
"id": “b0fd12e.f061af”,
"type": “http response”,
"z": “457f5faa.7fb0b”,
"name": “”,
"x": 793.5,
"y": 353,
"wires": []
}, {
"id": “379899a.4b7dd66”,
"type": “debug”,
"z": “457f5faa.7fb0b”,
"name": “”,
"active": true,
"console": “false”,
"complete": “payload”,
"x": 738.4999847412109,
"y": 76.19999694824219,
"wires": []
}, {
"id": “29543ce4.4090a4”,
"type": “function”,
"z": “457f5faa.7fb0b”,
"name": “eval”,
"func": “var num=msg.payload.params.replace( " ", "+" );\nconsole.log(num);\nvar result=context.global.math.eval(num);\nmsg.payload=result;\nreturn msg;”,
"outputs": 1,
"noerr": 0,
"x": 366,
"y": 559,
"wires": [
[“b0fd12e.f061af”, “379899a.4b7dd66”]
]
}]
=========================
4.
[{
"id": "15c46ee2.f27601",
"type": "subflow",
"name": "facebook",
"info": "",
"in": [{
"x": 43,
"y": 74,
"wires": [{
"id": "3d42c65c.56a14a"
}]
}],
"out": [{
"x": 821,
"y": 74,
"wires": [{
"id": "f8461b28.769c18",
"port": 0
}]
}]
}, {
"id": "3d42c65c.56a14a",
"type": "function",
"z": "15c46ee2.f27601",
"name": "Prepare Request",
"func": "msg.payload = {\n source: \"Facebook\", \n text: msg.payload.content,\n user: msg.payload.chatId\n};\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 221,
"y": 74,
"wires": [
["b5ad51f0.dc143"]
]
}, {
"id": "f8461b28.769c18",
"type": "function",
"z": "15c46ee2.f27601",
"name": "Prepare Response",
"func": "if (msg.payload.reply.attachment) {\n var json2md = global.get(\"json2md\");\n //msg.payload = json2md(msg.payload.reply.attachment);\n\n msg.payload = JSON.stringify(msg.payload.reply.attachment);\n}\nelse {\n msg.payload = msg.payload.reply.text;\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 646.9999389648438,
"y": 74.00003051757812,
"wires": [
["35fdc86.8dffc38"]
]
}, {
"id": "b5ad51f0.dc143",
"type": "sibabot-controller",
"z": "15c46ee2.f27601",
"name": "",
"server": "fc94c855.ab8d58",
"x": 431.99993896484375,
"y": 73.79998779296875,
"wires": [
["f8461b28.769c18"]
]
}, {
"id": "35fdc86.8dffc38",
"type": "debug",
"z": "15c46ee2.f27601",
"name": "",
"active": true,
"console": "true",
"complete": "true",
"x": 694.4999847412109,
"y": 315.59999084472656,
"wires": []
}, {
"id": "fc94c855.ab8d58",
"type": "sibabot-server",
"z": "",
"repohost": "",
"repopath": "",
"brokerhost": "",
"brokerport": "61613",
"name": ""
}, {
"id": "77586407.17ad1c",
"type": "chatbot-facebook-receive",
"z": "551b7b82.cac6f4",
"bot": "ac0aa820.d0dea8",
"x": 104,
"y": 34,
"wires": [
["de52e54.d307918", "2a45a4cc.babecc"]
]
}, {
"id": "de52e54.d307918",
"type": "chatbot-debug",
"z": "551b7b82.cac6f4",
"x": 227,
"y": 106,
"wires": []
}, {
"id": "5226790a.d0c338",
"type": "chatbot-message",
"z": "551b7b82.cac6f4",
"name": "",
"message": "",
"answer": true,
"track": false,
"parse_mode": "Markdown",
"x": 788,
"y": 96,
"wires": [
[]
]
}, {
"id": "2a45a4cc.babecc",
"type": "chatbot-conversation",
"z": "551b7b82.cac6f4",
"name": "",
"chatId": "",
"transport": "facebook",
"x": 307.5,
"y": 34,
"wires": [
["adb06223.96447"]
]
}, {
"id": "bf5e2e98.d8d32",
"type": "function",
"z": "551b7b82.cac6f4",
"name": "Set Text",
"func": "msg.payload = {\n \"chatId\": msg.originalMessage.chat.id,\n \"type\": \"message\",\n \"content\":{ \"message\": {\n \"attachment\":{\n \"type\":\"template\",\n \"payload\":{\n \"template_type\":\"generic\",\n \"elements\":[\n {\n \"title\":\"Welcome to Peter\\'s Hats\",\n \"image_url\":\"https://dev1.sirvisetti.com/company_image.png\",\n \"subtitle\":\"We\\'ve got the right hat for everyone.\",\n \"default_action\": {\n \"type\": \"web_url\",\n \"url\": \"https://dev1.sirvisetti.com/view?item=103\",\n \"messenger_extensions\": true,\n \"webview_height_ratio\": \"tall\",\n \"fallback_url\": \"https://dev1.sirvisetti.com/\"\n },\n \"buttons\":[\n {\n \"type\":\"web_url\",\n \"url\":\"https://dev1.sirvisetti.com\",\n \"title\":\"View Website\"\n },{\n \"type\":\"postback\",\n \"title\":\"Start Chatting\",\n \"payload\":\"DEVELOPER_DEFINED_PAYLOAD\"\n } \n ] \n }\n ]\n }\n }\n }}};\nnode.send(msg); ",
"outputs": 1,
"noerr": 0,
"x": 638,
"y": 34,
"wires": [
["1a8e8925.a0af07"]
]
}, {
"id": "adb06223.96447",
"type": "subflow:15c46ee2.f27601",
"z": "551b7b82.cac6f4",
"name": "",
"x": 482,
"y": 34,
"wires": [
["bf5e2e98.d8d32"]
]
}, {
"id": "1a8e8925.a0af07",
"type": "chatbot-facebook-send",
"z": "551b7b82.cac6f4",
"bot": "ac0aa820.d0dea8",
"track": false,
"outputs": 0,
"x": 961,
"y": 34,
"wires": []
}, {
"id": "ac0aa820.d0dea8",
"type": "chatbot-facebook-node",
"z": "",
"botname": "FB",
"usernames": "",
"log": ""
}]
==================
5.
[{
"id": "afee8c9e.04923",
"type": "function",
"z": "997df88c.8bd9e8",
"name": "Usps",
"func": "var responseArray = [];\nvar trackId = msg.req.query.trackId;\n//var json2md = global.get('json2md');\nvar attachment = {\n \"template\": {\n \"type\": \"generic\",\n \"content\": [{\n \"title\": {text: \"USPS Product and Tracking Information\", link: \"https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=\" + trackId\n }\n },\n {\n \"table\": {\n \"headers\": [\n \"Date & Time\",\n \"Location\",\n \"Status of Item\"\n\n ],\n \"rows\": []\n }\n }\n ]\n }\n}\n\n//console.log(\"OBJECT ++++++ :\" + json2md([jsonobj]));\n\nfunction getTrackingData(_callback) {\n ({\n UspsClient\n } = global.get('shipit'));\n\n\n usps = new UspsClient({\n userId: '888SIRVI2234',\n clientIp: '122.169.253.92'\n });\n\n usps.requestData({\n trackingNumber: trackId\n }, function(err, response) {\n if (err) {\n node.error(\"Error\" + err);\n msg.payload = err;\n node.send(msg);\n }\n if (response) {\n node.log(\"Response :\" + JSON.stringify(response));\n }\n this.response = response;\n this.error = err;\n _callback();\n });\n}\n\ngetTrackingData(function() {\n //node.log(\"RES :\" + JSON.stringify(this.response))\n //node.log(\"JSON OBJ ===== \" + JSON.stringify(jsonobj));\n if(this.response.activities.length!==0){\n for (i = 0; i < this.response.activities.length; i++) {\n var timestamp = this.response.activities[i].timestamp;\n var location = this.response.activities[i].location;\n var details = this.response.activities[i].details;\n attachment.template.content[1].table.rows.push([timestamp, location, details]);\n //console.log(\"timestamp \" + timestamp);\n\n }\n msg.payload._attachment = attachment;\n node.send(msg);\n }else{\n var message={\n \"template\": {\n \"type\": \"generic\",\n \"content\": [{\n \"title\": {text: \"USPS Product and Tracking Information\",link: \"https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=\" + trackId\n }\n },\n {\n \"h5\":\"The Postal Service could not locate the tracking information for your tracking number \" + trackId + \". Please verify your tracking number and try again later\"\n }\n \n ]\n }\n}\nmsg.payload._attachment=message;\nnode.send(msg);\n }\n \n \n \n});",
"outputs": 1,
"noerr": 0,
"x": 228,
"y": 113,
"wires": [
["b5bb9f22.4f5b9"]
]
}, {
"id": "3f7f8956.b873c6",
"type": "http response",
"z": "997df88c.8bd9e8",
"name": "",
"x": 711,
"y": 103,
"wires": []
}, {
"id": "c1ac7be1.6d0048",
"type": "http in",
"z": "997df88c.8bd9e8",
"name": "Usps",
"url": "/api/Usps",
"method": "get",
"swaggerDoc": "",
"x": 71,
"y": 112,
"wires": [
["afee8c9e.04923"]
]
}, {
"id": "b5bb9f22.4f5b9",
"type": "json",
"z": "997df88c.8bd9e8",
"name": "",
"x": 365,
"y": 40,
"wires": [
["e1e098bc.2bc878"]
]
}, {
"id": "e1e098bc.2bc878",
"type": "function",
"z": "997df88c.8bd9e8",
"name": "usps-payload",
"func": "var json2md=global.get('json2md');\n/*var json={\n \"h1\": [{\n \"h1\": \"Product and Tracking Information\"\n }, {\"blockquote\":\"First-Class Package Service\"},{\n \"table\": {\n \"headers\": [\"Date & Time\", \"location\", \"Status of Item\"],\n \"rows\": [\n [\"2016-10-12T07:54:00.000Z\", \"Miami, FL 33144\", \"Arrived at Unit\"],\n [\"2016-10-05T06:09:00.000Z\", \"\", \"In Transit to Destination\"],\n [\"2016-10-04T00:09:00.000Z\", \"Miami, FL 33152\", \"Departed USPS Origin Facility\"],\n [\"2016-10-03T12:34:00.000Z\", \"Miami, FL 33152\", \"Arrived at USPS Origin Facility\"],\n [\"2016-10-01T22:01:00.000Z\", \"Las Vegas, NV 89199\", \"Departed USPS Facility\"],\n [\"2016-10-01T19:45:00.000Z\", \"Las Vegas, NV 89199\", \"Arrived at USPS Destination Facility\"],\n [\"2016-09-29T04:30:00.000Z\", \"\", \"In Transit to Destination\"],\n [\"2016-09-27T22:30:00.000Z\", \"Miami, FL 33152\", \"Departed USPS Origin Facility\"],\n [\"2016-09-26T21:26:00.000Z\", \"Miami, FL 33152\", \"Arrived at USPS Origin Facility\"],\n [\"2016-09-26T20:58:00.000Z\", \"Miami, FL 33126\", \"Departed Post Office\"],\n [\"2016-09-26T16:43:00.000Z\", \"Miami, FL 33126\", \"Acceptance\"]\n ]\n }\n }]\n}\nmsg.payload=json2md([json]);*/\nreturn msg;\n\n",
"outputs": 1,
"noerr": 0,
"x": 548,
"y": 41,
"wires": [
["3f7f8956.b873c6"]
]
}, {
"id": "2f981c5c.072964",
"type": "http in",
"z": "997df88c.8bd9e8",
"name": "AmazonSkill",
"url": "/api/amazon",
"method": "get",
"swaggerDoc": "",
"x": 79,
"y": 205,
"wires": [
["69df733c.c3393c"]
]
}, {
"id": "69df733c.c3393c",
"type": "function",
"z": "997df88c.8bd9e8",
"name": "Amazon",
"func": "({\n AmazonClient\n} = global.get('shipit'));\namazonClient = new AmazonClient();\nvar orderID = msg.req.query.orderId;\nvar orderingShipmentId = msg.req.query.shippingId;\n/*var orderingShipmentId = 'DmZd0KS8k'*/\namazonClient.requestData({\n orderID\n}, function(err, result) {\n if (err !== null) {\n node.error('error retrieving tracking data' + err);\n }\n if (result !== null) {\n node.log('new tracking data received' + JSON.stringify(result));\n }\n});\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 312,
"y": 205,
"wires": [
["e96ad02e.27897"]
]
}, {
"id": "e96ad02e.27897",
"type": "http response",
"z": "997df88c.8bd9e8",
"name": "",
"x": 553,
"y": 207,
"wires": []
}, {
"id": "a2ce9cc1.5ad1c",
"type": "http in",
"z": "997df88c.8bd9e8",
"name": "ups",
"url": "/api/ups",
"method": "get",
"swaggerDoc": "",
"x": 58,
"y": 317,
"wires": [
["e34c4817.7a2e38"]
]
}, {
"id": "e34c4817.7a2e38",
"type": "function",
"z": "997df88c.8bd9e8",
"name": "ups",
"func": "({\n UpsClient\n \n} = global.get('shipit'));\n \nups = new UpsClient({\n licenseNumber: '1C999A999B999999',\n userId: 'naveen0119',\n password: 'Navinkiran@1210'\n});\n\nups.requestData({trackingNumber: '1Z1234567890123456'}, function(err, result) {\n if (err !== null) { console.log(`[ERROR] error retrieving tracking data ${err}`); }\n if (result !== null) { return console.log(`[DEBUG] new tracking data received ${JSON.stringify(result)}`); }\n});\n",
"outputs": 1,
"noerr": 0,
"x": 304,
"y": 317,
"wires": [
["a68a2725.12db58"]
]
}, {
"id": "a68a2725.12db58",
"type": "http response",
"z": "997df88c.8bd9e8",
"name": "",
"x": 525,
"y": 316,
"wires": []
}, {
"id": "ba7ae8a5.37e0e8",
"type": "function",
"z": "997df88c.8bd9e8",
"name": "FedEx",
"func": "var trackId=msg.req.query.trackId;\n({FedexClient} = global.get('shipit'));\n\nfedex = new FedexClient({\n key: 'nMPdeaGwJMGGWaE3', \n password: 'xcUGM86kqaEaKC5SCMfnAiAx4', \n account: '510087020', \n meter: '118769149'});\nfedex.requestData({trackingNumber: '338546050904603'}, function(err, result) {\n if(err!==null){\n node.log(\"Error :\"+ err);\n }if(result!==null){\n node.log(\"Result :\" + result);\n }\n});\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 291,
"y": 430,
"wires": [
["a3427a61.3e1e28"]
]
}, {
"id": "a8f8ada5.0cc4",
"type": "http in",
"z": "997df88c.8bd9e8",
"name": "FedEx",
"url": "/api/fedex",
"method": "get",
"swaggerDoc": "",
"x": 55,
"y": 429,
"wires": [
["ba7ae8a5.37e0e8"]
]
}, {
"id": "a3427a61.3e1e28",
"type": "http response",
"z": "997df88c.8bd9e8",
"name": "",
"x": 536,
"y": 430,
"wires": []
}, {
"id": "2851d4fe.7a96ec",
"type": "comment",
"z": "997df88c.8bd9e8",
"name": "USPS",
"info": "",
"x": 62,
"y": 44,
"wires": []
}, {
"id": "f7d253cb.f9b7",
"type": "comment",
"z": "997df88c.8bd9e8",
"name": "Amazon",
"info": "",
"x": 58,
"y": 162,
"wires": []
}, {
"id": "53f9a9eb.474b28",
"type": "comment",
"z": "997df88c.8bd9e8",
"name": "UPS",
"info": "",
"x": 58,
"y": 262,
"wires": []
}, {
"id": "f51686fc.5ae368",
"type": "comment",
"z": "997df88c.8bd9e8",
"name": "FedEx",
"info": "",
"x": 55,
"y": 367,
"wires": []
}]
=================
6.
[{
"id": "19fec87b.563eb8",
"type": "http in",
"z": "1bdca73.b459f59",
"name": "weather request",
"url": "/api/weather",
"method": "get",
"swaggerDoc": "",
"x": 85,
"y": 54,
"wires": [
["c1766c18.15a9b"]
]
}, {
"id": "c1766c18.15a9b",
"type": "function",
"z": "1bdca73.b459f59",
"name": "weather",
"func": "var zip = msg.payload.zip;\n//node.log(\"ZIP : \" + city);\nvar city=msg.payload.city;\n//node.log(\"CITY : \" + city);\n//var countrycode=msg.payload.countrycode;\n//var units=msg.payload.units;\nvar url = \"http://api.openweathermap.org/data/2.5/weather?zip=\"+zip+\",\"+city+\"&units=imperial&apikey=4157c4f2c69a61af77f4c468c4966678\";\n//node.log(\"URL IS : \" + url);\nmsg.url = url;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 189,
"y": 149,
"wires": [
["5fd39645.56954"]
]
}, {
"id": "29d14e84.48d51a",
"type": "http response",
"z": "1bdca73.b459f59",
"name": "weather response",
"x": 534,
"y": 62,
"wires": []
}, {
"id": "5fd39645.56954",
"type": "http request",
"z": "1bdca73.b459f59",
"name": "",
"method": "GET",
"ret": "obj",
"url": "",
"tls": "",
"x": 300,
"y": 64,
"wires": [
["254a5ceb.5869cc"]
]
}, {
"id": "e79d80e7.cc37e8",
"type": "function",
"z": "1bdca73.b459f59",
"name": "weather",
"func": "var data = msg.payload;\nvar country= data.sys.country;\nvar name=data.name;\nvar id=data.id;\nvar temp=data.main.temp;\nvar speed=data.wind.speed;\nvar pressure=data.main.pressure;\nvar humidity=data.main.humidity;\nvar sunrise1=data.sys.sunrise;\nvar sunrise2=sunrise1*1000;\nvar sunrise3=new Date(sunrise2);\n//var sunrise3=new Date(parseFloat(sunrise2));\n//sunrise2.setUTCMilliseconds(sunrise1);\n//console.log(sunrise3);\nvar hours = sunrise3.getHours()+5; \nif(hours>24)\n{\nhours1=hours-24;\n}else{\n hours1=hours;\n}\nvar minutes1 = sunrise3.getMinutes()+30;\nif(minutes1>=60)\n{\nminutes1=minutes1-60;\nhours1=hours+1;\n}else{\n minutes1=minutes1;\n hours1=hours;\n}\nvar sunrise = hours1 + ':' + minutes1;\n//sunrise.setUTCSeconds(sunrise1);\nvar sunset1=data.sys.sunset;\nvar sunset2=new Date(0);\nsunset2.setUTCSeconds(sunset1);\nvar hours2 = sunset2.getHours()+5;\nif(hours2>24)\n{\nhours2=hours2-24;\n}else{\n hours2=hours2;\n}\nvar minutes2 = sunset2.getMinutes()+30; \nif(minutes2>=60)\n{\nminutes2=minutes2-60;\nhours3=hours2+1;\n}else{\n minutes2=minutes2;\n hours3=hours2;\n}\nvar sunset = hours3 + ':' + minutes2;\n//sunset.setUTCSeconds(sunset1);\nvar lon=data.coord.lon;\nvar lat=data.coord.lat;\n//var txt =[lat,lon];\n//console.log(txt)\n//var result = txt.link(https://openweathermap.org/weathermap?zoom=8&\"+lat+\"&\"+lon);\nvar date1=data.dt;\nvar date2 = new Date(0);\ndate2.setUTCSeconds(date1);\nvar hours4 = date2.getHours()+5;\n//console.log(hours4);\nif(hours4>=12)\n{\nhours5=hours4-12;\n}else{\n hours5=hours4;\n}\nvar minutes3 = date2.getMinutes()+30;\n//console.log(minutes3);\nif(minutes3>=60)\n{\nminutes4=minutes3-60;\nhours6=hours5+1;\n}else{\n minutes4=minutes3;\n hours6=hours5;\n}\nvar date=(date2.getMonth() +1 )+ \"/\" +\n date2.getDate() + \"/\" +\n date2.getFullYear() + \" \" +\n hours6+ \":\" +\n minutes4+ \":\" +\n date2.getSeconds()\nif(hours4<12)\n{\n date=date+'AM';\n}else{\n date=date+'PM';\n}\nfor (var i = 0; i < data.weather.length; i++) \n {\n var counter = data.weather[i];\n description = counter.description;\n main = counter.main;\n icon=counter.icon;\n }\nvar a='['+lat+\",\"+lon+']'; \n//var res=a.link(\"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon);\n//console.log(res);\nvar link1=\"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon;\n//var b=\"<a href='\" + link1 +\"'>\" + a + \"</a>\";\n//console.log(b);\n//var a1= new URL(a, \"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon);\nvar attachment = {\n\t\"template\": {\n \"type\": \"generic\",\n \"content\": [\n {\n \"title\":{text:\"Click the link for complete weather report\",link:\"https://openweathermap.org/city/\"+id}\n },\n {\n \"h5\":\"Weather in \"+name+\",\"+country\n },\n {\n //\"subtitle\":<a href=\"http://openweathermap.org/img/w/\"+icon+'.png'>temp+ 'F'</a> \n \"img\":{title: \"Some image\", source: \"https://openweathermap.org/img/w/\"+icon+'.png'}\n },\n {\n \"h6\":temp+ 'F' \n },\n {\n \"h6\":description\n },\n {\n \"h6\":\"get at \"+date\n },\n {\n \"table\": {\n \"headers\":[\n \"Type\",\n \"Value\"\n ],\n \"rows\":[\n [\n \"Wind\",\n speed+'m/s'\n ],\n [\n \"Cloudiness\",\n description\n ],\n [\n \"Pressure\",\n pressure+'hpa'\n ],\n [\n \"Humidity\",\n humidity+'%'\n ],\n [\n \"Sunrise\",\n sunrise\n ],\n [\n \"Sunset\",\n sunset\n ],\n [\n \"Geo coords\",\n //res\n //link1\n {title :{text:a,link:link1}}\n //'['+lat+\",\"+lon+']'\n //\"title\":{text:'['+lat+\",\"+lon+']',link:\"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon}\n ]\n ]\n\t\t\t }\n\t\t } \n\t ]\n }\n}\nmsg.payload._attachment = attachment;\nnode.send(msg);",
"outputs": 1,
"noerr": 0,
"x": 429,
"y": 239,
"wires": [
[]
]
}, {
"id": "879bd77e.0ff56",
"type": "debug",
"z": "1bdca73.b459f59",
"name": "",
"active": true,
"console": "false",
"complete": "false",
"x": 447,
"y": 196,
"wires": []
}, {
"id": "254a5ceb.5869cc",
"type": "function",
"z": "1bdca73.b459f59",
"name": "",
"func": "var data = msg.payload;\nvar country= data.sys.country;\nvar name=data.name;\nvar id=data.id;\nvar temp=data.main.temp;\nvar speed=data.wind.speed;\nvar pressure=data.main.pressure;\nvar humidity=data.main.humidity;\nvar sunrise1=data.sys.sunrise;\nvar sunrise2=sunrise1*1000;\nvar sunrise3=new Date(sunrise2);\n//var sunrise3=new Date(parseFloat(sunrise2));\n//sunrise2.setUTCMilliseconds(sunrise1);\n//console.log(sunrise3);\nvar hours = sunrise3.getHours()+5; \nif(hours>24)\n{\nhours1=hours-24;\n}else{\n hours1=hours;\n}\nvar minutes1 = sunrise3.getMinutes()+30;\nif(minutes1>=60)\n{\nminutes1=minutes1-60;\nhours1=hours+1;\n}else{\n minutes1=minutes1;\n hours1=hours;\n}\nvar sunrise = hours1 + ':' + minutes1;\n//sunrise.setUTCSeconds(sunrise1);\nvar sunset1=data.sys.sunset;\nvar sunset2=new Date(0);\nsunset2.setUTCSeconds(sunset1);\nvar hours2 = sunset2.getHours()+5;\nif(hours2>24)\n{\nhours2=hours2-24;\n}else{\n hours2=hours2;\n}\nvar minutes2 = sunset2.getMinutes()+30; \nif(minutes2>=60)\n{\nminutes2=minutes2-60;\nhours3=hours2+1;\n}else{\n minutes2=minutes2;\n hours3=hours2;\n}\nvar sunset = hours3 + ':' + minutes2;\n//sunset.setUTCSeconds(sunset1);\nvar lon=data.coord.lon;\nvar lat=data.coord.lat;\n//var txt =[lat,lon];\n//console.log(txt)\n//var result = txt.link(https://openweathermap.org/weathermap?zoom=8&\"+lat+\"&\"+lon);\nvar date1=data.dt;\nvar date2 = new Date(0);\ndate2.setUTCSeconds(date1);\nvar hours4 = date2.getHours()+5;\n//console.log(hours4);\nif(hours4>=12)\n{\nhours5=hours4-12;\n}else{\n hours5=hours4;\n}\nvar minutes3 = date2.getMinutes()+30;\n//console.log(minutes3);\nif(minutes3>=60)\n{\nminutes4=minutes3-60;\nhours6=hours5+1;\n}else{\n minutes4=minutes3;\n hours6=hours5;\n}\nvar date=(date2.getMonth() +1 )+ \"/\" +\n date2.getDate() + \"/\" +\n date2.getFullYear() + \" \" +\n hours6+ \":\" +\n minutes4+ \":\" +\n date2.getSeconds()\nif(hours4<12)\n{\n date=date+'AM';\n}else{\n date=date+'PM';\n}\nfor (var i = 0; i < data.weather.length; i++) \n {\n var counter = data.weather[i];\n description = counter.description;\n main = counter.main;\n icon=counter.icon;\n }\nvar a='['+lat+\",\"+lon+']'; \n//var res=a.link(\"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon);\n//console.log(res);\nvar link1=\"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon;\n//var b=\"<a href='\" + link1 +\"'>\" + a + \"</a>\";\n//console.log(b);\n//var a1= new URL(a, \"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon);\nvar attachment = {\n\t\"template\": {\n \"type\": \"generic\",\n \"content\": [\n {\n \"title\":{text:\"Click the link for complete weather report\",link:\"https://openweathermap.org/city/\"+id}\n },\n {\n \"h5\":\"Weather in \"+name+\",\"+country\n },\n {\"table\": {\n \"headers\":[],\n \"rows\":[\n [{img:{title: \"Some image\", source: \"https://openweathermap.org/img/w/\"+icon+'.png'}},temp+'F']\n ]\n\t\t\t}\n\t\t\t},\n {\n \"h6\":description\n },\n {\n \"h6\":\"get at \"+date\n },\n {\n \"table\": {\n \"headers\":[\n \"Type\",\n \"Value\"\n ],\n \"rows\":[\n [\n \"Wind\",\n speed+'m/s'\n ],\n [\n \"Cloudiness\",\n description\n ],\n [\n \"Pressure\",\n pressure+'hpa'\n ],\n [\n \"Humidity\",\n humidity+'%'\n ],\n [\n \"Sunrise\",\n sunrise\n ],\n [\n \"Sunset\",\n sunset\n ],\n [\n \"Geo coords\",\n //res\n //link1\n {title :{text:a,link:link1}}\n //'['+lat+\",\"+lon+']'\n //\"title\":{text:'['+lat+\",\"+lon+']',link:\"https://openweathermap.org/weathermap?zoom=8&lat=\"+lat+'&lon='+lon}\n ]\n ]\n\t\t\t }\n\t\t } \n\t ]\n }\n}\nmsg.payload._attachment = attachment;\nnode.send(msg);",
"outputs": 1,
"noerr": 0,
"x": 413,
"y": 132,
"wires": [
["29d14e84.48d51a", "879bd77e.0ff56"]
]
}]
======================
7.GOOGLE API SKILLS
===================
[{
"id": "845c6c1d.69d1f",
"type": "http in",
"z": "de0a13a6.fbc28",
"name": "distance",
"url": "/api/distance",
"method": "get",
"swaggerDoc": "",
"x": 100,
"y": 151,
"wires": [
["1010ef6c.8e8871"]
]
}, {
"id": "d47a3ae8.da67c8",
"type": "http request",
"z": "de0a13a6.fbc28",
"name": "",
"method": "GET",
"ret": "txt",
"url": "",
"tls": "",
"x": 357,
"y": 130,
"wires": [
["2dc99d17.b5a222"]
]
}, {
"id": "5f1d12ff.1ef17c",
"type": "http response",
"z": "de0a13a6.fbc28",
"name": "",
"x": 640,
"y": 143,
"wires": []
}, {
"id": "1010ef6c.8e8871",
"type": "function",
"z": "de0a13a6.fbc28",
"name": "distanceApi",
"func": "var orginPlace = msg.payload.origin;\nvar destinationPlace = msg.payload.destination\nvar keyVal = \"AIzaSyBYC2_GtSIWbvRJYvSOHBaJ7V2uwAf8l30\"; //From googlemaps api\n\nmsg.url = \"https://maps.googleapis.com/maps/api/distancematrix/json?origins=\"+orginPlace+\"&destinations=\"+destinationPlace+\"&key=\"+keyVal;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 202,
"y": 80,
"wires": [
["d47a3ae8.da67c8"]
]
}, {
"id": "2dc99d17.b5a222",
"type": "function",
"z": "de0a13a6.fbc28",
"name": "distanceCalculation",
"func": "var orgin = msg.req.query.origin;\nvar destination = msg.req.query.destination;\n\nvar data = JSON.parse(msg.payload);\nvar elementsLength;\nvar distanceVal;\nvar duration;\nvar distance;\nvar statusVal;\nvar destinationAddress = data.destination_addresses;\nvar originAddress = data.origin_addresses;\n\nvar attachment = {\n \"_attachment\": {\n \"template\": {\n \"type\": \"generic\",\n \"content\": [{\n \"h5\": \"Distance Calculation Details\"\n },\n {\n \"title\": {\n \"text\": \"Distance Between \" + orgin + \" & \" + destination,\n \"link\": \"https://www.google.co.in/maps/dir/\" + originAddress + \"/\" + destinationAddress\n }\n },\n {\n \"table\": {\n \"headers\": [\n \"Origin\",\n \"Destination\",\n \"Distance\",\n \"Duration\"\n ],\n \"rows\": []\n }\n }\n ]\n }\n }\n}\n\n\n//No Data\nvar emptyAttachment = {\n \"_attachment\": {\n \"template\": {\n \"type\": \"generic\",\n \"content\": [{\n \"h5\": \"No Data found\"\n }]\n }\n }\n}\n\nfor (var a = 0; a <= data.rows.length; a++) {\n if (data.rows[a] !== undefined) {\n elementsLength = data.rows[a].elements;\n for (var b = 0; b <= elementsLength.length; b++) {\n if (elementsLength[b] !== undefined) {\n distanceVal = elementsLength[b].distance;\n durationVal = elementsLength[b].duration;\n if (durationVal !== undefined && distanceVal !== undefined) {\n duration = durationVal.text\n distance = distanceVal.text\n } else {\n duration = \"no duration\"\n distance = \"no distance\"\n }\n }\n }\n }\n}\n\nif (duration !== \"no duration\" && distance !== \"no distance\") {\n attachment._attachment.template.content[2].table.rows.push([originAddress, destinationAddress, distance, duration]);\n msg.payload = attachment;\n} else {\n msg.payload = emptyAttachment;\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 505,
"y": 75,
"wires": [
["5f1d12ff.1ef17c"]
]
}, {
"id": "c5ef38c9.bc6628",
"type": "http in",
"z": "de0a13a6.fbc28",
"name": "findPlaces",
"url": "/api/findPlaces",
"method": "get",
"swaggerDoc": "",
"x": 82,
"y": 330,
"wires": [
["3c62f55b.37f2ba"]
]
}, {
"id": "483f18bf.820f78",
"type": "http request",
"z": "de0a13a6.fbc28",
"name": "",
"method": "GET",
"ret": "txt",
"url": "",
"tls": "",
"x": 353,
"y": 340,
"wires": [
["e4ecfdd5.22ff9"]
]
}, {
"id": "e4e288db.2d19b8",
"type": "http response",
"z": "de0a13a6.fbc28",
"name": "",
"x": 748,
"y": 368,
"wires": []
}, {
"id": "3c62f55b.37f2ba",
"type": "function",
"z": "de0a13a6.fbc28",
"name": "findPlacesApi",
"func": "//var location = msg.req.query.location\n//var radius = msg.req.query.radius\nvar name = msg.req.query.name\n//var key = msg.req.query.key\n\n//API to find longitude and latitude\nmsg.url = \"https://maps.googleapis.com/maps/api/geocode/json?address=\"+name+\"&key=AIzaSyAvXHEIAwe4KitKzM2RAl2DE4ZXF4oW4Ps\"\n\n//API to find near by locations\n//msg.url = \"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=\"+location+\"&radius=\"+radius+\"&name=\"+name+\"&key=\"+key\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 226,
"y": 277,
"wires": [
["483f18bf.820f78"]
]
}, {
"id": "e4ecfdd5.22ff9",
"type": "function",
"z": "de0a13a6.fbc28",
"name": "findLongitudeAndLattitude",
"func": "var data = JSON.parse(msg.payload);\nvar resultsArray = [];\nvar geometryArray = [];\nvar locationArray = [];\nvar longitude;\nvar latitude;\nfor (var a = 0; a <= data.results.length; a++) {\n if (data.results[a] !== undefined) {\n resultsArray.push(data.results[a]);\n }\n}\n\nfor (var c = 0; c <= resultsArray.length; c++) {\n if (resultsArray[c] !== undefined) {\n geometryArray.push(resultsArray[c].geometry);\n for (d = 0; d <= geometryArray.length; d++) {\n if (geometryArray[d] !== undefined) {\n locationArray.push(geometryArray[d].location);\n for (e = 0; e <= locationArray.length; e++) {\n if (locationArray[e] !== undefined) {\n longitude = locationArray[e].lat;\n latitude = locationArray[e].lng\n }\n }\n }\n }\n }\n}\n\n//To find locations in certain radius.\nmsg.url = \"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=\"+longitude+\",\"+latitude+\"&radius=\"+msg.req.query.radius+\"&name=\"+msg.req.query.name+\"&key=AIzaSyAvXHEIAwe4KitKzM2RAl2DE4ZXF4oW4Ps\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 462,
"y": 262,
"wires": [
["81f58a47.ecaee8"]
]
}, {
"id": "3b18a58b.74790a",
"type": "comment",
"z": "de0a13a6.fbc28",
"name": "Detaials of Distance b/w Origin and Destination",
"info": "",
"x": 202,
"y": 40,
"wires": []
}, {
"id": "844842ab.5fc59",
"type": "comment",
"z": "de0a13a6.fbc28",
"name": "Details of places in a location surroundings",
"info": "",
"x": 194,
"y": 223,
"wires": []
}, {
"id": "81f58a47.ecaee8",
"type": "http request",
"z": "de0a13a6.fbc28",
"name": "",
"method": "GET",
"ret": "txt",
"url": "",
"x": 565,
"y": 345,
"wires": [
["a9b54570.421ec8"]
]
}, {
"id": "a9b54570.421ec8",
"type": "function",
"z": "de0a13a6.fbc28",
"name": "findPlaces",
"func": "var data = JSON.parse(msg.payload);\nvar resultsArray = [];\nvar nameArray = [];\nvar ratingArray = [];\n\nvar attachment = {\n \"_attachment\": {\n \"template\": {\n \"type\": \"generic\",\n \"content\": [{\n \"h5\": \"Nearby places of your surroundings\"\n },\n {\n \"title\": {\n \"text\": \"Surroundings of \" + msg.req.query.name,\n \"link\": \"\"\n }\n },\n {\n \"table\": {\n \"headers\": [\n \"Name\",\n \"Rating\",\n \"Vicinity\",\n// \"Icon\"\n ],\n \"rows\": [] \n }\n }\n ]\n }\n }\n}\n\nfor (var a = 0; a <= data.results.length; a++) {\n resultsArray.push(data.results[a]);\n}\nvar finalArray = [];\nfor (var b = 0; b <= resultsArray.length; b++) {\n if (resultsArray[b] !== undefined) {\n// nameArray.push(resultsArray[b].name);\n titleName = resultsArray[b].name;\n if (resultsArray[b].rating === undefined) {\n resultsArray[b].rating = \"-\"\n }\n// ratingArray.push(resultsArray[b].rating);\n rating = resultsArray[b].rating;\n vicinity = resultsArray[b].vicinity\n// icon = {\"image_url\": \"https://maps.gstatic.com/mapfiles/place_api/icons/bank_dollar-71.png\"}//resultsArray[b].icon\n }\n attachment._attachment.template.content[2].table.rows.push([titleName,rating,vicinity]);\n \n}\n\n\n// attachment._attachment.template.content[2].table.rows.push(nameData,ratingData);\nmsg.payload = attachment;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 694,
"y": 235,
"wires": [
["e4e288db.2d19b8"]
]
}, {
"id": "8eb80c4d.3b102",
"type": "comment",
"z": "de0a13a6.fbc28",
"name": "Address of a location",
"info": "",
"x": 132,
"y": 453,
"wires": []
}, {
"id": "5519093e.281dd8",
"type": "http in",
"z": "de0a13a6.fbc28",
"name": "findAddress",
"url": "/api/findAddress",
"method": "get",
"swaggerDoc": "",
"x": 88,
"y": 567,
"wires": [
["96852390.88a93"]
]
}, {
"id": "f29cd79f.0645c8",
"type": "http request",
"z": "de0a13a6.fbc28",
"name": "",
"method": "GET",
"ret": "txt",
"url": "",
"x": 393,
"y": 566,
"wires": [
["670aedc0.21cb64"]
]
}, {
"id": "396ac738.2cecf8",
"type": "http response",
"z": "de0a13a6.fbc28",
"name": "",
"x": 740,
"y": 485,
"wires": []
}, {
"id": "96852390.88a93",
"type": "function",
"z": "de0a13a6.fbc28",
"name": "findAddressApi",
"func": "var nameOfLocatoin = msg.req.query.locationName;\nvar city = msg.req.query.city;\n\nmsg.url = \"https://maps.googleapis.com/maps/api/geocode/json?address=\"+nameOfLocatoin+\" \"+city+\"&key=AIzaSyAvXHEIAwe4KitKzM2RAl2DE4ZXF4oW4Ps\"\nconsole.log(msg.url);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 238,
"y": 500,
"wires": [
["f29cd79f.0645c8"]
]
}, {
"id": "c437effb.643b",
"type": "function",
"z": "de0a13a6.fbc28",
"name": "findAddress",
"func": "var data = msg.payload;\nvar locationName = msg.req.query.locationName;\n\nvar addressArray = [];\n\nvar attachment = {\n \"_attachment\": {\n \"template\": {\n \"type\": \"generic\",\n \"content\": [\n /*{\n \"h5\": \"Address\"\n },\n {\n \"title\": {\n \"text\": \"Address\",\n \"link\": \"\"\n }\n },*/\n {\n \"table\": {\n \"headers\": [\n \"Address\"\n ],\n \"rows\": [] \n }\n }\n ]\n }\n }\n}\n\nfor(var i=0;i<=data.results.length;i++){\n if(data.results[i] !== undefined){\n addressArray.push(data.results[i].formatted_address) \n }\n}\n\nattachment._attachment.template.content[0].table.rows.push([addressArray.toString()]);\nmsg.payload = attachment;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 645,
"y": 564,
"wires": [
["396ac738.2cecf8"]
]
}, {
"id": "670aedc0.21cb64",
"type": "json",
"z": "de0a13a6.fbc28",
"name": "",
"x": 528,
"y": 493,
"wires": [
["c437effb.643b"]
]
}]
0 notes