Automatic NR Forum Checker


#1

I moderate another forum (very low volume) that also uses Discourse and I wanted to create a flow to check it to see if there were any new posts. I put it together and it works very well, so I made anotehr copy for the BF forum (had to add a bit of extra code to handle sticky posts) and here is the result.

The attached flow will check the forum for new topics every 5 minutes and send an alert. It's currently using the 'sysmessage' node sending OSXAlerts since I'm using a Mac, but you should be able to change it to alert you any way you want.

Paul

[{"id":"4fde9ac6.677204","type":"tab","label":"Check NR forum","disabled":false,"info":""},{"id":"a8133abd.81496","type":"inject","z":"4fde9ac6.677204","name":"","topic":"","payload":"","payloadType":"date","repeat":"300","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":220,"wires":[["dd981367.5e87a"]]},{"id":"b294fa92.d5fc3","type":"http request","z":"4fde9ac6.677204","name":"","method":"GET","ret":"txt","url":"https://discourse.nodered.org/latest","tls":"","x":130,"y":280,"wires":[["4ccbac6f.258fc4"]]},{"id":"4ccbac6f.258fc4","type":"split","z":"4fde9ac6.677204","name":"Split HTML","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":370,"y":280,"wires":[["da3396e8.18af6"]]},{"id":"dd981367.5e87a","type":"change","z":"4fde9ac6.677204","name":"set 'NR_found_topic\"  false","rules":[{"t":"set","p":"NR_found_topic","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":220,"wires":[["b294fa92.d5fc3"]]},{"id":"da3396e8.18af6","type":"switch","z":"4fde9ac6.677204","name":"Have we found the first topic","property":"NR_found_topic","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":180,"y":340,"wires":[[],["b0cd3ab5.71c1c8"]]},{"id":"b0cd3ab5.71c1c8","type":"switch","z":"4fde9ac6.677204","name":"only look at lines containing <meta itemprop='url'","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"<meta itemprop='url'","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":340,"wires":[["cf8b0da0.dfd658"],[]]},{"id":"6225f4ee.acfffc","type":"change","z":"4fde9ac6.677204","name":"set 'NR_found_topic\"  true","rules":[{"t":"set","p":"NR_found_topic","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":420,"wires":[["a5ed800c.64aff8"]]},{"id":"b29ec1ba.4f69b8","type":"inject","z":"4fde9ac6.677204","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":120,"wires":[["b1a4688c.c734a8"]]},{"id":"b1a4688c.c734a8","type":"change","z":"4fde9ac6.677204","name":"","rules":[{"t":"set","p":"NR_last_topic","pt":"flow","to":"first time run","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":120,"wires":[[]]},{"id":"a5ed800c.64aff8","type":"switch","z":"4fde9ac6.677204","name":"see if topic changed","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"NR_last_topic","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":160,"y":480,"wires":[["fbf79e9b.57ac3"]]},{"id":"fbf79e9b.57ac3","type":"change","z":"4fde9ac6.677204","name":"Put topic into flow.NR_last_topic","rules":[{"t":"set","p":"NR_last_topic","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":480,"wires":[["8f52e759.3f12b"]]},{"id":"48152616.621f7","type":"sysmessage","z":"4fde9ac6.677204","command":"osxalert","title":"","subtitle":"","op1":"","op1type":"pay","receiver":"","name":"","x":560,"y":540,"wires":[[]]},{"id":"8f52e759.3f12b","type":"change","z":"4fde9ac6.677204","name":"Clean up msg payload","rules":[{"t":"change","p":"payload","pt":"msg","from":" <meta itemprop='url' content='","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"'>","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":540,"wires":[["48152616.621f7"]]},{"id":"cf8b0da0.dfd658","type":"switch","z":"4fde9ac6.677204","name":"Skip the 'how to share code\" and \"welcome...\" stickies","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"how-to-share-code-or-flow-json","vt":"str"},{"t":"cont","v":"welcome-to-the-node-red-forum","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":260,"y":400,"wires":[[],[],["6225f4ee.acfffc"]]},{"id":"ffa4bd8.e22b4c","type":"comment","z":"4fde9ac6.677204","name":"Runs at startup to initilize the last topic flow variable","info":"","x":230,"y":80,"wires":[]},{"id":"56184af4.d3981c","type":"comment","z":"4fde9ac6.677204","name":"Runs every 5 minutes","info":"","x":140,"y":180,"wires":[]},{"id":"a8b1b757.b2ece8","type":"comment","z":"4fde9ac6.677204","name":"Flow to check for new topics on Node-RED forum","info":"","x":490,"y":20,"wires":[]}]