Universal Notifications Using Telegram and cURL

March 7, 2018
shell notification jenkins travis

If you ever wanted to get notified when certain things happen but didn’t find a lightweight solution – here comes captain Telegram.

Using a simple Telegram bot, it’s possible to send notifications to your mobile phone or browser. All the notifier node needs is curl installed.

Registering a bot

First of all, a Telegram bot has to be registered in order to send messages later on. Follow these steps to get started:

Sending messages

Now, you should have to following things: - Bot API token - Chat ID of the chat between you and your newly created bot.

To send a message, it’s as simple as using the following command structure

curl -i -X GET "https://api.telegram.org/bot<BOT_TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=hello"

Example 1: Jenkins build notifications

In order to get notified in case a Jenkins build succeeds or fails, you can edit the Jenkinsfile as follows

try {
   // Build steps
catch(error) {
   // Send Telegram message: Fail
   error "Exception occurred, aborting"
// Send Telegram message: Success

Example 2: Travis notifications

If you use Travis CI to build your projects after pushing to GitHub, notifications can be implemented by editing the .travis.yml file:

  - curl -iX GET "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=$CHATID&text=Build OK" 2>&1 >/dev/null

  - curl -iX GET "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=$CHATID&text=Build failed" 2>&1 >/dev/null

Two things are important here:

  1. Redirect the output to /dev/null in order to prevent the chat ID from being logged into the public build log.
  2. Add your secrets ($TOKEN and $CHATID) to the repository specific settings in Travis to populate the used environment variables in a secure manner.

Methods to Upgrade nc Reverse Shells

May 16, 2018
pentesting shell

Random Note #12354123: Easy Remote Pair Programming Using Docker and Tmux

April 10, 2018
randomnote docker vim tmux shell programming

Using Shellcheck and Docker to Automatically Lint Dotfiles

March 8, 2018
shell dotfiles docker travis