How to send Telegram notifications after Travis-CI builds

Dan Okhlopkov
2 min readMay 16, 2019

--

In this article, I’ll show the simplest way to send Travis-CI notifications into Telegram chat, channel or private message.

In Morejust we like to build free and open source tools. We are huge fans of GitHub Pages and its ability to serve static websites. We use Travis CI to build our frontend into gh-pages branch. And we use Telegram for our internal communications. That’s why we really want to send notifications when our frontends successfully deployed and delivered by Travis.

Set up the environment variables

To build a static website and serve it with GitHub Pages you will need to specify the GitHub token — this will allow Travis Ci to push built files into your repo’s gh-pages branch. The token can be obtained with this instruction.

Moreover, you’ll need to specify Telegram token and Chat Id if you want Travis to send telegram notifications after a build. Telegram Token can be obtained from BotFather, chat ID can be found with other bots or tricks.

Go to setting of your Travis CI and find the place for environment variables.

Travis yml config to send Telegram notifications.

Since curl is pre-installed on every Travis machines, we will use it to trigger the Telegram webhook after a successful build:

curl -X POST
https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage
-d chat_id=$TELEGRAM_CHAT_ID
-d “text=Sexy Frontend Deployed!"

Travis will insert the environment variables into this URL by itself. You can try to execute thiscurl command locally on your machine to test it out.

The example of working .travis.yml for building the Angular frontend with Telegram notification (check the last line):

And that is it! Happy hacking!

This solution was inspired with this thread: https://github.com/travis-ci/travis-ci/issues/9145

Follow me for more hacks and tricks! With love morejust.foundation.

--

--

No responses yet