On 24 June, 2015, Telegram published the Bot API, enabling machines to talk Telegram. From that day on, not only can human use Telegram, so can machines.
For those who don't know what Telegram is, it is a messaging app, very much like WhatsApp. This tutorial is going to teach how to send a Telegram message to your Raspberry Pi, and how to make your Pi telegram back.
Step 1: Install Telegram on your phone, obviously
Go to App Store (iPhone) or Play Store (Android), download and install Telegram on your phone.
Now, you can use Telegram. Not yet for the Raspberry Pi. Telegram reserves a special kind of accounts for machines, called bot accounts. As the owner of your own Pi, you have to obtain a bot account for it.
Step 2: Text /newbot to BotFather
Open Telegram on your phone, search for a user called BotFather. As the name implies, he is the Father of All Bots.
As you may have guessed, he is not of our own species, but is actually a machine. He accepts special commands, because he does not understand plain English very well.
To obtain a bot account, text him /newbot. (you need the slash ‘/' in front) He will then ask a couple of questions. In the screenshot above, I call my bot “Dicey Clock”. You will see why in a few moments. But you can give it any name you want.
At the end of process, you will be given a token, something like 123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ. This token represents the bot account. You are going to put this token on the Pi.
Here, we have a problem. How are you going to copy this lonnnnnnng token from the phone to the Pi? By hand?
Step 3: Use Telegram's Web Version
Aside from being a smartphone app, Telegram may also be used on a web browser.
On your PC, open a browser, go to Telegram's Web Version. It will ask for your phone number, then send you an SMS message containing a code. Enter the code, and you will be led to an interface very similar to your Telegram app.
Find the conversations with BotFather. You should see the token right there. Now, you can easily copy-&-paste the token from the browser window to the Pi, whenever you want, as often as you want.
For more detail: Set up Telegram Bot on Raspberry Pi