This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
Add a way to cummunicate with a Telegram Bot
Vonkenboer
Member
Hi,
On my Fibaro system I use a several Telegram Bots to receive logs and alerts. It's easy to setup and easy to use!
(see http://forum.fibaro.com/index.php?/topic/20581-sending-messages-from-your-hc2-to-your-telegram-account/ for more information)
To bad I don't have the programming skills to make one by my self, but I love to see this implemented!
If you have any questions regarding setting up a Telegram Bot, just ask.
Have a nice weekend!
On my Fibaro system I use a several Telegram Bots to receive logs and alerts. It's easy to setup and easy to use!
(see http://forum.fibaro.com/index.php?/topic/20581-sending-messages-from-your-hc2-to-your-telegram-account/ for more information)
To bad I don't have the programming skills to make one by my self, but I love to see this implemented!
If you have any questions regarding setting up a Telegram Bot, just ask.
Have a nice weekend!
Comments
https://github.com/yagop/node-telegram-bot-api
Would be nice to have!
However, the creation of a bot on the website of Telegram failed when I tried... no matter what I did. So at that moment I abandoned my ideas
I would love to test it
A bot is a whole different case. Haven't looked into that extensively yet, but I think there are a lot of possibilities.
What kind of stuff would you like to do with the Telegram bot? I myself was thinking of using commands, that can be linked to triggers.
For example, you send the Telegram bot:
/trigger test123 321test
And then in Homey you can have a Telegram trigger on 'test123' with a token 'data1' that contains 321test.
But I'd love to hear your own ideas!
1 - In your Telegram messenger app or desktop software search for BotFather.
2 - Select Botfather for give it instructions. These instructions are summarized with the /-button
3 - Create a new bot with /newbot. It will ask for a name and a username (must end with .....bot).
4 - When created a <token> is given to you. Save this somewhere.
5 - Set your privacy settings with /setprivacy (is default on enabled, which is ok, but just to be sure....)
6 - Search for new bot with the username.
7 - Select begin or type /start
8 - Send the bot a message (this is crucial!)
9 - In a webbrowser get your user ID by sending: https://api.telegram.org/bot<token>/getUpdates
10 - Get your user-ID from json output of the message you send to the bot.
11 - Test it in your browser by sending a example in your browser:
That's all you need! To communicate with the bot you need the token and to get messages, only for you, you need your user-ID (also called chat-ID)
If you want to /deletebot or change the settings, this done by the BotFather. When you don't know your token you can /revoke it and get a /newtoken
Hope this will help.
Now just need some ideas of use cases.
It would be nice to have the ability to send text to different bots to begin with. Secondly pictures or video's (from ip-cams) and the ability to send instruction to the Homey (Telegrambots can use webhooks).
For more info: https://core.telegram.org/bots/api
Thanks for looking into this. I hope I got you interested...
- The app on Homey sets up a unique identification key.
- You need to add the bot and send a message (for example, /register uniquekey12345) to the bot to register your Homey to it.
- After that, you can send any message to the bot in the same chat to get the message in Homey.
- I'm working on the possibility to send a message to the Telegram chat from inside Homey, after registering Homey to the bot.
Any requests?
BTW, what do you mean "The app on Homey sets up a unique identification key"? Do you mean the bot-token can be inserted?
But I needed to find a way to connect a user ID on telegram to a Homey. So by setting up a unique ID on Homey, and then 'registering' that ID on the chat, that is possible. Homey will remember which user it should listen to on the chat
The source code will be open so it can be used easily to create a new app if you would prefer it working differently.
Please keep in mind privacy and security as fundamental. Just my opinion.
The reason I mentioned privacy and security is to minimize the consequences when something goes wrong or when breached.
Can you explain why you need a webhook? Is this used for receiving instructions from the Telegram-bot to the Homey?
For example:
If I need to know which messages were received, I would need to 'poll' Telegram: https://api.telegram.org/bot<token>/getUpdates
I could do that every x seconds from Homey, for example every 10 seconds.
However, then I have to do 'something' from every Homey that has the app installed, 6 times a minute, 360 times an hour, 8640 times a day... while probably you will only need it about 0 - 10 times a day when a message is sent.
Besides that, it will take up to 10 seconds to get the message to the Homey.
By using a webhook, it is far more optimised:
When Telegram receives a message sent to the bot, it will hook into the webhook of Athom which will then send it to the right Homey.
Before one second has passed, I can send back an answer. I just tested that, a ping-pong mechanism is already in place (Send 'ping' to the bot, will be received by Homey, Homey sends back 'pong' which will be received in the Telegram chat).
I am making it dynamic now, so you can enter your own bot token which has preference over the 'general' bot token. Will write up some instructions on the settings page.
Next thing is that I need to make sure that you can 'unregister' from the bot from the settings page, I'm already half way there. But it will be a lot of testing still.
I expect to be able to submit it to the app store by the end of the week!
It's fun looking over your shoulder to watch things evolve though..
I think I got it working, so tomorrow I will do another test with adding and deleting a custom bot, and if that works it will be submitted to the app store for approval.
Already registered my own bot.
Just to be a pain in the ass Can your app be used for more then one bot?
Noob question: Isn't it possible to install apps in Homey twice?