How to make Telegram notifications work?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
tgg3
Posts: 9
Joined: Monday 14 May 2018 9:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

How to make Telegram notifications work?

Post by tgg3 »

I'm trying to get Telegram notifications working. However, I see the following in the log when I click the "Test" button next to to the Telegram notification settings:
---------------
2018-05-17 16:02:43.737 Error: Telegram: {"ok":false,"error_code":404,"description":"Not Found"}
2018-05-17 16:02:43.737 Notification sent (telegram) => Failed
2018-05-17 16:02:43.753 Active notification Subsystems: telegram (1/14)
---------------

I got the API Key and the Chat ID (from the @get_id_bot on Telegram) and pasted those strings into the notification settings Telegram. I get the feeling I need to do something else.

Thanks much for your help.
Tom
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: How to make Telegram notifications work?

Post by simonrg »

The error looks like it isn't Domoticz, but somehow in the communication to / from Telegram.

Try this is browser -

Code: Select all

http://api.telegram.org/botAPInumeric:APIalphanumeric/sendMessage?chat_id=CHATID&text=Hello
Replace APInumeric:APIalphanumeric with your API key and CHATID with your chat ID.

Response should be:

Code: Select all

{"ok":true,"result":{"message_id":xxxxxx,"from":{"id":xxxxxxx,"is_bot":true,"first_name":"Bot Name","username":"botname"},"chat":{"id":xxxxxxx,"first_name":"firstname","last_name":"surname","username":"userid","type":"private"},"date":1526568064,"text":"Hello"}}
Are you able to get this to work?
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
tgg3
Posts: 9
Joined: Monday 14 May 2018 9:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: How to make Telegram notifications work?

Post by tgg3 »

I found my problems. Your HTTP test code was very useful. I hadn't created the bot and then added a chat for that bot to my Telegram app (which isn't mentioned in https://www.domoticz.com/wiki/Telegram_notification). The api key I was using didn't go with the bot I ended up creating.

Sorry for the NOOB mistake. There are so many new concepts for someone new to the world of DIY IoT (sensors, controllers, new hardware, new software languages, messaging APIs, etc.). I really appreciate the help from everyone in the support forums.
Tom
WarLion
Posts: 15
Joined: Thursday 08 December 2016 6:38
Target OS: Linux
Domoticz version:
Contact:

Re: How to make Telegram notifications work?

Post by WarLion »

i had a problem like this if i use the URL
https://api.telegram.org/bot*****:***** ... &text=test
work prefect

but when i use my token and chat_id on domoticz notificacion (latest beta) i get
2019-02-20 17:05:30.535 Error: Telegram: {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}


also using it on custom HTTP/action works without a problem
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to make Telegram notifications work?

Post by jvdz »

Did you fill in the token without the "bot" prefix?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
WarLion
Posts: 15
Joined: Thursday 08 December 2016 6:38
Target OS: Linux
Domoticz version:
Contact:

Re: How to make Telegram notifications work?

Post by WarLion »

i did just the token , , i decide to try again and now is working didnt change anything , not sure why yesterday didnt work, thanks guys
Marque1968
Posts: 60
Joined: Tuesday 03 April 2018 18:41
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: How to make Telegram notifications work?

Post by Marque1968 »

tgg3 wrote: Friday 18 May 2018 6:51 I found my problems. Your HTTP test code was very useful. I hadn't created the bot and then added a chat for that bot to my Telegram app (which isn't mentioned in https://www.domoticz.com/wiki/Telegram_notification). The api key I was using didn't go with the bot I ended up creating.

Sorry for the NOOB mistake. There are so many new concepts for someone new to the world of DIY IoT (sensors, controllers, new hardware, new software languages, messaging APIs, etc.). I really appreciate the help from everyone in the support forums.
So how did you add the chat to your telegram app. Also a noob on this end, who installed Telegram soley for this purpose...
Marque1968
Posts: 60
Joined: Tuesday 03 April 2018 18:41
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: How to make Telegram notifications work?

Post by Marque1968 »

Ok, for the noobs that didn't get it either:
- In Telegram select Menu
- Select contacts
- Press the add-button
- enter @ + the name you have entered upon creating the key.

Only now you will recieve the bot messages.
pretendor
Posts: 9
Joined: Thursday 21 March 2019 21:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to make Telegram notifications work?

Post by pretendor »

Guy's i have all things done.
the api HTTP access link will sent me a notification.
so the token and the chatid er fine.
still got the same error message in domoticz.
2019-04-12 20:32:42.237 Notification sent (telegram) => Failed
2019-04-12 20:32:42.244 Active notification Subsystems: email, pushbullet, telegram (3/13)
2019-04-12 20:32:42.237 Error: Telegram: {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}


