Telegram - how to send an image

Hi.

Sending a message to telegram. it works.
I don't know how to add an image.
Advice?
Thank you.

Did you check in the built in examples ?

I can send text (Message).
I can send a photo.
I can't send text + photo at once

No at computer, but i seem to remember that you can send a caption with a image. msg.payload.caption I think. https://raw.githubusercontent.com/windkh/node-red-contrib-telegrambot/refs/heads/master/examples/sendphoto.json

This is a simple flow example (if you would like to view the image being sent in the NR editor, please install node-red-contrib-image-tools ). The example monitors a folder and if you drop an image to it, it will be read and sent. Obviously you can feed the function node with image data directly in other ways

[
    {
        "id": "88d8ff214f48ece7",
        "type": "function",
        "z": "be169c56949ba685",
        "name": "Create image for Telegram",
        "func": "var cId = 123456;\n\nmsg.payload = { chatId: cId, type:\"photo\", content:msg.payload, caption:\"Snapshot of image\"};\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 80,
        "wires": [
            [
                "95114cabc3339005"
            ]
        ]
    },
    {
        "id": "95114cabc3339005",
        "type": "telegram sender",
        "z": "be169c56949ba685",
        "name": "",
        "bot": "a0a9832f.04aa5",
        "haserroroutput": false,
        "outputs": 1,
        "x": 980,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "47abe4fc60e4e1ae",
        "type": "image viewer",
        "z": "be169c56949ba685",
        "name": "",
        "width": 160,
        "data": "payload",
        "dataType": "msg",
        "active": true,
        "x": 720,
        "y": 150,
        "wires": [
            []
        ]
    },
    {
        "id": "d9231585ae2a792b",
        "type": "file in",
        "z": "be169c56949ba685",
        "name": "",
        "filename": "filename",
        "filenameType": "msg",
        "format": "",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 500,
        "y": 80,
        "wires": [
            [
                "88d8ff214f48ece7",
                "47abe4fc60e4e1ae",
                "c8aa613381b1b29b"
            ]
        ]
    },
    {
        "id": "dd24b7769ad4adf7",
        "type": "watch",
        "z": "be169c56949ba685",
        "name": "",
        "files": "/home/pi/Pictures",
        "recursive": "",
        "x": 170,
        "y": 80,
        "wires": [
            [
                "86107013c36ba942"
            ]
        ]
    },
    {
        "id": "946937a69c9686d3",
        "type": "comment",
        "z": "be169c56949ba685",
        "name": "Monitor folder for new images and send them via Telegram",
        "info": "",
        "x": 290,
        "y": 40,
        "wires": []
    },
    {
        "id": "86107013c36ba942",
        "type": "delay",
        "z": "be169c56949ba685",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 350,
        "y": 80,
        "wires": [
            [
                "d9231585ae2a792b"
            ]
        ]
    },
    {
        "id": "a0a9832f.04aa5",
        "type": "telegram bot",
        "botname": "Testchat",
        "usernames": "",
        "chatids": "",
        "baseapiurl": "",
        "updatemode": "polling",
        "pollinterval": "300",
        "usesocks": false,
        "sockshost": "",
        "socksport": "6667",
        "socksusername": "anonymous",
        "sockspassword": "",
        "bothost": "",
        "botpath": "",
        "localbotport": "8443",
        "publicbotport": "8443",
        "privatekey": "",
        "certificate": "",
        "useselfsignedcertificate": false,
        "sslterminated": false,
        "verboselogging": false
    }
]
1 Like

I think you will find msg.payload.type should be 'photo' not 'message' in the 'change' node.

You can also include a caption for the photo with...

msg.payload.caption "this is a photo of a cat"

It already works. Thank you

Thank you, for reviving this. I looked into it several years ago but sending images via the cellphone provider's Email to MMS gateway was easier and worked very well, and had the major benefit of not needing to install anything on my wife's phone and then having to teach her how to use it. Also was trivial to redirect the images to my neighbor when we went on vacation.

But a bit over a year ago FCC/FTC rules in the US caused all providers (as far as I can tell) to adopt "anti-spam" filters on the gateways. Some providers just turned off the gateways, most others bought a lame third party solution that blocks more than one message from the source in a three or four hour (or longer) interval. Sometimes message are delayed for a day or more! I send duplicates to the Gateway and my Gmail. It used to be a race that the MMS Gateway almost always won, now Gmail almost always wins and I can rarely get more than a couple of MMS messages a day to go through.

Trying to use Telegram is high on my todo list now, moreso since we have a vacation trip coming up in April.

1 Like

(Slight aside - if you just need to push an image (plus text of course) - then I find the Pushover app (and node) much easier to use than Telegram - If you need two way interaction then yes go with Telegram)

1 Like

Thanks, I'll look into it!