Nodered & http post node

Hello

I am trying to trigger a telegram msg with a http post node from nodered.

I have the following flow:

image

The http node consists of the following:

Obviously I have removed the API and chat ID for security reasons. But if I type that same URL into my browser, the message sends to my telegram bot.

When I hit the timestamp in the flow, I get "NO RESPONSE FROM SERVER" under the HTTP node.

Any ideas what I am doing wronG?

A browser will perform a GET, you have set POST.

Is there any reason you are not using the already pre build & highly capable node-red-contrib-telegrambot nodes?

the GET returns a "NO RESPONSE FROM SERVER"

I tried the telegram nodes, but I kept getting errors every time it polled. See below

image

I have entered the following:

  • Bot-name is my bot name
  • Token is the HTTP API code provided by Botfather
  • Users is my user name
  • Chat ID is the ID provided by IDbot

I couldn't figure out why I kept getting this polling error, so I tried the HTTP node since I know I can send messages to the bot from my browser. But that's not working either!

does your node-red instance have a route to the telegram api?

As i am certain you know, node-red can run in a completely different place to your browser.

for example, node-red could be running in a docker container with no access to the outside world!

The url i use for http requests is,
https://api.telegram.org/bot1dhdhhrrjjddkkLzFW_525Kmrl-ilr5EfE/sendMessage?chat_id=-5874643834082&text={{payload}}

You may need to add the https://
and method get, and ignore payload.

Also check the request node can do a get request to say https://www.google.com.

If you are getting errors from telegrambot, it would be best to show them to us. Add debug nodes set to full message object, telegram gives good error messages normally.

Also show how the telegrambot config is set, obviously use fake chat and bot api keys.

Thanks for the replies. Node red is not running in a docker.

The request to google works fine, I get a bunch of jargon from google.

I tried your url in the http request node with the following options:

In the debug node I get the following:

payload: "RequestError ...."
topic: ""
statusCode: "ETIMEDOUT"

When I paste that exact same URL in a browser, the message works fine.

This flow works fine for me, add your api key and chatid and test

[{"id":"153ea825a8452766","type":"inject","z":"bf510de9c34b4fc2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":600,"y":320,"wires":[["1f07ee7d.d6edda"]]},{"id":"1f07ee7d.d6edda","type":"http request","z":"bf510de9c34b4fc2","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://api.telegram.org/bot1234567890qwertyuiopasdfghjk/sendMessage?chat_id=-264836494082&text={{payload}}","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":750,"y":320,"wires":[["16725a2ced4bf3d4"]]},{"id":"16725a2ced4bf3d4","type":"debug","z":"bf510de9c34b4fc2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":320,"wires":[]}]

returns

{
    "_msgid": "977a59a428ba099f",
    "payload": {
        "ok": true,
        "result": {
            "message_id": 20969,
            "from": {
                "id": 125467896,
                "is_bot": true,
                "first_name": "******",
                "username": "********"
            },
            "chat": {
                "id": -**************,
                "title": "*********",
                "type": "*********"
            },
            "date": 1703891201,
            "text": "1703891201865"
        }
    },
    "topic": "",
    "statusCode": 200,
    "headers": {
        "server": "nginx/1.18.0",
        "date": "Fri, 29 Dec 2023 23:06:41 GMT",
        "content-type": "application/json",
        "content-length": "237",
        "connection": "keep-alive",
        "strict-transport-security": "max-age=31536000; includeSubDomains; preload",
        "access-control-allow-origin": "*",
        "access-control-allow-methods": "GET, POST, OPTIONS",
        "access-control-expose-headers": "Content-Length,Content-Type,Date,Server,Connection",
        "x-node-red-request-node": "26a69c1a"
    },
    "responseUrl": "https://api.telegram.org/bot*************************/sendMessage?chat_id=-***********&text=1703891201865",
    "redirectList": [],
    "retry": 0
}

If that fails please export your test flow so we can see exactly what you have entered, please alter chatid and api for security.

Nope did not work.

here is the flow:

[
    {
        "id": "4bd8072b210bc49c",
        "type": "http request",
        "z": "94e3a7440c826f1f",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://api.telegram.org/botAPI_KEY_HERE/sendMessage?chat_id=CHAT_ID_HERE&text={{payload}}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "basic",
        "senderr": false,
        "headers": [],
        "x": 390,
        "y": 140,
        "wires": [
            [
                "21af778c8feed1d3"
            ]
        ]
    },
    {
        "id": "21af778c8feed1d3",
        "type": "debug",
        "z": "94e3a7440c826f1f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 140,
        "wires": []
    },
    {
        "id": "1af5636fbf63f643",
        "type": "inject",
        "z": "94e3a7440c826f1f",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 240,
        "y": 140,
        "wires": [
            [
                "4bd8072b210bc49c"
            ]
        ]
    }
]

Here is the complete debug message:

image

Again, when I copy that exact link into my browser, the message sends :frowning:

You did not use my flow and add your api and chat id.

In your test flow you have use basic auth set.

Try my flow and add your bot api key and the chatid in the url, instead of the ones added..

If you want you can send me the api and chatid in a PM so I can test.

Sorry not sure what happened, here is the flow:

[
    {
        "id": "153ea825a8452766",
        "type": "inject",
        "z": "185499ce70cfb9ef",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 6260,
        "y": 720,
        "wires": [
            [
                "1f07ee7d.d6edda"
            ]
        ]
    },
    {
        "id": "1f07ee7d.d6edda",
        "type": "http request",
        "z": "185499ce70cfb9ef",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://api.telegram.org/botAPIKEY/sendMessage?chat_id=CHATID&text={{payload}}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 6410,
        "y": 720,
        "wires": [
            [
                "16725a2ced4bf3d4"
            ]
        ]
    },
    {
        "id": "16725a2ced4bf3d4",
        "type": "debug",
        "z": "185499ce70cfb9ef",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 6550,
        "y": 720,
        "wires": []
    }
]

Here is the debug:

I can send you the actual flow with the API key etc. if you have no other suggestions?

I have received your flow and sent you a message to telegram, i get a 200 response and seems to be working fine for me. Did you get 2 messages from me one a timestamp another some text?

Yep I got your messages, I have no idea why it's not working on my flow :frowning:

Strange as you can send http request to google but not telegram url, I can only think is there some form of firewall or DNS issue. The error you receive seems to be from the http node, not your usual error response from telegram.
What is node-red running on, and what do you receive from the google url if you add it to my flow example.

I've also tried pinging api.telegram.org from terminal and it pings fine so that would eliminate DNS issue, the host name resolves to the api.telegram.org IP address.

It's not a firewall issue on the machine. I've also checked router logs, nothing shows up there.

Node red is running on ubuntu.

I get the following when I try www.google.com:

image

Also I get the same error response when I try www.telegram.org with the HTTP GET node.

Interestingly enough, I recall this working fine before I upgraded to Ubuntu 22.04 and node.js version 20.10.0. Maybe that has something to do with it?

May be, I also notice that the google url is not https.
There does seem to be issues on this and nodejs 20 ubuntu https issue at DuckDuckGo

Ah it might be an ipv4/ipv6 thing.

Ping telegram, get the ip and use that in the URL.

Does node20 prioritise ip6 over ip4?

Kinda, since node 18. Iirc since v18, node no longer sorts IP address lookups but returns them as is. Can't find the memo tho to back this up

1 Like

I think there is a flag somewhere to tell it to return ip4 first

1 Like