MQTT gif Payload

Hello,

So i recently bought Synology NAS where current I'm running my HA and node-red and plus my Synology Survalion system. finally this week I setup the telegram system on my SS and HA and everything is working the only problem I have is Synology Survalion cant send a snapshot of motion detection, So I was able to setup a dedicated docker tnx for fabtesta where it will generate .gif file and send it to MQTT. I created flow in node-red and using debug i do see the .gif file in the payload but i dont know how to format so it can send the payload to telegram. I already have telegram setup on Nod-Red.

Is the GIF in a payload or a file?

Essensially, if you get the picture into node-red as a buffer, pass the payload through a function like this...

var pl = {
  content: msg.payload, //payload as a buffer works for me
  message: `here is your picture`,
  type : 'photo',
  chatId: msg.originalMessage.chat.id, //the chatId must be present
  chat: msg.originalMessage.chat, //cant remember if this is important (dont think it is)
  from: msg.originalMessage.from, //cant remember if this is important (dont think it is)
  message_id : msg.originalMessage.message_id //cant remember if this is important (dont think it is)
}

msg.payload = pl; //set the msg.payload before returning it


/* type can be one of the following
photo
audio
video
sticker
voice
document
*/

return msg; //send to next node (the telegram node)

... then to a telegram node

Do i enter my chat id in the function node? And should I use the sender telegram node after the function node?

The chatId should come from somewhere (usually you respond to a telegram message so you get chatId from that - pass it through your nodes into the function node)

Alternatively, like in the screen shot below, you can store the chatId in flow or global context.

NOTE: you can of course hard code the chatId but it'll only ever repond to that one chat.

^ see here, the command /pic sends a message, I route it though some nodes (picking up a camera image or file or web request) then pass the image (buffer) through the function (like the one i posted earlier) then to the sender node.

This what i currently have and my debug mode shows this

Yeah, your buffer is not an image (it would be at least a few thousand bytes if it was an image) - its a file name. That wont work. Try loading the image with a file in node (set to return a buffer)

Is it possible you can share a flow with me? I forgot to mention every gif file are stored on my Synology NAS if this helps

Here you go - if you can make sense of it (delete what you dont need)

PS, does your docker image have access to the files on the NAS? (you will likely need to explicitly set that)


