Telegram issues in 0.45

Hi,

I mostly use iOS notifications nowadays, but still had Telegram configured as a fallback, so I might not be up to speed with the latest changes.
I’ve seen that there were some additions to the telegram platform in the most recent releases, but I didn’t think they’d concern me.

My “legacy” config for telegram notifications looks like:

notify:
  - platform: telegram
    name: telegram
    api_key: '...'
    chat_id: ...

I just updated to 0.45 and the HA web interface notified me that there’s something wrong with my telegram config (which I didn’t touch for weeks).
Is this still supposed to work? I didn’t read anything about the notify Telegram component being deprecated.

Anyway, I disabled the notify component and set up the telegram_bot platform:

telegram_bot:
  platform: webhooks
  api_key: '...'
  allowed_chat_ids:
    - ...

This results in an error message at HA startup:

ERROR (MainThread) [homeassistant.components.telegram_bot] Error setting up platform webhooks
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/telegram_bot/__init__.py", line 194, in async_setup_platform
    platform.async_setup_platform(hass, p_config, discovery_info)
  File "/usr/src/app/homeassistant/components/telegram_bot/webhooks.py", line 46, in async_setup_platform
    result = yield from hass.async_add_job(bot.setWebhook, handler_url)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/telegram/bot.py", line 125, in decorator
    result = func(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/telegram/bot.py", line 1280, in setWebhook
    result = self._request.post(url, data, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/telegram/utils/request.py", line 207, in post
    **urlopen_kwargs)
  File "/usr/local/lib/python3.6/site-packages/telegram/utils/request.py", line 152, in _request_wrapper
    raise BadRequest(repr(message))
telegram.error.BadRequest: 'Bad Request: bad webhook: HTTPS url must be provided for webhook'

So, how is this supposed to work now?

Sebastian

Jepp, the same problem here

Same here. Working telegram-config stopped working with HA 0.45.0.

same issue here with me, was working fine before upgrading.

017-05-21 10:09:23 ERROR (MainThread) [homeassistant.setup] Error during setup of component telegram_bot
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 185, in _async_setup_component
result = yield from component.async_setup(hass, processed_config)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/telegram_bot/init.py”, line 176, in async_setup
conf = config[DOMAIN]
KeyError: ‘telegram_bot’
2017-05-21 10:09:23 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of notify.telegram. Setup failed for dependencies: telegram_bot
2017-05-21 10:09:23 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform notify.telegram: Could not setup all dependencies.
2017-05-21 10:09:24 ERROR (MainThread) [homeassistant.components.notify] Unknown notification service specified

Had the same issue (the docs weren’t clear about this breaking change) but got it to work again with:

notify:
  - platform: telegram
    name: telegram
    chat_id: xxxxx
telegram_bot:
  platform: webhooks
  api_key: xxxxx
  allowed_chat_ids:
    - xxxxx

chat_id and allowed_chat_ids are the the same in my case.

Ah, so both are necessary and telegram_bot only acts as a kind of backend?
I re-enabled my Telegram notify configuration and removed the api key from there.
I left the telegram_bot setup as it was.

When I restart HA, the UI warning about the faulty telegram notification config is gone.
But I still get the “HTTPS url must be provided” error for the _bot in the logs.
Also, notify.telegram is still not working anymore.

Sebastian

If your install is not exposed to the Internet, eg via letsencrypt, use the polling telegram_bot, instead of webhooks.

3 Likes

Ah, thanks! Changing to polling did the trick!

Sebastian

1 Like

Thanks change to polling and we are good :slight_smile:

1 Like

Thanks a lot!

1 Like

Anyone having problems with negative Chat IDs ?
I added my bot a while ago to a telegram group (i.e. multiple people in one chat - not the HA-groups :slight_smile: ). The ID starts with a “-”. It seems to me since the update only positive Chat IDs are allowed?

2017-05-22 07:52:29 ERROR (MainThread) [homeassistant.config] Invalid config for [telegram_bot]: value must be at least 0 @ data['telegram_bot']['allowed_chat_ids'][0]. Got '-123456789'. (See /home/homeassistant/.homeassistant/configuration.yaml, line 154). Please check the docs at https://home-assistant.io/components/telegram_bot/

Same error while setting up the specific notification:

2017-05-22 07:52:36 ERROR (MainThread) [homeassistant.config] Invalid config for [notify.telegram]: value must be at least 0 for dictionary value @ data['chat_id']. Got '-123456789'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/notify.telegram

I tried with quotes and without quotes. Nothing works.

Cheers.

Negative chat ids were fixed in:
https://github.com/home-assistant/home-assistant/pull/7689

This should go out with 0.45.1.

That saved me a lot of pain, thanks @martinhjelmare!

1 Like

Hello to everyone… I dont understand what chat_id is for? it’s possible to send message to different bots?

Thanks

Yes. It’s so you can send to different bots/chats.

You can add your bot to different chats. Lets say you have a chat just “you <–> bot” where you get system notifications. And another chat-group with you, the bot and all your family members whatsoever where other notifications are shared. Both chats have different IDs. So each notification ends in the right chat.

1 Like

When I try to send photo from url I receive this error:

May 23 09:28:58 hass hass[48125]: 2017-05-23 09:28:58 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
May 23 09:28:58 hass hass[48125]: AttributeError: ‘str’ object has no attribute ‘hass’

Sending through notification component and settion of telegram_bot : polling

Text message are ok, only photos have error

OK… but is ONE bot in different chats, no DIFFERENT bots… ok… thanks

I have the same issue. Upgraded from a working Telegram setup in 0.42. Messages work, but photos, which are a key part of my setup, stopped working with the same error message you describe.

hello guys i need help.
i have two mobile phones with diferent numbers.
my actually config is:

inside the notify.yaml

- name: telegramrodolfo
  platform: telegram
  api_key: secret
  chat_id: secret
  
- name: telegrampaula
  platform: telegram
  api_key: secret
 chat_id: secret

now it of this news version, how is the right configuration???
@martinhjelmare can u help.