Unfortunately, this doesn’t work upon receiving the messages (in fact, I cannot even see the event). Sending the messages does work on the other hand (via a service or by triggering the automation).
How come I can send messages but I cannot receive them?
I’ve given up on Nabu Casa since I cannot do port forwarding. I am now trying to do the same with DuckDNS but I also cannot get it working. The reaction is the same. I can send messages, but not receive. I’ve tried multiple things:
Monitored the event stream by watching for telegram_message and telegram_text, but nothing happens when I send a text to the bot.
Monitored the full event stream with node-red debugging, but nothing happens when I send a text to the bot.
I checked the open ports and the one I specify for Telegram (8443) is open (from the internet). This means the port forwarding works correctly and something is happening on this port.
I have no active Telegram related errors. The platform is set up correctly.
Besides, I’m using duckdns for accessing my Home assistant instance and that is working correctly, so it also isn’t the connection.
Hmm, I’ve been trying the webhooks way since it was recommended as ‘the preferred way’. Switched to polling and now it works indeed without url (tried it also without url with webhooks, but without any effect).
Have anybody godt webhooks for Telegram working when using Nabu Casa? I currently use polling which works fine, but I sometimes get repeated messages, which might be due to polling. In the docs webooks need a base_url, but is that just the remote URL for nabu casa?
I am also waiting to see this working so I can use Telegram app to communicate to HA.
By the polling mode makes in thousands of request to telegram server and PiHole lists HA top client in the list
I have Telegram working using webhooks via Nabu Casa. I also switched from polling to avoid all those requests (and I think webhooks is a bit quicker as well).
There is no need to configure an url in the Telegram config when you have defined the external url in the basic information setup.
You have to add 127.0.0.1 to trusted_networks as otherwise the messages aren’t received by the bot.
thanks. this has solved my problems. also please check ip_bans.yaml and make sure 127.0.0.1 is not listed inside there. It was listed in mine and I have wasted many hours trying to figure out what went wrong.
Oke, I’ve been at this for a few days now… and finally managed to get it working with webhooks. I have HomeAssistant running on a Raspberry Pi, not directly exposed to the internet.
I have a Synology NAS running a Reverse Proxy, thus handeling the ssl certificates.
I’ve forwarded port 8443 from my router to my nas. Note that in the NAS, I have hooked up external port 8443 to internal port 8123. Also note that https is forwarded as http traffic, this is because there is no valid ssl certificate between the NAS and the Pi.
My http config looks like this:
http:
use_x_forwarded_for: true # Required for reverse proxy to work
trusted_proxies: 192.168.1.2 # IP of the synology
My Telegram config looks like this:
telegram_bot:
- platform: webhooks
api_key: !secret telegram_api_key
allowed_chat_ids: !secret telegram_allowed_chat_ids
trusted_networks:
- 149.154.160.0/20
- 91.108.4.0/22
- 127.0.0.1 # Not sure if this is actually required
- 192.168.1.2 # The nas
url: !secret telegram_url # https://example.org:8443
The AHA! moment was when I realised that Home Assistant was blocking traffic on 8443 because it is not configured as the server port, that’s when I routed external traffic on 8443 to 8123 on the pi.