Sending Telegram messages via bots!

Telegram is a messaging platform similar to Whatsapp, but you can create bots and use an API to send messages from devices to yourself.

I have been experimenting with using Telegram bots to send notifications and alerts instead of emails.

I thought I'd try it out on the Onion and see what happens! You can also send commands through the bot too although I havnt ventured down that path ie. send a "/lighton" command and the omega switches a specific GPIO pin to 1 to turn a light on.

You should be able to follow the sequence below to get started:

Browse to https://telegram.org and create an account OR download the app on your iDevice or similar and create an account that way. If you have created an account on your device you can login to a web session on the telegram website to send messages via your browser also.

You must get your unique CHATID for your user. Send /getid to @IDBot, it needs to be this specific command to get the answer. This will give you your CHATID which we will use later.

Next create a bot! Send /helpto @BotFather, next to create a bot send /newbot. The BotFather will then ask a couple of questions, first a Name that is just a label and then the username for the bot which must end in Bot. He will send you the API token which again you must keep, although you can ask him to generate another by using the /token message. You should notice there are a load of commands you can ask of the BotFather, I mainly use the /setuserpic which you can use to change the bots avatar!

Next is to install curl which is used to create the HTTP requests, in this case a POST.

opkg update
opkg upgrade
opkg install curl

Once curl is installed we can start sending messages! Copy pasta the following to setup the script file:

cd /root
touch telegram.sh
chmod 775 telegram.sh

Open the file using your favourite text editor (I enjoy VI as it is on version of linux!) Copy the below text to create a script file that is used to send a message:

Once the script is setup and you have modified it to have your CHATID and bot API token then use it!

echo "Test: Onion Omega FTW!!" | ./telegram.sh

You should get back a return of a valid message from the console and on whatever platform you have Telgram installed on!

One problem I have found is the pipe validation. Within bash it echos a response if nothing is piped. The same bit of code doesnt seem to work for busybox. If anyone has got a better way of doing it let me know!

Hopefully this will get some people thinking of some better ways of notifying people of events!

Hopefully @Boken-Lin will get it added to the Wiki if it is worthy! :+1:

I have a bot with 70K subscribers on Telegram! Why am I not able to broadcast a message to all of them on time?! I mean if I go ahead and broadcast a simple message, God knows when it will be delivered to all! Can anybody guide me on this issue? what should I do about it? Do I need a more powerful server or its not related to my server's configurations directly?! Thanks