Hi all,
I'm having trouble with a flow I'm trying to create - I'm sure there is an easier way of doing this whole flow, if so, please let me know...
I have a "collection" of a few pictures that I want to send to a telegram bot in a random order triggered by an MQTT message.
Attached to these pictures, as captions, I want to have text - also attached randomly.
The format of the last send function node is correct for the Telegram node.
The issue I'm having is with the "Caption Picker" function node. I tried using msg.topic = "Caption"
so the join node could get the info, but I can't seem to get it right... I'm assuming the if/else function node isn't formatted correctly or something is not allowing the msg.topic = "Caption"
to be sent on...
I want different combinations of picture/text for the messages - as not to have the same old picture/text combo all the time. What would be great would be a random node that output predefined text
I did search the Node Library, but couldn't find anything...
Like I say, if I can do this in a simpler way please let me know.
Thanks in advance everyone
[{"id":"6ec407e95e9dbbb3","type":"group","z":"090649e01c38995f","name":"Example Flow","style":{"stroke":"#92d04f","fill":"#e3f3d3","fill-opacity":"0.3","label":true,"label-position":"ne","color":"#000000"},"nodes":["7c766c69e31fb170","3ff9f1d47969adc9","369030915ece8ff4","973be7a50f93fb9b","35c3ee8b9adcf61a","8e625554fa800735","81931ab6a02d4695","ae4540e4f1533d28","cbd338ce86a850c1"],"x":44,"y":319,"w":912,"h":192},{"id":"7c766c69e31fb170","type":"random","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"","low":1,"high":"5","inte":"true","property":"payload","x":300,"y":390,"wires":[["8e625554fa800735"]]},{"id":"3ff9f1d47969adc9","type":"random","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"","low":1,"high":"5","inte":"true","property":"payload","x":300,"y":430,"wires":[["cbd338ce86a850c1"]]},{"id":"369030915ece8ff4","type":"inject","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":410,"wires":[["3ff9f1d47969adc9","7c766c69e31fb170"]]},{"id":"973be7a50f93fb9b","type":"debug","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":820,"y":470,"wires":[]},{"id":"35c3ee8b9adcf61a","type":"join","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":500,"y":410,"wires":[["81931ab6a02d4695"]]},{"id":"8e625554fa800735","type":"function","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"","func":"msg.topic = \"Photo\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":360,"wires":[["35c3ee8b9adcf61a"]]},{"id":"81931ab6a02d4695","type":"function","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"Send","func":"msg.method = \"sendPhoto\";\nmsg.payload = {\n photo: \"/home/pi/Picture\" + msg.payload.Photo + \".png\",\n caption: msg.payload.Caption\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":410,"wires":[["973be7a50f93fb9b","ae4540e4f1533d28"]]},{"id":"ae4540e4f1533d28","type":"telegrambot-payload","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"","bot":"","chatId":"","sendMethod":"","payload":"","x":840,"y":410,"wires":[[]]},{"id":"cbd338ce86a850c1","type":"function","z":"090649e01c38995f","g":"6ec407e95e9dbbb3","name":"Caption Picker","func":"msg.topic = \"Caption\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":460,"wires":[["35c3ee8b9adcf61a"]]},{"id":"f763a52cb615f42a","type":"group","z":"090649e01c38995f","name":"Problem Flow","style":{"stroke":"#ff0000","fill":"#ffbfbf","fill-opacity":"0.3","label":true,"label-position":"ne","color":"#000000"},"nodes":["bdd3c2f42db2cd92","af7dcb1b24182bb8","8b4b33c4fd93ee02","43f40d863406bdc2","bfe136ab82242bcf","edfac785d9ae747f","9ba20c469316b028","2fb5d1d37eae0de2","41fdbacc8728e3a5"],"x":44,"y":129,"w":912,"h":192},{"id":"bdd3c2f42db2cd92","type":"random","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"","low":1,"high":"5","inte":"true","property":"payload","x":300,"y":200,"wires":[["edfac785d9ae747f"]]},{"id":"af7dcb1b24182bb8","type":"random","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"","low":1,"high":"5","inte":"true","property":"payload","x":300,"y":240,"wires":[["41fdbacc8728e3a5"]]},{"id":"8b4b33c4fd93ee02","type":"inject","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":220,"wires":[["af7dcb1b24182bb8","bdd3c2f42db2cd92"]]},{"id":"43f40d863406bdc2","type":"debug","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":820,"y":280,"wires":[]},{"id":"bfe136ab82242bcf","type":"join","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":500,"y":220,"wires":[["9ba20c469316b028"]]},{"id":"edfac785d9ae747f","type":"function","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"","func":"msg.topic = \"Photo\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":170,"wires":[["bfe136ab82242bcf"]]},{"id":"9ba20c469316b028","type":"function","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"Send","func":"msg.method = \"sendPhoto\";\nmsg.payload = {\n photo: \"/home/pi/Picture\" + msg.payload.Photo + \".png\",\n caption: msg.payload.Caption\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":220,"wires":[["43f40d863406bdc2","2fb5d1d37eae0de2"]]},{"id":"2fb5d1d37eae0de2","type":"telegrambot-payload","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"","bot":"","chatId":"","sendMethod":"","payload":"","x":840,"y":220,"wires":[[]]},{"id":"41fdbacc8728e3a5","type":"function","z":"090649e01c38995f","g":"f763a52cb615f42a","name":"Caption Picker","func":"msg.topic = \"Caption\"\n\nvar msg1 = \"Text 1\"\nvar msg2 = \"Text 2\"\nvar msg3 = \"Text 3\"\nvar msg4 = \"Text 4\"\n\nif (msg.payload == \"1\") {\n return {payload: msg1}\n} else if (msg.payload == \"2\") {\n return {payload: msg2}\n} else if (msg.payload == \"3\") {\n return {payload: msg3}\n} else {\n return {payload:msg4}\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":270,"wires":[["bfe136ab82242bcf"]]}]