[{"id":"99ee972c.22d088","type":"telegram sender","z":"5d3f964c.fef898","name":"","bot":"fa7a9376.321ce","x":930,"y":300,"wires":[["72b71335.355a9c"]]},{"id":"58e78fc.dd0b27","type":"telegram command","z":"5d3f964c.fef898","name":"/pic","command":"/pic","bot":"fa7a9376.321ce","strict":false,"hasresponse":false,"x":170,"y":300,"wires":[["3eb663cf.b0d58c","bf3c65a6.f27108"]]},{"id":"72b71335.355a9c","type":"debug","z":"5d3f964c.fef898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":970,"y":240,"wires":[]},{"id":"2058d729.1a3a48","type":"function","z":"5d3f964c.fef898","name":"send picture","func":"var pl = {\n  content: msg.payload,\n  message: `Hey ${msg.originalMessage.from.first_name}, here is ${msg.originalMessage.text} you requested`,\n  type : 'photo',\n  chatId: msg.originalMessage.chat.id,\n  chat: msg.originalMessage.chat,\n  from: msg.originalMessage.from,\n  message_id : msg.originalMessage.message_id\n}\n\nmsg.payload = pl;\n\n\n/* type can be one of the following\nphoto\naudio\nvideo\nsticker\nvoice\ndocument\n*/\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":300,"wires":[["99ee972c.22d088"]]},{"id":"959c0404.742708","type":"image","z":"5d3f964c.fef898","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"x":920,"y":360,"wires":[[]]},{"id":"bf3c65a6.f27108","type":"change","z":"5d3f964c.fef898","name":"save chatId","rules":[{"t":"set","p":"chatId","pt":"flow","to":"payload.chatId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":240,"wires":[[]]},{"id":"8391db5a.8f0d58","type":"function","z":"5d3f964c.fef898","name":"send markdown","func":"var message = \n`\n## New message\n\nHello *markdown* formatted messages!'\n\nwith \\`inline\\` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold** \n\n`;\n\nmsg.payload = {chatId : msg.payload, type : 'message', content : message};\n\n// activate markdown\nmsg.payload.options = {\n  disable_web_page_preview : true, \n  parse_mode : \"Markdown\"};\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":240,"wires":[["99ee972c.22d088"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold** "},{"id":"63145ead.8eebb","type":"inject","z":"5d3f964c.fef898","name":"Trigger","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":"","x":410,"y":240,"wires":[["c64e6dd.c31869"]]},{"id":"c64e6dd.c31869","type":"change","z":"5d3f964c.fef898","name":"get chatId","rules":[{"t":"set","p":"payload","pt":"msg","to":"chatId","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":240,"wires":[["8391db5a.8f0d58"]]},{"id":"3eb663cf.b0d58c","type":"switch","z":"5d3f964c.fef898","name":"local, random, camera","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"/pic local","vt":"str"},{"t":"eq","v":"/pic random","vt":"str"},{"t":"eq","v":"/pic camera","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":260,"y":380,"wires":[["7c8090ca.00c02"],["dec15032.19344"],["484d5235.7bc32c"],["c41817dc.703418"]]},{"id":"7c8090ca.00c02","type":"file in","z":"5d3f964c.fef898","name":"load image","filename":"node-red-256.png","format":"","chunk":false,"sendError":false,"encoding":"none","x":510,"y":300,"wires":[["2058d729.1a3a48","959c0404.742708"]]},{"id":"c41817dc.703418","type":"function","z":"5d3f964c.fef898","name":"Dont understand message","func":"var message = \n`\n## I dont understand 🤔\n\nPlease send \\`/pic local\\` or \\`/pic random\\`\n\n`;\n\nmsg.payload.type = 'message';\nmsg.payload.content = message;\n\n// activate markdown\nmsg.payload.options = {\n  disable_web_page_preview : true, \n  parse_mode : \"Markdown\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":480,"wires":[["99ee972c.22d088"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold** "},{"id":"dec15032.19344","type":"http request","z":"5d3f964c.fef898","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"https://picsum.photos/200/300","tls":"","proxy":"","authType":"","x":510,"y":360,"wires":[["959c0404.742708","2058d729.1a3a48"]]},{"id":"484d5235.7bc32c","type":"usbcamera","z":"5d3f964c.fef898","filemode":"0","filename":"image01.jpg","filedefpath":"1","filepath":"","fileformat":"jpeg","resolution":"1","name":"","x":510,"y":420,"wires":[["2058d729.1a3a48"]]},{"id":"fa7a9376.321ce","type":"telegram bot","z":"5d3f964c.fef898","botname":"my_bot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

Yes, my docker has access to the files on NAS how would I tell the system to look for the file that is coming from MQTT buffer as you see every file that is coming from MQTT is different so somehow I need to specify but i dont know how. and where would I need to put MQTT in node? do I put in the begging of the flow?

Firstly, you don't want a buffer, you want a string. So change the setting on your mqtt in to return a string. Next you'll have to concatenate the file name to a path and pass it to a file in node to read the specified file - much like the example flow I posted.

Does this look right?

[{"id":"f46565a7.143a28","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"d81e227.c23a5e","type":"telegram sender","z":"f46565a7.143a28","name":"","bot":"ea8356ea.87f0a8","x":1400,"y":260,"wires":[["87ef4a5e.37f148"]]},{"id":"a4b10c87.c2e68","type":"telegram command","z":"f46565a7.143a28","name":"/pic","command":"/pic","bot":"ea8356ea.87f0a8","strict":false,"x":290,"y":200,"wires":[["8c045307.21b2f","433b7f13.8474a"],[]]},{"id":"87ef4a5e.37f148","type":"debug","z":"f46565a7.143a28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1630,"y":140,"wires":[]},{"id":"6fdfd099.932fc","type":"function","z":"f46565a7.143a28","name":"send picture","func":"var pl = {\n  content: msg.payload,\n  message: `Hey ${msg.originalMessage.from.first_name}, here is ${msg.originalMessage.text} you requested`,\n  type : 'photo',\n  chatId: msg.originalMessage.chat.id,\n  chat: msg.originalMessage.chat,\n  from: msg.originalMessage.from,\n  message_id : msg.originalMessage.message_id\n}\n\nmsg.payload = pl;\n\n\n/* type can be one of the following\nphoto\naudio\nvideo\nsticker\nvoice\ndocument\n*/\n\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":200,"wires":[["d81e227.c23a5e"]]},{"id":"433b7f13.8474a","type":"change","z":"f46565a7.143a28","name":"save chatId","rules":[{"t":"set","p":"chatId","pt":"flow","to":"payload.chatId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":80,"wires":[[]]},{"id":"bdff64b6.c8f578","type":"function","z":"f46565a7.143a28","name":"send markdown","func":"var message = \n`\n## New message\n\nHello *markdown* formatted messages!'\n\nwith \\`inline\\` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold** \n\n`;\n\nmsg.payload = {chatId : msg.payload, type : 'message', content : message};\n\n// activate markdown\nmsg.payload.options = {\n  disable_web_page_preview : true, \n  parse_mode : \"Markdown\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1080,"y":140,"wires":[["d81e227.c23a5e"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold** "},{"id":"d28c5058.bddd1","type":"inject","z":"f46565a7.143a28","name":"Trigger","repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"{}","payloadType":"json","x":630,"y":140,"wires":[["dddedf65.7dd92"]]},{"id":"dddedf65.7dd92","type":"change","z":"f46565a7.143a28","name":"get chatId","rules":[{"t":"set","p":"payload","pt":"msg","to":"chatId","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":140,"wires":[["bdff64b6.c8f578"]]},{"id":"8c045307.21b2f","type":"switch","z":"f46565a7.143a28","name":"local, random, camera","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"eq","v":"/volume1/docker/synology-surveillance-api-motion-mqtt-gifs/gifs","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":560,"y":300,"wires":[["52564207.c7770c"],["e4068474.c5ee08"]]},{"id":"52564207.c7770c","type":"file in","z":"f46565a7.143a28","name":"load image","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":850,"y":200,"wires":[["6fdfd099.932fc"]]},{"id":"e4068474.c5ee08","type":"function","z":"f46565a7.143a28","name":"Dont understand message","func":"var message = \n`\n## I dont understand 🤔\n\nPlease send \\`/pic local\\` or \\`/pic random\\`\n\n`;\n\nmsg.payload.type = 'message';\nmsg.payload.content = message;\n\n// activate markdown\nmsg.payload.options = {\n  disable_web_page_preview : true, \n  parse_mode : \"Markdown\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":960,"y":340,"wires":[["d81e227.c23a5e"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold** "},{"id":"3afd91bf.63caae","type":"mqtt in","z":"f46565a7.143a28","name":"","topic":"synology/cameras/gifs/sidegate","qos":"2","datatype":"utf8","broker":"2ca7e989.0cec46","x":190,"y":560,"wires":[["8c045307.21b2f"]]},{"id":"c44f2004.86643","type":"mqtt in","z":"f46565a7.143a28","name":"","topic":"synology/cameras/gifs/kitchenside","qos":"2","datatype":"utf8","broker":"2ca7e989.0cec46","x":200,"y":500,"wires":[["8c045307.21b2f"]]},{"id":"46323f6.9f771c","type":"mqtt in","z":"f46565a7.143a28","name":"","topic":"synology/cameras/gifs/garageback","qos":"2","datatype":"utf8","broker":"2ca7e989.0cec46","x":200,"y":440,"wires":[["8c045307.21b2f"]]},{"id":"9349caa7.3808b8","type":"mqtt in","z":"f46565a7.143a28","name":"","topic":"synology/cameras/gifs/garagefront","qos":"2","datatype":"utf8","broker":"2ca7e989.0cec46","x":200,"y":380,"wires":[["8c045307.21b2f"]]},{"id":"22c6a76c.b54468","type":"mqtt in","z":"f46565a7.143a28","name":"","topic":"synology/cameras/gifs/sittingarea","qos":"2","datatype":"utf8","broker":"2ca7e989.0cec46","x":200,"y":320,"wires":[["8c045307.21b2f"]]},{"id":"ea8356ea.87f0a8","type":"telegram bot","z":"f46565a7.143a28","botname":"my_bot","usernames":"","chatids":"12345678","baseapiurl":"","updatemode":"polling","pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"2ca7e989.0cec46","type":"mqtt-broker","z":"","name":"","broker":"10.0.0.50","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Not on my computer. Post a screenshot of the flow and a screenshot of the debug message before and after the file in node.

Here you go

No idea what you have there but I suspect the mqtt hasn't triggered.

Also, Have you sent a message from telegram to your bot ?

That blue telegram node on the left is a command node and expects you to send /pic then you can grab the chatId.

Do you know how the telegram nodes work? If not, you need to play around a bit before you try doing more complicated stuff with images etc.

Also, what's that error message.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.