<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Linux Tech</title>
    <description>The latest articles on DEV Community by Linux Tech (@linuxtech).</description>
    <link>https://dev.to/linuxtech</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1075635%2F7ffe6b8c-f0c2-4259-8f26-15c32caab9bd.png</url>
      <title>DEV Community: Linux Tech</title>
      <link>https://dev.to/linuxtech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/linuxtech"/>
    <language>en</language>
    <item>
      <title>How to send Alerts and Notifications with Telegram</title>
      <dc:creator>Linux Tech</dc:creator>
      <pubDate>Tue, 16 Apr 2024 17:13:00 +0000</pubDate>
      <link>https://dev.to/linuxtech/how-to-send-alerts-and-notifications-with-telegram-46of</link>
      <guid>https://dev.to/linuxtech/how-to-send-alerts-and-notifications-with-telegram-46of</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Telegram Bot API
&lt;/h2&gt;

&lt;p&gt;For sending Alerts and Notifications with Telegram we utilize Telegram Bot API which supports programmatic interaction between developers and the Telegram platform. Create a Telegram bot using BotFather, the official bot for managing Telegram bots, to get started. Let us closely look into this process detailed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Telegram Bot
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Start a conversation with BotFather on Telegram by searching for “&lt;a class="mentioned-user" href="https://dev.to/botfather"&gt;@botfather&lt;/a&gt;” in the search bar.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc1vbw0xghmnhm7r04x6q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc1vbw0xghmnhm7r04x6q.png" alt="conversation with BotFather on Telegram&amp;lt;br&amp;gt;
" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuqow3iafpmy1cei4muk.png" alt="Click on start" width="800" height="357"&gt;
&lt;/h2&gt;

&lt;p&gt;Initiate the bot creation process by sending the “/newbot” command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj7nk22vqrvl6usvw2u2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj7nk22vqrvl6usvw2u2.png" alt="select /newbot" width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Follow BotFather’s instructions to set a name and username for your bot. Once created, BotFather will provide you with a unique API token, which you’ll need to access the Telegram Bot API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseh30yv5mgmwz6al6q0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseh30yv5mgmwz6al6q0e.png" alt="your api key generated" width="800" height="483"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Obtaining Chat IDs
&lt;/h2&gt;

&lt;p&gt;To send notifications to specific users or groups, you’ll need their unique chat IDs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Get Chat ID for a Private Chat
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Search and open your Telegram bot in the Telegram app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click “Start” or send a message to initiate a conversation with the bot.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the following URL in a web browser: &lt;code&gt;https://api.telegram.org/bot&amp;lt;your_bot_token&amp;gt;/getUpdates&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;code&gt;&amp;lt;your_bot_token&amp;gt;&lt;/code&gt; with your actual bot token.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You’ll receive a JSON response containing information about recent updates, including the chat ID of the conversation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1391u57ehq07khn0hbtj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1391u57ehq07khn0hbtj.png" alt="Telegram Get Chat ID for a Private Chat&amp;lt;br&amp;gt;
" width="800" height="626"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Get Chat ID for a Group Chat
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Add your Telegram bot to a group chat where you want to obtain the chat ID.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Send a message to the group chat.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the following URL in a web browser: &lt;code&gt;https://api.telegram.org/bot&amp;lt;your_bot_token&amp;gt;/getUpdates&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;code&gt;&amp;lt;your_bot_token&amp;gt;&lt;/code&gt; with your actual bot token.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following these steps should allow you to obtain the chat ID for both private and group chats on Telegram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8umbep98fz0q9rlundv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8umbep98fz0q9rlundv.png" alt="Telegram Get Chat ID for a Group Chat&amp;lt;br&amp;gt;
" width="800" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sending Alerts and Notifications:&lt;br&gt;
To send a text message, you can use a programming language that can handle HTTP requests, like Python or JavaScript.&lt;br&gt;
&lt;strong&gt;Here is a simple cURL request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Replace &lt;code&gt;&amp;lt;YourBotToken&amp;gt;&lt;/code&gt; with your actual bot token and &lt;code&gt;&amp;lt;CHAT_ID&amp;gt;&lt;/code&gt; with the extracted chat ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "https://api.telegram.org/bot&amp;lt;YourBotToken&amp;gt;/sendMessage" \
-d 'chat_id=&amp;lt;CHAT_ID&amp;gt;' -d 'text=Hello, world 👋'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F82mxl0lps3vgmtavf8zx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F82mxl0lps3vgmtavf8zx.png" alt="Text notification⁄alert received using Telegram Api&amp;lt;br&amp;gt;
" width="800" height="1777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;It’s never been easier to send quick messages and alerts with Telegram’s powerful Bot API. If you follow the steps in this article, you’ll be able to add notification features to your apps or systems without any problems. This will allow you to keep your users updated and engaged in real time.&lt;/p&gt;

&lt;p&gt;In addition, the Telegram Bot API can be used for more than just chatting. You can also use it to connect to monitoring tools like Prometheus AlertManager or any other tool you choose. This integration lets you get immediate alerts and notifications about critical events, so you can control your infrastructure actively and respond quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Ready to implement Telegram alerts in Python?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Explore detailed steps and sample code on &lt;a href="https://linuxtech.in/how-to-send-alerts-and-notifications-with-telegram/"&gt;LinuxTech: How to Send Alerts and Notifications with Telegram&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Start Sending Notifications with Telegram Programmatically!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>monitoring</category>
      <category>sre</category>
      <category>python</category>
    </item>
  </channel>
</rss>
