[Question] telegram bot (telegram_bot.send_photo) does not work as expected

Hi,

I have configured the telegram bot in Home Assistant.
In my automations the “notify.telegram” works as expected and it sends messages to a group.

The “telegram_bot.send_photo” sends a message (picture) to the bot itself and notifies me on the telegram app. How do I send the picture to the group?

My configurations:

# configuration.yaml
# Telegram bot
telegram_bot:
  - platform: polling
    api_key: my api key
    allowed_chat_ids:
      -group id number

notify:
  - platform: telegram
    name: telegram
    chat_id: -group id number

This works and sends a message to the defined group

# automations.yaml

- service: notify.telegram
    data:
      title: ALARM!
      message: "some text"

this one does not work as expected and sends a picture to the telegram bot and it shows only for me not in the telegram group

# automations.yaml
- service: telegram_bot.send_photo
    data:
      url: some url

Any advice would be appreciated. Thank you

As per the ‘telegram_bot.send_photo’ documents found here:

target: An array of pre-authorized chat_ids or user_ids to send the notification to. Defaults to the first allowed chat_id.

So you need something like this for it not to default to the fist id:

- service: telegram_bot.send_photo
  data:
    url: some url
    target:
      - 123456789
      - 987654321
1 Like

Thank you. This works.

1 Like

Guys, I’m having a similiar problem to the poster above, I’ve been messing about with different configs but I just cannot get this to work
I’ve been using Telegram just fine all along, but I was only messaging the bot (myself) of any notifications.
Now I have a need to message a group on Telegram, and despite putting in the -groupid and configuring it all the same, I cannot get the message to go to the group. Even when I remove the individual bot id and just leave the group id in, it STILL messages the bot alone. It is definitely something to do with my HA config, since I can message the group from the web api… I’ve attacched my code below, even with those bits commented out, it still sends to the bot only. Tearing my hair out here! ANy ideas anyone?

telegram_bot:
  - platform: polling
    api_key: apikey-here
    allowed_chat_ids:
#           - chatidXXX
       - --chatidYYY
#    notify:
#  - name: notify_telegram
#    platform: telegram
#    chat_id: chatidXXX
#  - name: notify_dadsgroup
#    platform: telegram
#    chat_id: -chatidYYY
    
notify: 
#       - name: notify_telegram
#         platform: telegram 
#         chat_id: chatidXXX
   - name: notify_dadsgroup
     platform: telegram 
     chat_id: -chatidYYY

Hi @McSpud99,

I am not at home at the moment. Ill check later my config and let you know.

I remember I had to add my bot also to the telegram group. This is not a HA config. Its in the telegram group itself.

Hi yf, yeah I’ve done that too, and promoted the bot to admin and all that… I’m stumped by it, I think the telegram end is configured okay, since I can message the group via the web api at this link:

https://api.telegram.org/bot_telegram_api_in_here/sendmessage?chat_id=-chatid_for_group&text=test_message_to_group

This string works fine when invoked in a browser, which kinda says to me that the telegram bit is ok, but HA is not using it no matter what I stick in the yaml… its very frustrating, maybe it would help if I knew how to code!! LOL

@McSpud99

My configuration that works:

configurations.yaml

telegram_bot:
  - platform: polling
    api_key: !secret telegrambotapikey
    allowed_chat_ids:
      - -79xxxxxxx

notify:
  - platform: telegram
    name: telegram
    chat_id: -79xxxxxxx

automations.yaml

- service: notify.telegram
    data:
      title: Briefkasten!
      message: Post ist da :)
      target: -79xxxxxxx

I am using the same Telegram chat id’s (the group id) in all three configs/examples.

not sure if this was just a copy paste issue. but you have one “-” to much. It should be 2 and not 3.

      - -79xxxxxxx

And maybe try to use the order that works in my config. No idea if it is important. Just seen that you are using a diffrent order.

1 Like

Thank you so much yf_ha, the problem was in how I was invoking the message data in the automation, it was your code snippet from your automation gave me the clue. Thank you very much my friend!
It seems the ‘Target’ information is where you specify the intended recipient(s)… its working fantastic for me now!!! :slight_smile:

1 Like