Is it possible to get multiple telegram bots?

I actually solved my idea in a different way than having 2 bots.
I have 1 bot but two telegram groups.
1 group for generic notifications and the other for urgent notifications.
I added the chat id’s of those 2 groups to the allowed chat ids:

telegram_bot:
  - platform: broadcast
    api_key: !secret telegram_api
    allowed_chat_ids:
      - !secret telegram_chatid
      - !secret telegram_chatid2

Then under notify I created 2 items called Bot and BotUrgent with those same chatid’s:

notify:
  - name: TelegramBot 
    platform: telegram
    chat_id: !secret telegram_chatid
  - name: TelegramBotUrgent   
    platform: telegram
    chat_id: !secret telegram_chatid2

So now in an automation I can send it to either of the 2.
If you also add (both under telegram_bot as under notify) for instance the chatid of your own telegram account (so not the groups but your private one), you can also send notifications only to yourself instead of the groups. I did that because my wife is in the groups but some notifications really only need to go to myself.

10 Likes

Having groups you will see messages arriving from different “users” in telegram android/iphone app correct?
Will investigate how to do these different groups, and use also @clyra idea of mqtt, I like way more of doing changes without having all the time to restart HASS

Also interested how many groups you guys use, and for each group which type of messages /notifications you use (for inspiration)

I’ve tried to get this working but I keep hitting an error and well… it doesn’t work… Any ideas please?

ERROR (SyncWorker_19) [homeassistant.components.telegram_bot] Error sending message: Chat not found. Args: (xxxxx, 'Home Assistant restarted'),
1 Like

answer my own question… group IDs are a negative… so use -123456678 etc

I had the same problem. I want a “standard bot” for info and a small chat app I created (turn lights on/off, set cover position, get gas prices…), but I wanted another bot for urgent alarm messages (water leakage…). It didn’t work with groups for me, because I want my fitness tracker (Mi Band) to vibrate aggressively in an urgent case, and I didn’t manage to set up “Tools & Mi Band” (an app) to distinguish between the groups, as both messages come from the same contact/bot.

That’s why I extended my appdaemon app, that I wrote a long time ago when I had an unstable internet connection (that’s why all the ping and check stuff is in the app. I could remove that one day…).
It listenes for an event called “custom_notify”. Any automation (or appdaemon app) can send it. If you provide a target that is defined in configuration.yaml, it will send the message to that target. If traget == “special_bot”, you have to provide the token of that bot (I accidently called it api_key) and the chat_id it should be sent to.
By that, I can send a message via every bot I want, and I do not disturb the “standard bot” configuration of home assistant.

Maybe this helps if someone has a similar issue…

3 Likes

You are just a GENIUS! Thank you so much!
I do not understand why this is not a very popular topic.
I think this is a very important issue.
You need a channel for regular notifications, for history, and you need a separate channel for the most important notifications. Type of alarm.
Just awesome! Thanks again!

1 Like

Did anyone solve this without any extra config like appdaemon, etc?

Well this still works fine for me (and it’s without appdeamon): Is it possible to get multiple telegram bots?

Yeah, but with the groups, and I’d rather like to avoid that. But thanks, I guess that will be the fallback :confused:

What are you after? I don’t think I understand.

Using two bots, to send directly to my telegram user. But I cant select which bot to send from.

1 Like

Same problem. I want to avoid seeing the “message arrived” warnings in HASS when using two different groups with a single bot.

The only way I have found to do this is through node-red, which works great.

This does not work for me, I get yaml configuration error. There apparently can be only one entry per platform in notify:

I’m on version core-2021.1.5 and this still works:

notify:
  - name: telegrambot 
    platform: telegram
    chat_id: !secret telegram_chatid1
  - name: telegramboturgent
    platform: telegram
    chat_id: !secret telegram_chatid2
  - name: telegramlwerk
    platform: telegram
    chat_id: !secret telegram_chatid3

On which version are you where this is not working (anymore)?

Same problem here. Any solution yet on how to use multiple telegram bots to send messages?

EDIT: I made the according feature request here:

1 Like

Why do you need to bots?

I participate in several Telegram groups, and I want each group to have its own bot.

Yes, I can have a single bot talking to different channels/groups, that’s what I do now, but I still think having separate bots is more elegant and better maintainable.

1 Like

Indeed. And as @lugia already mentioned in the feature request, it’s just better readable and maintainable if you have the possibility to work with multiple Telegram bots as you can give them different names.