Sending messages to 2 different bots in Telegram

Hello,
I am new to Nodered, i want to use it in Home Assistant because i would like to send different categories of messages to different bots in Telegram.
Aparently Nodered is a good way to achiebve sending to several bots.
So, i installed it, and tried an example with 2 bots.

My 2 bots, Alerte and Gonthiers, are created, API token got for each bot, Chat ID found also in Telegram.

In Nodered, i have added the node-red-contrib-telegrambot.

Flows are :
image
image

In each telegram sender i have all parameters set, with dedicated token and name for each bot.

But only the second bot, Gonthiers, is connected, the first one, Alerte, says :
"TypeError: Cannot read properties of null (reading 'botname')"

Both are described in the same way.

My first trial with this Alerte bot was succesfull, problems started when i created a flow to send to Gonthiers.

And now, even if i remove the second flow to Gonthiers, the first one gives still the same error.

I can provide more details, but clearly there is something i don't know or understand...

Hi and welcome to the forum.

Sending to two bots works as i have 2 bots and all works fine.
It is most likely you have not set up 2 separate config nodes, use the + icon to add a separate config for the second bot,.

Please export the flows and paste here, so wee can see if there are any mistakes in your flows. Your botkeys are not exported with the flow if in config nodes, else please obscure the keys and chatids.

How to import/export a flow

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

I can export, i have found how, but i can see the chat id easily and remove it, but what are the keys to be obscured also ?

But if i try to create only 1 flow, with the +, it works if i use the Gonthiers bot, but it doesn't work if i use the Alerte bot.

Again please export your flows.

By key i mean bot key and chatid. If they are in the config node they will be excluded form an export automatically.

Here is the export, i removed the chatid, the bot key doesn't seems to be inside

The message got when i deploy it is : "TypeError: Cannot read properties of null (reading 'botname')"

[
    {
        "id": "b0f39ff40427433d",
        "type": "tab",
        "label": "Envoi Test sur Alerte",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8762ab0182274272",
        "type": "inject",
        "z": "b0f39ff40427433d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 110,
        "y": 220,
        "wires": [
            [
                "bb87ea5087378e45"
            ]
        ]
    },
    {
        "id": "2f83d99970d36a7b",
        "type": "debug",
        "z": "b0f39ff40427433d",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 800,
        "y": 220,
        "wires": []
    },
    {
        "id": "bb87ea5087378e45",
        "type": "function",
        "z": "b0f39ff40427433d",
        "name": "function 1",
        "func": "var content = \"hello de nodered\"\nmsg.payload = {\n    \"chatId\": 56xxxxxx20,\n    \"sentMessageId\":46,\n    \"type\":\"message\",\n    \"content\":content}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 220,
        "wires": [
            [
                "ae26373ca5d12a0b"
            ]
        ]
    },
    {
        "id": "ae26373ca5d12a0b",
        "type": "telegram sender",
        "z": "b0f39ff40427433d",
        "name": "",
        "bot": "837f5f4ab454a0a6",
        "haserroroutput": false,
        "outputs": 1,
        "x": 550,
        "y": 220,
        "wires": [
            [
                "2f83d99970d36a7b"
            ]
        ]
    },
    {
        "id": "837f5f4ab454a0a6",
        "type": "telegram bot",
        "botname": "Alerte",
        "usernames": "Alerte47bot",
        "chatids": "",
        "baseapiurl": "",
        "testenvironment": false,
        "updatemode": "polling",
        "addressfamily": "",
        "pollinterval": "300",
        "usesocks": false,
        "sockshost": "",
        "socksprotocol": "socks5",
        "socksport": "6667",
        "socksusername": "anonymous",
        "sockspassword": "",
        "bothost": "",
        "botpath": "",
        "localbotport": "8443",
        "publicbotport": "8443",
        "privatekey": "",
        "certificate": "",
        "useselfsignedcertificate": false,
        "sslterminated": false,
        "verboselogging": false
    }
]

edit : without changing anything, it says now "connected" but give the followinf message when launched "TypeError: Cannot read properties of null (reading 'getTelegramBot')"

That is one flow , I asked for the flows. So i could see if you had 2 configs or 1. Please supply both flows.

there is no other flow now as i remove the other one to check if there was an interaction between them

Questions : the chatid should be the same for all bots ? i got it through a getid bot in Telegram and it seems to be an ID for my Telegram, so unique ? is that right ?

The situation is now, that with only this flow,, if create a sender with the bot "Gonthiers", it works, if i remove and delete it and create another sender with "Alerte" it still says "TypeError: Cannot read properties of null (reading 'botname')", same as in the posts above

As i have said there is a high possibility that you had both flows using the same config node, without the OG flows I can not see the issue that caused it.

I suggest deleting the flow, then go to the config sidebar and delete all unused telegram bot configs.

Then recreate the flows and when you create the second, make sure you click the + icon when adding a new bot key.

The chat id depends on what and where you are sending the message, There are member chatid's and group chatid's

[edit] OG = original

have you got two bots in telegram as well as the botfather?

1 Like

ok, maybe i don't understand what you call the "OG flow" ?

It's not what i put in the post 5 ?

Edit : i see OG = original, that's what is in the post 5.... i guess, thta's all i have

But i will : unistall Nodered from HA, to be sure that all is resetted, réinstall, recreate flows and test...

You do not need to uninstall node-red, just the flow/s.
OG as in post 1 flows.

If you require help it is best to not change the goal posts, you originally showed two flows, which were conflicting. rather than wait you deleted one of them, I would of expected a deply error if you had 2 configs, as there would of been a unused config left with out a flow.

