Mad World #Save_GAZA: Free Palestine  

Search

How to Get Docker Container Notifications on Telegram with Synology | Docker

  • Share this:
How to Get Docker Container Notifications on Telegram with Synology | Docker

If you're looking for a way to automate certain tasks or just want to have a little fun with telegram, then you may be interested in creating a bot. In this article, we will show you how to create a telegram bot using the BotFather also how to use this bot to build up a notification system to keep you updated. BotFather is the official telegram bot that allows you to create and manage bots for telegram. Let's get started!

 

First, you will need to install telegram on your device. Once you have installed telegram, open it and go to the following menu:

Settings > Apps > Telegram > Permissions

Make sure that the "Notifications" and "Messages" permissions are enabled. If they are not enabled, enable them and then exit telegram.

 

Now, open a web browser and go to the BotFather website:

telegram.me/botfather

Once you have opened the BotFather website, log in with your telegram account. If you do not have a telegram account, you can create one by clicking on this link:

telegram.org/dl

Once you have logged in, you will see a list of commands that BotFather can perform. To create a bot, type the commands below and follow the instructions. Once you have created your bot, BotFather will give you a token. This token is used to authenticate your bot with telegram. Keep this token safe, as you will need it later.

	/newbot
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
	igprod
Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.
	IGProd_bot
Done! Congratulations on your new bot. You will find it at t.me/IGProd_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.

Use this token to access the HTTP API:
51508464384:AAG2Q0yfObXuckxxxxxxxxxx-xxxxxxxxxxxxx
Keep your token secure and store it safely, it can be used by anyone to control your bot.

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

You may also add a description and an image to your bot.

	/setdescription
OK. Send me the new description for the bot. People will see this description when they open a chat with your bot, in a block titled 'What can this bot do?'.
	Docker system notification

Success! Description updated. /help

This table contains additional commands.

/newbot - create a new bot
/mybots - edit your bots [beta]

Edit Bots
/setname - change a bot's name
/setdescription - change bot description
/setabouttext - change bot about info
/setuserpic - change bot profile photo
/setcommands - change the list of commands
/deletebot - delete a bot

Bot Settings
/token - generate authorization token
/revoke - revoke bot access token
/setinline - toggle inline mode
/setinlinegeo - toggle inline location requests
/setinlinefeedback - change inline feedback settings
/setjoingroups - can your bot be added to groups?
/setprivacy - toggle privacy mode in groups

Games
/mygames - edit your games [beta]
/newgame - create a new game
/listgames - get a list of your games
/editgame - edit a game
/deletegame - delete an existing game

If BotFather has successfully configured your bot, you will see your bot's name and profile picture here. If you do not see your bot here, make sure that you have correctly entered your token.

Tape the username that you've previously given your bot in the search area to find it.

bot0



Now that you have created your bot and obtained its token, we'll need to get our chat id because we'll need it in the container settings. 

In order to get the group chat id, do as follows:

Add the Telegram BOT to the group.

Get the list of updates for your BOT:

https://api.telegram.org/bot<YourBOTToken>/getUpdates
Ex:

https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates
Look for the "chat" object:

{"update_id":8393,"message":{"message_id":3,"from":{"id":7474,"first_name":"AAA"},"chat":{"id":XXXXXX<group_ID>,"title":""},"date":25497,"new_chat_participant":{"id":164938438743,"first_name":"NAME","username":"YOUR_BOT_NAME"}}}

(If you created the new group with the bot and you only get {"ok":true,"result":[]}, just send text message to your bot and refresh the page

Source : https://stackoverflow.com/a/32572159

Now We will show you how to configure it in docker container to get notifications so let's go …

Open docker or Portainer and past to the following commands:

Docker CLI

docker run -v /var/run/docker.sock:/var/run/docker.sock:ro --name DSM-notifier -h telegram -e TELEGRAM_NOTIFIER_BOT_TOKEN=Your Token -e TELEGRAM_NOTIFIER_CHAT_ID=XXXXXXX poma/docker-telegram-notifier:latest 

Portainer (Stack) - docker-compose

services:
  notifier:
    image: poma/docker-telegram-notifier:latest
    container_name: DSM-notifier
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro # for local instance
    environment:
      TELEGRAM_NOTIFIER_BOT_TOKEN: Your token 
      TELEGRAM_NOTIFIER_CHAT_ID: Your chat ID
    restart: always
    hostname: telegram
    network_mode: bridge

Now that you've learned how to create a Telegram bot and set up container system notifications, let's put our system to the test.

We gonna stop a container called adminer

docker stop adminer

Let's see if our bot will send us a notification about the container we just stopped.

bot2


Boooooom !!!!!! Have fun with your new telegram bot and your notification system.

If you want to use telegram bots for business purposes, make sure to check out our article on telegram marketing:

telegram.org/blog/telegram-marketing

Thanks for reading!

 Yassine

Yassine

Yassine founded IGProd to educate the visitors with technological tutorials. These helpful guides are available for all sorts of professionals and novices, whether they work in technology or not!

Surf freely 💗

Leave a comment

Your email address will not be published. Required fields are marked *