Hi to you all!
Just want to share a simple HowTo to setup a Telegram bot for all your messages from, and to your home automation services.
For example, I use three separate Telegram-bots:
- Logging-bot for, ehh, logging. No sounds or pop-ups when messages arrive on my phone/tablet/desktop.
- Status-bot for state-changes like Home, Away, Armed and so on. Just a ‘beep’ when messages are received.
- Alarm-bot for alarm and emergency messages, including pictures from cameras in breached zones. With a lot of noise!
How to setup a Telegram-bot:
- Install Telegram Messenger on your mobile device (also available on any computer/laptop/webbrowser when configuration is completed on your mobile!!).
- Search for the BotFather-bot in your Telegram Messenger app.
- Create a new bot by sending the command
/newbotto the BotFather. Fill in the necessary information and write down/copy the
Authentication Token <— important! Keep it safe and secret!!
- Go to your newly created bot and send a message to the bot. Doesn’t matter what the message contains.
- Get your User ID by sending a URL in a webbrowser:
https://api.telegram.org/bot<token>/getUpdates(without the brackets)
Where is the Authentication Token obtained in step 3. Check the JSON output and look for the value behind
"id":and write down the value. This is your User ID.
EDIT 20190702: If this does not work, please try this solution to obtain your User ID.
- Check if everything went right by sending this URL in your webbrowser:
If everything went right your Telegram-bot send you a message with text testing
Be Aware!! Don’t share your Authentication Token with anyone or post it somewhere on the forum/internet. Keep it secret at all times!!
You can send messages from, and to, the bot using the Telegram API.
Using your bot in Node-Red:
In short, you can use Node-Red nodes to send messages, photo’s, build menu structures and even construct conversations with your bot. The best way to do this is to add special nodes to your Node-Red palette called node-red-contrib-chatbot
Check this page for more info and examples!
You have to configure the Telegram-Sender node with your Telegram-bot configuration details:
Be sure to add your User-ID to the users box, otherwise it will be visible for everyone visiting your bot!! You can also add multiple User-ID’s for all your family/relatives/friends who you want to share the messages with.
It is advised to configure a log file. That way you can always see if you had (foreign) visitors and check this file for debugging/logging.
FYI, the node-red-contrib-chatbot can also be used for Facebook, Slack, Viber and Smooch.
I hope I got you started. It’s to your imagination how you are gonna use it, the possibilities are endless.
PS. Don’t use < or > characters in messages you send to the bot, it will result in a error message in return by Telegram.