any idea how to fix?
if i use the link:
http://api.telegram.org/bot*******:**** ... text=Hello
on privacy reasons changed the values to ***.

i got the replay that everything is ok and get a new message in telegram (on the bot channel i created) so the bot is working fine and the apitoken and chat_id also......... need help cuz this time i'm gonna crazy!
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to make Telegram notifications work?

Post by jvdz »

You need the Chat_id, not a channel_id for this to work.
try sending it to your telephone's chat_id.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
pretendor
Posts: 9
Joined: Thursday 21 March 2019 21:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to make Telegram notifications work?

Post by pretendor »

jvdz wrote: Friday 12 April 2019 21:57 You need the Chat_id, not a channel_id for this to work.
try sending it to your telephone's chat_id.

Jos
Jos i had used the chat id that i requested by the @get_id bot
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to make Telegram notifications work?

Post by gschmidt »

jvdz wrote: Friday 12 April 2019 21:57 You need the Chat_id, not a channel_id for this to work.
try sending it to your telephone's chat_id.

Jos
Hey Jos,

I have telegram notification working when using my telephones chat_id, but is it also possible to push domoticz notifications to my 2 other family members?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to make Telegram notifications work?

Post by jvdz »

You could setup either a group or a channel in Telegram when you want to address multiple people with the buildin Telegram notification.
I use for my own notifications a lua script that sends the Telegram Bot notifications, where I can select to whom it needs to be send to and control the number of people easily.

Jos

Edit: Something like this LUA function will submit 1 or 2 notifications depending on the name you provide in the function call:

Code: Select all

function TelegramMsg(sendto, message)
	token = "123456789:xxxxxxxxxxxxxxxxxxxxxxxxxx"
	ID1 = 1111111
	ID2 = 2222222
	NAME1 = "name1"
	NAME2 = "name2"
	ALL = "both"
	-- Define sending text without notification
	if (sendto == ALL or sendto == NAME1 or sendto == ID1) then
		os.execute('curl --data chat_id='..ID1..' --data-urlencode "text='..message..'" '..' "https://api.telegram.org/bot'..token..'/sendMessage" &')
	end
	if (sendto == ALL or sendto == NAME2 or sendto == ID2) then
		os.execute('curl --data chat_id='..ID2..' --data-urlencode "text='..message..'" '..' "https://api.telegram.org/bot'..token..'/sendMessage" &')
	end
end

Code: Select all

TelegramMsg("name1", "Send Telegram notification to person 1")
TelegramMsg("name2", "Send Telegram notification to person 2")
TelegramMsg("both", "Send Telegram notification to both persons")
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to make Telegram notifications work?

Post by riko »

jvdz wrote: Friday 10 April 2020 18:42 You could setup either a group or a channel in Telegram when you want to address multiple people with the buildin Telegram notification.
I use for my own notifications a lua script that sends the Telegram Bot notifications, where I can select to whom it needs to be send to and control the number of people easily.

Jos

Edit: Something like this LUA function will submit 1 or 2 notifications depending on the name you provide in the function call:

Code: Select all

TelegramMsg("name1", "Send Telegram notification to person 1")
TelegramMsg("name2", "Send Telegram notification to person 2")
TelegramMsg("both", "Send Telegram notification to both persons")
Nice solution which I would like to use. I'm only thinking how to handle the notifications which I've configured today on switches in the Domoticz interface (by clicking the 'notifications' button). Is there a way how I can use this script in an easy way on these switches? Instead of writing separate scripts for it.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to make Telegram notifications work?

Post by jvdz »

The group/channel solution will obviously also work with the standard build-in notification mechanism.
I am not sure whether a DzEvents script can be triggered on an Notification, but don't think regular LUA events can do that, so I have all my event notifications programmed in my scripts.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
rfvdboom
Posts: 38
Joined: Tuesday 20 September 2016 8:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: How to make Telegram notifications work?

Post by rfvdboom »

At first my telegram notification wasnt working in Domoticz after using the turorial in the Wiki. Got Error in de log. After some testing i found out that my ad-blocker was blocking the API request from Telegram. So make sure you whitelist the API request from telegram in your Adblocker. :!:
Odroid N2+ | Raspberry P 3 ModelB | RFXcom | AEOTEC Zwave | Honeywell Lyric T6| Milight | Milighthub (NodeMCU) | SolarEdge | P1 Smart meter USB | KAKU | Wemos D1 (esphome) | Denon | Logitech Harmony
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests