Skip to content

Instantly share code, notes, and snippets.

@ruial
Last active August 4, 2020 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruial/69dec3c00b991c3b75da16c16907f87d to your computer and use it in GitHub Desktop.
Save ruial/69dec3c00b991c3b75da16c16907f87d to your computer and use it in GitHub Desktop.
Node-RED example flows
[{"id":"ef8ef87c.3c2f38","type":"tab","label":"Packt flow","disabled":false,"info":""},{"id":"4c3c8f8d.0445a","type":"inject","z":"ef8ef87c.3c2f38","name":"variables","props":[{"p":"payload"},{"p":"telegram_token","v":"TELEGRAM_TOKEN","vt":"env"},{"p":"telegram_chat","v":"TELEGRAM_CHAT","vt":"env"}],"repeat":"","crontab":"30 09 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":160,"wires":[["662c9ee6.0ce8e"]]},{"id":"662c9ee6.0ce8e","type":"function","z":"ef8ef87c.3c2f38","name":"set dates","func":"var date = new Date(msg.payload);\ndate.setUTCHours(0, 0, 0, 0);\nmsg.startDate = date.toISOString();\ndate.setDate(date.getDate() + 1);\nmsg.endDate = date.toISOString();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":160,"wires":[["b61dc518.46d9a8"]]},{"id":"5de23f05.e8358","type":"debug","z":"ef8ef87c.3c2f38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"chatMessage","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":340,"wires":[]},{"id":"b61dc518.46d9a8","type":"http request","z":"ef8ef87c.3c2f38","name":"request offer","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://services.packtpub.com/free-learning-v1/offers?dateFrom={{startDate}}&dateTo={{endDate}}","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":160,"wires":[["fc3d587d.86cde8"]]},{"id":"2525d7f2.f8f548","type":"http request","z":"ef8ef87c.3c2f38","name":"request details","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://static.packt-cdn.com/products/{{payload}}/summary","tls":"","persist":false,"proxy":"","authType":"","x":240,"y":280,"wires":[["bf09938.444a57"]]},{"id":"fc3d587d.86cde8","type":"function","z":"ef8ef87c.3c2f38","name":"","func":"msg.payload = msg.payload.data[0].productId\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":700,"y":160,"wires":[["2525d7f2.f8f548"]]},{"id":"bf09938.444a57","type":"function","z":"ef8ef87c.3c2f38","name":"set message","func":"msg.chatMessage = encodeURIComponent(msg.payload.title + \" -> \" + msg.payload.oneLiner);\nmsg.payload = undefined;\nreturn msg;\n\n// this would stop the flow\n// return;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":280,"wires":[["5de23f05.e8358","a6c734c7.331b18"]]},{"id":"a6c734c7.331b18","type":"http request","z":"ef8ef87c.3c2f38","name":"send message","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.telegram.org/bot{{telegram_token}}/sendMessage?chat_id={{telegram_chat}}&text={{chatMessage}}","tls":"","persist":false,"proxy":"","authType":"","x":640,"y":280,"wires":[[]]}]
[{"id":"ffb884a3.d3f578","type":"tab","label":"Product hunt","disabled":false,"info":""},{"id":"f019596a.6c5f88","type":"http request","z":"ffb884a3.d3f578","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://www.producthunt.com","tls":"","persist":false,"proxy":"","authType":"","x":390,"y":180,"wires":[["6e9079ea.5d2938"]]},{"id":"293ec2f8.f4bd1e","type":"debug","z":"ffb884a3.d3f578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":380,"wires":[]},{"id":"6e9079ea.5d2938","type":"html","z":"ffb884a3.d3f578","name":"main content","property":"payload","outproperty":"payload","tag":"ul[class^=postsList]","ret":"html","as":"single","x":590,"y":180,"wires":[["acd25b2f.e72768"]]},{"id":"b44c104.2e962f","type":"html","z":"ffb884a3.d3f578","name":"","property":"payload","outproperty":"payload","tag":"div[class^=item]","ret":"text","as":"single","x":700,"y":280,"wires":[["47e5a1d4.f882"]]},{"id":"acd25b2f.e72768","type":"function","z":"ffb884a3.d3f578","name":"last content","func":"// sometimes there is an add on top\nmsg.payload = msg.payload[msg.payload.length - 1]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":280,"wires":[["b44c104.2e962f"]]},{"id":"f69fc481.fcac68","type":"http in","z":"ffb884a3.d3f578","name":"","url":"/producthunt","method":"get","upload":false,"swaggerDoc":"","x":160,"y":180,"wires":[["f019596a.6c5f88"]]},{"id":"667636ac.af36a8","type":"http response","z":"ffb884a3.d3f578","name":"","statusCode":"","headers":{},"x":830,"y":460,"wires":[]},{"id":"f9f5e5b1.c965a8","type":"template","z":"ffb884a3.d3f578","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \n \"descriptions\": [\n {{#payload}}\n \"{{desc}}\"\n {{^last}}\n ,\n {{/last}}\n {{/payload}}\n ],\n \"limit\": {{limit}}\n}","output":"json","x":460,"y":460,"wires":[["296876f6.be806a"]]},{"id":"296876f6.be806a","type":"change","z":"ffb884a3.d3f578","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":460,"wires":[["667636ac.af36a8"]]},{"id":"47e5a1d4.f882","type":"function","z":"ffb884a3.d3f578","name":"slice and map","func":"var size = msg.req.query.size || 5\nvar length = msg.payload.length\nvar limit = length < size ? length : size\nmsg.limit = limit\nmsg.payload = msg.payload.slice(0, limit).map((p,i) => {\n return {\n desc: p,\n last: limit == i + 1\n }\n})\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":380,"wires":[["f9f5e5b1.c965a8","293ec2f8.f4bd1e"]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment