Two telegram bots, one chat for notifications

I’m trying to configure home assistant so it can use two bots randomly on a chat for notifications.

So far, I’ve managed to configure it to use one bot, so I’m not starting from zero :slight_smile:

The idea is to first set up two bots that can be called independently.
Then, I need to ransomise the bot call from the automation.

For the first part, I’ve tried to configure a secondary bot with a secondary api key

telegram_bot:
  - platform: polling
    api_key: api_01
    allowed_chat_ids:
      - 'chat_id_1'
  - platform: polling
    api_key: api_02
    allowed_chat_ids:
      - 'chat_id_1'

And for the notify part, on a notify.yaml file:

- platform: telegram
  name: telegram_bot_1
  chat_id: 'chat_id_1'
- platform: telegram
  name: telegram_bot_2
  chat_id: 'chat_id_1'

Note how:

  • Theres a unique chat_id
  • There are two different bots with differentt api_keys

But if I call notify.telegram_bot_1, telegram_bot_2 is the one that sends the message.

I really can’t figure out the part for two bots and how to randomise the usage of either one of them.

Can anyone help me?

1 Like

This is how I set up two separate chat groups:

telegram_bot:
  - platform: webhooks
    api_key: !secret telegram_api_key
    allowed_chat_ids:
      - !secret telegram_general_chat_group_id
      - !secret telegram_system_chat_group_id
      - !secret telegram_tom_id
    trusted_networks:
      - 149.154.160.0/20
      - 91.108.4.0/22

Notification services:

- platform: telegram
  name: telegram_general
  chat_id: !secret telegram_general_chat_group_id

- platform: telegram
  name: telegram_system
  chat_id: !secret telegram_system_chat_group_id

Yeah, that’s how you set up two different chats, but how to set up two different bots?
Thanks for the reply!

Ok, so I guess there’s no way of having two different bots to post stuff on a same chat :frowning:

Hi, I’m trying to figure out the same thing: How to use two telegram bots. I experience the same thing as OP; only the last defined bot will be used. I assume that the “telegram_bot” service doesn’t support two bots.

It is, however, a much wanted feature. I’d like one bot for alerts to go to the whole family (eg. fire alarm). The other bot is used for less urgent stuff, like doorbell, etc.

Regarding groups: I don’t quite understand how this is used. Is there a tutorial on that? Can I achieve separate alert and info with groups?

You can do that with the one bot sending to two (or more) different chat groups. See my example above. The system notification goes to me only for urgent system related issues like available updates or errors, the general chat group is used by me and others to receive functional alerts like the washing machine finishing, smoke or house alarm etc…

It is a long time since I set this up, so don’t remember the specifics but I think it was as simple as creating a chat group in telegram, inviting the bot, and setting up the notification services as above.

1 Like

Ok, thank you, it works now. Basically, I use the config as given by you above (but I have “platform: polling” instead of “platform: webhooks”, not sure if that means anything).

To get the group and/or channel ids, I created group/channel (using Telegram app), and then invited my bot and also the “IDBot” from Telegram, and issued “/getgroupid@myidbot”, got the id, kicked out the bot, invited the family members. Then I used the ID in the config. Works!

1 Like

Hi… then is no way, to have different bots for different notifcations? only we can use groups?
Thanks