How to send a picture through Telegram?

Just for the record, my telegram is working fine with messages :slight_smile:

Without the actual flow, a bit hard to tell, but the above looks ok. Although for debugging (and Prod) I would substitute the function node for a Change node. It makes visualising what is happening a bit easier.

Also, put in the absolute path and name of the image file, and hard code your chatid as well. Again, easy to do using a Change node.

1 Like

Hi Bobo.

Sorry for my late reply, hobby project gets worked on when there are time (usualy weekends).

Thanks for the input, i used a wrong chad.ID, that seemed to have been my problem.

I toke your advice and tried to change my function node with a change node, but it will not accept my chatId. Can you see what i have done wrong (Change node left side of attached picture and error log on right)?

Do you have an l instead of a capital I in chatId?

1 Like

Hi Zenofmud.

It also catched my eye, but it is a capital "i" and not a 1.

Best regards

Please export your flow and put it in a response after reading this thread: How to share code or flow json

Not sure I'd agree with that part since it is like an address, not sure what the consequences of that might be if you shared it.

Sorry, not sure I understand your comment. Shared with whom? I was referring to debugging the issue.

Well, your chat id is an identifier in Telegram, putting it in this forum potentially shares it with a lot of people. Depending on the configuration you are using, I now have access to a group or person in Telegram and I'm not sure you want that. It is like sharing a user ID.

Julian, I didn't ask the op to put his chatid in this forum. I asked him to hard code it in the Change node, along with everything else, to facilitate his debugging of the issue.

No, but you asked the OP to hard code it into the flow & that means that it is likely to be shared if the flow is posted here. Indeed, the OP has posted their chatid. This is not, in my view, good practice.

I never said it was good practice, indeed some may say it is not good practice to publish a "working flow" at all.

But perhaps you should be addressing your comments to the op instead of me? Just a thought. In any case, there is an easy fix for a compromised chatid.

Hi guys. Thank you for the concern. It is my understanding that it is only the identifier for the chat that i have going with my telegram_bot. I would think that it requires some sort of code for actually joining the chat, but even if someone should join that conversation it is only for testing purposes (I will start a new topic for the actual production). If someone else joins the conversation i will try to bore them to death with technical questions :stuck_out_tongue:

However posting my JSON flow would expose my login and password, so that i will have to hide... maybe i just change it to some dummy login and passwords, before uploading it.

However i am not at home, but will do it later.

3 Likes

In most cases, ids and passwords are configured in nodes to be credential items These are stored encrypted by Node-RED in a separate JSON file and are not included when you export a flow.

There is also a credentials node if you want to manually put sensitive data somewhere more secure.

Ok so here are the flow.

I checked and TotallyInformation are correct regarding passwords, they are not in the flow.

So in the exported flow i am only connected to the working function node and not the none-working Change node (see picture). Just to be clear, it does not work when i bypass my function node, through the change node. The change node should do the exact same thing as the function node, but it does not.

[{"id":"aa33016d.b3794","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"6618ba55.82d724","type":"telegram sender","z":"aa33016d.b3794","name":"","bot":"152ce6b7.4d69c9","x":490,"y":160,"wires":[["1be6d811.298e28"]]},{"id":"46ab6f8e.9252d","type":"inject","z":"aa33016d.b3794","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":160,"wires":[["556f04ec.6413ec"]]},{"id":"556f04ec.6413ec","type":"function","z":"aa33016d.b3794","name":"build payload","func":"msg.payload = {chatId: \"1049505879\", type: \"photo\", content: \"/home/pi/Pictures/cat.jpg\", caption:\"Picture of cat\"};\n\n//chatId: msg.chatId,\n//msg.payload.content= \"/home/pi/Pictures/cat.jpg\";\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":160,"wires":[["6618ba55.82d724"]]},{"id":"1be6d811.298e28","type":"debug","z":"aa33016d.b3794","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.content","targetType":"msg","x":740,"y":160,"wires":[]},{"id":"d1a5f53e.867708","type":"change","z":"aa33016d.b3794","name":"","rules":[{"t":"set","p":"payload.chatId","pt":"msg","to":"1049505879","tot":"str"},{"t":"set","p":"payload.type","pt":"msg","to":"photo","tot":"str"},{"t":"set","p":"payload.content","pt":"msg","to":"/home/pi/Pictures/cat.jpg","tot":"str"},{"t":"set","p":"payload.caption","pt":"msg","to":"Picture of cat","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":240,"wires":[[]]},{"id":"152ce6b7.4d69c9","type":"telegram bot","z":"","botname":"Resedavej_test_bot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

You need to remove the existing number from the payload in order to create a new type of object

1 Like

Perfect, that worked. Thank you.

But i do not understand why i had to delete the payload, i have never put anything in it, should it not be empty to start with or am i missing what the inject node does?

If you read the Info tab of the inject node you will see:

Injects a message into a flow either manually or at regular intervals. The message payload can be a variety of types, including strings, JavaScript objects or the current time.

if you create msg.payload as a json object (stick in {}) then you wouldn't have to delete msg.payload because it would already be an object.

1 Like

Ahh i see... i thought it was already a json object, i think that also explains some other troubles i have encountered. Maybe i should sit down and study the manual a bit more before rushing into a project :slight_smile:

Thank you so much for all your help.

Best regards

to be fair - that is indeed (yet another) a subtlety of javascript. If the object is an object it's easy to add/edit/remove properties. If it's a type like a number or string (or boolean) then that can't be assigned extra properties so trying to add them will fail.