URL Expander
This subflow node expands all urls present in a string in msg.payload, in the form http://xxx or https://xxx.
It uses unshorten.me service.
For instance, if it finds http://goo.gl/IGL1lE output payload will contain https://unshorten.me/.
If an url is not shorted it will be kept the same.
It may be other contents in the string, the are kept untouched and sent forward to output
Output 1: String with unshorted urls
Output 2: Outputs every found URL
Output 3: Outputs every expanded URL
[{"id":"141a0710.3db4b9","type":"subflow","name":"Unshorten URLs","info":"This subflow node expands all **urls** present in a string in **msg.payload**, in the form http://xxx or https://xxx.\n\nIt uses [unshorten.me](http://unshorten.me) service.\n\nFor instance, if it finds http://goo.gl/IGL1lE output payload will contain https://unshorten.me/.\n\nIf an **url** is not shorted it will be kept the same.\n\nIt may be other contents in the string, the are kept untouched and sent forward to output\n\nOutput 1: String with unshorted **urls**\n\nOutput 2: Outputs every found URL\n\nOutput 3: Outputs every expanded URL","in":[{"x":100,"y":540,"wires":[{"id":"5cf3b361.142914"}]}],"out":[{"x":1480,"y":540,"wires":[{"id":"353ede66.c54cfa","port":0}]},{"x":1560,"y":300,"wires":[{"id":"8965f687.09b0b8","port":0}]},{"x":1560,"y":240,"wires":[{"id":"b9d2da28.852188","port":0}]}],"outputLabels":["payload","Found URL","Unshorted URL"]},{"id":"aa0087aa.032958","type":"change","z":"141a0710.3db4b9","name":"Get next URL","rules":[{"t":"set","p":"urlexpander.urls","pt":"msg","to":"urlexpander.buffer.$match(/((http:|https:)+[^\\s]+[\\w])/,1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":480,"wires":[["d283ec72.3b21d8"]]},{"id":"d283ec72.3b21d8","type":"change","z":"141a0710.3db4b9","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://unshorten.me/json/\" & urlexpander.urls.match","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":480,"wires":[["b540c418.f144d"]]},{"id":"b540c418.f144d","type":"http request","z":"141a0710.3db4b9","name":"","method":"GET","ret":"txt","url":"","x":1090,"y":480,"wires":[["edd33b90.fd56f8"]]},{"id":"d8a00ecb.e82128","type":"change","z":"141a0710.3db4b9","name":"","rules":[{"t":"set","p":"urlexpander.buffer","pt":"msg","to":"$replace(urlexpander.buffer,payload.requested_url, \"\")","tot":"jsonata"},{"t":"set","p":"urlexpander.orig_payload","pt":"msg","to":"$replace(urlexpander.orig_payload,payload.requested_url, payload.resolved_url)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":280,"wires":[["90d5cee9.543cf"]]},{"id":"edd33b90.fd56f8","type":"json","z":"141a0710.3db4b9","name":"","property":"payload","action":"obj","pretty":false,"x":1250,"y":480,"wires":[["d8a00ecb.e82128","c1f7f31c.bee338"]]},{"id":"5cf3b361.142914","type":"change","z":"141a0710.3db4b9","name":"Store data","rules":[{"t":"set","p":"urlexpander.buffer","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"urlexpander.orig_payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":540,"wires":[["90d5cee9.543cf"]]},{"id":"90d5cee9.543cf","type":"switch","z":"141a0710.3db4b9","name":"while !finished","property":"urlexpander.buffer","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"urlexpander.buffer.$contains(/((http:|https:)+[^\\s]+[\\w])/)","vt":"jsonata"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":520,"y":540,"wires":[["aa0087aa.032958"],["353ede66.c54cfa"]]},{"id":"353ede66.c54cfa","type":"change","z":"141a0710.3db4b9","name":"Clean data","rules":[{"t":"move","p":"urlexpander.orig_payload","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"urlexpander","pt":"msg"},{"t":"delete","p":"url","pt":"msg"},{"t":"delete","p":"responseUrl","pt":"msg"},{"t":"delete","p":"responseCookies","pt":"msg"},{"t":"delete","p":"headers","pt":"msg"},{"t":"delete","p":"statusCode","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":950,"y":540,"wires":[[]]},{"id":"8965f687.09b0b8","type":"change","z":"141a0710.3db4b9","name":"RequestedURL","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.requested_url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":300,"wires":[[]]},{"id":"b9d2da28.852188","type":"change","z":"141a0710.3db4b9","name":"UnshortedURL","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.resolved_url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":240,"wires":[[]]},{"id":"c1f7f31c.bee338","type":"change","z":"141a0710.3db4b9","name":"Clean data","rules":[{"t":"delete","p":"urlexpander","pt":"msg"},{"t":"delete","p":"url","pt":"msg"},{"t":"delete","p":"responseUrl","pt":"msg"},{"t":"delete","p":"responseCookies","pt":"msg"},{"t":"delete","p":"headers","pt":"msg"},{"t":"delete","p":"statusCode","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190,"y":280,"wires":[["b9d2da28.852188","8965f687.09b0b8"]]},{"id":"3438c5e1.ae3382","type":"subflow:141a0710.3db4b9","z":"91ed6400.da2168","name":"Unshorten URLs","x":450,"y":520,"wires":[["64be5fcb.cb107"],["ebb5e3aa.9c5488"],["c81ba7c1.5cf1a8"]]}]