Friday , December 6 2024

How To Send Telegram Messages From SQL Server

In today’s article, I will be explaining how to send the notifications we obtain while managing SQL Server to Telegram.

First of all, of course, the first thing we need to do is to have a telegram account.

I would also like to give basic information about Telegram.

It is a WhatsApp-style messaging platform that we all use, and it has different features that distinguish both products from each other.

We may need WhatsApp business or different middleware to send notifications from WhatsApp, which we will explain in the subject.

After sharing information about Telegram, what we need to do is to obtain a token and a chat_id to send notifications in Telegram.

To do this, we log in to “web.telegram.org”.

Picture-1 web.telegram.org

We write @BotFather in the Search section and start the conversation with start.

Picture-2 @BotFather features

As seen in the picture above, we can actually get support for many contents with @BotFather.

What we want to do is create a new bot.

For this we write “/newbot”.

It first asks us for a name for the bot, and then a username for the bot.

Picture-3 Bot Information

The important thing to note in Picture 3 is that the username information must end with _bot, and the same picture gives you the HTTP API information you will need to use this bot. Don’t forget to take note of this information!

Next is to get Chat_id information.

To do this, we call the username we gave in picture-2 and say hello. (We search and find it and say start.)

Picture-4 Hello Bot

After saying Hello to the bot we created, all we need to do is edit and open the address below in a new browser tab.

Here we replace the part that says <HTTPTOKENAPI> with the HTTPAPI information we see in Picture 3.

When we continue the process, a screen like the one below appears.

Picture-5 Obtaining chat_id information

We have completed what needs to be done on Telegram, now we have Token information and Chat_id information.

Using these two information, we will make an http post request in SQL Server and send our notification.

For this process, we first need to enable the use of Ole objects on the SQL Server side.

Let’s do this with the code block below.

Now it’s time for the query to make the notification. There are two parts in the query that need to be changed.

We will enter the Token and Chat_id information we have, write the notification we want and run the query. (You must fill in the @TelegramToken and @TelegramChatId information!)

If your transaction is successful after the query, the information you provided will be sent to Telegram.

Picture6 Result

By using this method, you can quickly get information about the developing situations in the SQL Server Database Servers under your management.

With different improvements, you can send notifications to telegram groups and instantly inform many people other than yourself.

Loading

About Çağlar Özenç

Leave a Reply

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