Maybe you sgould watch the essentials videos to get a basic understandingof how flows and configeration nodes work. it is really worth watching.

donc, uninstall / réinstall Nodered avec suppression data : ok
résintall node-red-contrib-telegrambot : ok

recréation d'un flux simple :

[
    {
        "id": "c93d76e425518d9b",
        "type": "tab",
        "label": "Flux 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "27dbf17afad2e3b4",
        "type": "telegram sender",
        "z": "c93d76e425518d9b",
        "name": "",
        "bot": "f9e88713e8567cb0",
        "haserroroutput": false,
        "outputs": 1,
        "x": 490,
        "y": 200,
        "wires": [
            [
                "2b026e37f524e43d"
            ]
        ]
    },
    {
        "id": "e4352dfd80d583bb",
        "type": "inject",
        "z": "c93d76e425518d9b",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"type\":\"message\",\"chatId\":56xxxxxx20,\"content\":\"Hello envoi sur bot Alerte\"}",
        "payloadType": "json",
        "x": 70,
        "y": 200,
        "wires": [
            [
                "27dbf17afad2e3b4"
            ]
        ]
    },
    {
        "id": "2b026e37f524e43d",
        "type": "debug",
        "z": "c93d76e425518d9b",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 200,
        "wires": []
    },
    {
        "id": "f9e88713e8567cb0",
        "type": "telegram bot",
        "botname": "Alerte",
        "usernames": "Alerte47bot",
        "chatids": "",
        "baseapiurl": "",
        "testenvironment": false,
        "updatemode": "polling",
        "addressfamily": "",
        "pollinterval": "300",
        "usesocks": false,
        "sockshost": "",
        "socksprotocol": "socks5",
        "socksport": "6667",
        "socksusername": "anonymous",
        "sockspassword": "",
        "bothost": "",
        "botpath": "",
        "localbotport": "8443",
        "publicbotport": "8443",
        "privatekey": "",
        "certificate": "",
        "useselfsignedcertificate": false,
        "sslterminated": false,
        "verboselogging": false
    }
]

résultat : ok, message reçu sur le bon bot

je poursuis avec création d'un 2ème flux identique pour envoyer sur le 2ème bot

Et ça fonctionne bien !

Bon, désolé, il y avait des trucs incorrects, pas sûr d'avoir compris quoi, mais au moins j'ai 2 flux envoyant sur 2 bots différents....

reste à activer ça depuis HA.... encore une autre histoire ....

Ă  suivre...

Merci du soutien.

I do not read French(i guess) If you want help, my time i volunteer freely, as such i require you to help me help you.

As to your issue, here are 2 flows each has a separate config nodes. They do not share the same config.

[{"id":"b056a7065dce2313","type":"telegram sender","z":"c93d76e425518d9b","name":"","bot":"b1ba1d9ec569f73d","haserroroutput":false,"outputs":1,"x":490,"y":280,"wires":[["b6e0382922e8e2c0"]]},{"id":"e4352dfd80d583bb","type":"inject","z":"c93d76e425518d9b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"message\",\"chatId\":56xxxxxx20,\"content\":\"Hello envoi sur bot Alerte\"}","payloadType":"json","x":70,"y":200,"wires":[["27dbf17afad2e3b4"]]},{"id":"27dbf17afad2e3b4","type":"telegram sender","z":"c93d76e425518d9b","name":"","bot":"f9e88713e8567cb0","haserroroutput":false,"outputs":1,"x":490,"y":200,"wires":[["2b026e37f524e43d"]]},{"id":"2b026e37f524e43d","type":"debug","z":"c93d76e425518d9b","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":200,"wires":[]},{"id":"3015cf4085ad5dde","type":"inject","z":"c93d76e425518d9b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"message\",\"chatId\":56xxxxxx20,\"content\":\"Hello envoi sur bot  Gonthiers\"}","payloadType":"json","x":70,"y":280,"wires":[["b056a7065dce2313"]]},{"id":"b6e0382922e8e2c0","type":"debug","z":"c93d76e425518d9b","name":"debug 2575","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":280,"wires":[]},{"id":"b1ba1d9ec569f73d","type":"telegram bot","botname":" Gonthiers","usernames":"","chatids":"-1002033145747","baseapiurl":"","testenvironment":false,"updatemode":"polling","addressfamily":"","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"f9e88713e8567cb0","type":"telegram bot","botname":"Alerte","usernames":"Alerte47bot","chatids":"","baseapiurl":"","testenvironment":false,"updatemode":"polling","addressfamily":"","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

I understand you may have difficulty as there is a language barrier.

whao... no, sorry, i didn't noticed that i switched to french :flushed:

I just said that i deleted evrything from Nodered in my HA including data from Nodered, then réinstall all.
I recreated a 1st flow to send to one bot : ok
Then i created a second flow to send to the second bot and it worked also.
Both are now working separately very well !
So, i don't know what was wrong but at least it works now.

Now my next step is to understand how to send infos from Home Assistant with formatting text and chosing to which bot i will send.

If you have a good tuto to advise i will be happy...

And sorry as it was my mistake somewhere, but thanks for your help anyway.
Always better having someone giving some adices than searching all alone when you juyst start as a noob

Great you got it working.

I still suspect you where using one config, rather than two.

Mark this topic solved.

If you have further topics on HA and formatting, i would start separate topics. This makes it easier for future readers to find specific topics that may help them.

2 Likes

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