How to integrate GitHub Actions with Slack, Telegram andWhatsApp

What if you setup your continuous integration to send some messages?

João Gabriel
7 min readNov 17, 2021

The CI tool GitHub Actions allows us to integrate with some communication tools like Slack, Telegram e Whatsapp. Using this integration, it's possible to send messages to our teams automatically when some specific step of our continuous integration is completed.

Let's go! Let's make continuous integration send some messages! 😃

To do this integration, it's necessary to understand some concepts. The next topic's objective is to make sure you understand the concept of repository secrets on GitHub.

Secrets of the repository

For us to integrate our CI with these third party tools (Slack/Telegram/WhatsApp), GitHub Actions needs to use some private credentials, the safe way to add those credentials inside your repository is to use the secrets of repository. Using the secrets, it's possible to store private credentials that are not going to be visible on our CI instructions file and also store the secrets using cryptography. Follow the steps below to find the secrets of you repository:

  1. Go to settings on your repository
Settings of your project repository circled in red

2. Select Secrets and then select Actions

List of secrets available to use on the Actions

All of the secrets stored on your repository are going to be encrypted 🔐 by default and only used on GitHub Actions. Those secrets can be referenced in the .yml instructions in this way:

${{ secrets.NAME_OF_YOUR_SECRET }}

In this case, it will return the content of the secret named “NAME_OF_YOUR_SECRET” in the repository secrets.

Integrating with Slack

We are going to use this action for this integration. Considering that we already have a Slack Workspace created and a channel dedicated for our CI, we can integrate this channel with the Slack App Incoming WebHooks. Using this app we can have access to a link that will be used by GitHub Actions to send messages on Slack. To do this, follow the steps below:

  • Select the slack channel
  • Select the arrow on the side of the channel name
  • Select "integrations" on the menu
  • Search for and select “Incoming WebHooks”
  • Select "Add to Slack"
  • Select de target channel

The steps above can be visualised below:

Integrating Slack Channel with Incoming WebHooks

At the end of this process, we are going to see the "Installation Instructions", with the link in the first topic "Webhook URL". Copy this link.

Create the secret with this link on your repository with the name:

SLACK_WEBHOOK_URL

Follow the steps below to add the secret on your repository:

Creating the secret of the repository with the link of the Incoming WebHook for Slack.

Now, we can create our .yml file in this way:

(This file must be created inside root of the repository “.github/workflows/notifier.yml”.)

File .yml prepared to send custom message on Slack

About the above code:

  • Line 17 = SLACK_CHANNEL = Here we can add the name of the slack channel
  • Line 18 = SLACK_TITLE = Here we can add the title of the message
  • Line 19 = SLACK_USERNAME = Here we can add the name of the user that will be associated with the message
  • Line 21 = SLACK_MESSAGE = The message
  • Line 20 = SLACK_WEBHOOK = Property referencing the secret of the repository with the link for the webhook

Executing the CI we have the following results 😃

Message sent on Slack.

Integrating with Telegram

For us to integrate with telegram, we are going to use telegram-action that integrates with a Telegram bot. First of all, it's necessary to create the bot (that has a token), and a chat.

Creating a bot

Based on the documentation of Telegram about bots, follow the steps below:

  • Access BotFather and select “Send message”
  • Start a chat with BotFather and send the message:
/newbot
  • Send a message with the name of your bot
  • Send a message with the unique user name (that will be associated with your bot)
  • After creating the bot, you will receive a message with the token

OBS.: The token is generated with the format below:

1234567890:ABCDE123ABCDE123ABCDE123ABCDE123ABC

Creating the chat

Now that our bot is created, we can create a chat with it. To do this, let's open Telegram and follow the steps below:

  • Search for the unique user name associated with your bot (step 4 of creating a bot)
  • Start a conversation with this user
  • Send the message
/start
  • Send a message with any text

Obtaining the chat id (that we started above)

Finally the bot and the chat are built. Now we need to find the chat id. To get it let's follow the steps bellow:

  • Open terminal
  • Execute the command below (replacing "TOKEN" with the token of your bot)
curl https://api.telegram.org/botTOKEN/getUpdates
  • Get the id of the chat inside the API response (the bold id in the example API response below XXXXXXXXX)
{
"ok":true,
"result":[
{
"update_id":777368030,
"message":{
"message_id":1,
"from":{
"id":1234567890,
"is_bot":false,
"first_name":"YourUserName",
"username":"YourTelegramUser",
"language_code":"pt-br"
},
"chat":{
"id":XXXXXXXXX,
"first_name":"YourUserName",
"username":"YourTelegramUser",
"type":"private"
},
"date":1234567890,
"text":"/start",
"entities":[
{
"offset":0,
"length":6,
"type":"bot_command"
}
]
}
}
]
}

For more details about Telegram Bots, visit Telegram Bots API.

Configuring Action

Nice! 😮‍💨 Now that we have our bot token and our chat id, we can insert this information on the repository secrets.

The token is going to be placed inside the secret named TELEGRAM_TOKEN and the id inside the secret named TELEGRAM_TO. After adding the secrets, your secrets list will look like this:

Token e ID added

Now, we can prepare our .yml file in this way:

(This file must be created inside root of the repository “.github/workflows/notifier.yml”.)

The .yml file for sending custom Telegram messages.

As we can see, the content of message (from line19) can be used to insert a custom text to send.

We can see the results of executing the CI, below 😃

Message received on Telegram.

Integrating with WhatsApp

In this tutorial, we are going to use this action and a third party tool for us to send messages on WhatsApp. The name of the tool is Twilio. Let's follow the steps below.

OBS.: There is a free tier of $15 dollars after creating the account. It's important for you to know that this is a payed tool that works in a pay-as-you-go model. To see details about pricing, visit Twilio WhatsApp Pricing.

  1. Create an account on Twilio

2. Configure the repository secrets

3. Create the repository secrets below:

WPP_TWILIO_TO_WHATSAPP_NO

This secret is for you to add the phone number that has WhatsApp in the format: 5511900001111

4. To get the account sid and auth token, visit Twillio:

Twilio console, with Account SID and Auth Token

5. Create the repository secrets and add respectively the account sid and auth token:

WPP_TWILIO_ACCOUNT_SIDWPP_TWILIO_AUTH_TOKEN

After adding these 3 secrets, the repository secrets list is going to look like this:

Repository secret list with the 3 secrets.

5. Sen a message to Twilio.

Using the left menu on the Twilio website, go to Messaging / Try it out / Send a WhatsApp message. Send the indicated message (in this case “join merely-potatoes”) for the indicated number on WhatsApp, as we can see bellow:

Guide on Twilio for sending messages.

It's importante for you to know that this configuration uses the Twilio phone number to sent messages, but there is another way to do this. It's possible to register your own phone number to send messages by following the oficial Twilio documentation.

6. Create the .yml file on your repository.

(This file must be created inside root of the repository “.github/workflows/notifier.yml”.)

The .yml file for sending custom messages on WhatsApp.

As we can see, the content of message (line 21) can be a custom message as needed.

After executing the CI, we are going to receive the message as we can see below:

Message sent on WhatsApp.

Conclusion

There is a lot of options to communicate with our teams about the steps of our CI. Knowing the available tools, it's possible to do better choices depending on out needs. I hope you have learned some new integrations today to use on your projects. 😃

Messages sent after executing the CI.

--

--