<?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: Dmitry Koleev</title>
    <description>The latest articles on DEV Community by Dmitry Koleev (@dmitry-koleev).</description>
    <link>https://dev.to/dmitry-koleev</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%2F1805300%2Fd98aebb6-deef-4caf-8ca7-80dac87c304e.png</url>
      <title>DEV Community: Dmitry Koleev</title>
      <link>https://dev.to/dmitry-koleev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dmitry-koleev"/>
    <language>en</language>
    <item>
      <title>"What Every Programmer Should Know About Memory" by Ulrich Drepper.</title>
      <dc:creator>Dmitry Koleev</dc:creator>
      <pubDate>Tue, 08 Oct 2024 17:54:09 +0000</pubDate>
      <link>https://dev.to/dmitry-koleev/what-every-programmer-should-know-about-memory-by-ulrich-drepper-2poe</link>
      <guid>https://dev.to/dmitry-koleev/what-every-programmer-should-know-about-memory-by-ulrich-drepper-2poe</guid>
      <description>&lt;p&gt;I highly recommend that every programmer reads &lt;a href="https://people.freebsd.org/~lstewart/articles/cpumemory.pdf" rel="noopener noreferrer"&gt;this&lt;/a&gt; document at least once in their life.&lt;/p&gt;

&lt;h1&gt;
  
  
  Brief overview
&lt;/h1&gt;

&lt;p&gt;In his seminal work, Ulrich Drepper provides a deep dive into the intricacies of modern memory subsystems and offers practical advice for developers aiming to optimize software performance. As CPU cores become faster and more numerous, memory access has emerged as a key bottleneck for many applications. Drepper's paper breaks down how programmers can utilize hardware advancements like CPU caches and RAM to improve efficiency.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Memory Bottlenecks in Modern Systems
&lt;/h2&gt;

&lt;p&gt;The paper starts by highlighting the increasing gap between CPU speed and memory performance. While CPUs have evolved rapidly, memory subsystems, particularly DRAM, have not kept pace. This discrepancy leads to delays, as CPUs often have to wait for data to be retrieved from memory. To combat this, modern systems use caches, but their effectiveness depends on how well software leverages them.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. CPU Caches and Their Importance
&lt;/h2&gt;

&lt;p&gt;CPU caches, small but fast memory storage areas, are critical for bridging the gap between slow memory access times and fast CPU cycles. Caches store frequently accessed data, reducing the number of times the CPU needs to fetch data from slower RAM. Drepper explains the multi-level cache hierarchy (L1, L2, and sometimes L3 caches), detailing how data flows through these caches and how proper usage can drastically reduce access times. The paper also emphasizes that programmers must understand how data is loaded into and evicted from caches to optimize code performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. RAM Types: DRAM vs. SRAM
&lt;/h2&gt;

&lt;p&gt;Drepper discusses the differences between two main types of RAM: Static RAM (SRAM) and Dynamic RAM (DRAM). While SRAM is faster, it's more expensive and takes up more space. Therefore, it is typically used for CPU caches. DRAM, on the other hand, is cheaper and used for main memory, but it is slower and requires constant refreshing. These trade-offs mean that efficient use of memory is essential for performance, especially when designing memory-intensive applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Non-Uniform Memory Access (NUMA) and Direct Memory Access (DMA)
&lt;/h2&gt;

&lt;p&gt;For large systems, memory access can become even more complicated due to architectures like NUMA, where memory is divided into regions that are closer to specific processors. Accessing remote memory in a NUMA system is slower, and Drepper stresses the importance of optimizing memory allocation to reduce latency. Similarly, DMA allows devices to access memory directly without involving the CPU, which can lead to faster data transfers but also introduces competition for memory bandwidth.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Optimizing Software for Memory Subsystems
&lt;/h2&gt;

&lt;p&gt;A significant portion of Drepper’s paper provides actionable advice for programmers. To maximize performance, developers need to design software that aligns with the hardware's memory architecture:&lt;/p&gt;

&lt;p&gt;Cache-friendly algorithms: Organize data structures and access patterns in ways that take advantage of the spatial and temporal locality that caches thrive on.&lt;br&gt;
Prefetching: Both hardware and software prefetching techniques can be used to load data into caches before it is needed, reducing wait times.&lt;br&gt;
Data locality: Keeping data that is frequently accessed together helps ensure that it stays in the cache longer, improving performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Tools for Analyzing Memory Usage
&lt;/h2&gt;

&lt;p&gt;Drepper also introduces various tools that can help programmers analyze their software’s memory usage. These tools can detect cache misses, memory access patterns, and bottlenecks in the system, giving developers the insight they need to optimize their code further.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: The Future of Memory and Software Optimization
&lt;/h2&gt;

&lt;p&gt;Drepper concludes by looking toward the future, discussing upcoming memory technologies and trends, such as faster DDR RAM and more sophisticated cache systems. However, he emphasizes that no matter how advanced memory technology becomes, software must be designed with these hardware constraints in mind. For developers, understanding the structure of memory and CPU caches is crucial for writing efficient code that can handle the demands of modern, multi-core, and multi-threaded processors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In summary&lt;/strong&gt;, "What Every Programmer Should Know About Memory" is an essential guide for developers looking to optimize their software for modern hardware. By understanding how memory works, from caches to RAM to NUMA systems, programmers can write code that performs more efficiently and leverages the full potential of today's computing architectures.&lt;/p&gt;

</description>
      <category>cpu</category>
      <category>memory</category>
      <category>programming</category>
      <category>development</category>
    </item>
    <item>
      <title>How to Create Custom Git Commands on Windows</title>
      <dc:creator>Dmitry Koleev</dc:creator>
      <pubDate>Tue, 01 Oct 2024 08:28:08 +0000</pubDate>
      <link>https://dev.to/dmitry-koleev/how-to-create-a-custom-git-commands-on-windows-4e93</link>
      <guid>https://dev.to/dmitry-koleev/how-to-create-a-custom-git-commands-on-windows-4e93</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;&lt;code&gt;Git&lt;/code&gt;&lt;/a&gt; is one of the most popular version control systems, widely used by developers to manage and track changes in their code. While &lt;code&gt;Git&lt;/code&gt; comes with built-in commands that handle most tasks, sometimes you may want to create custom commands to simplify repetitive tasks or enhance your workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Create Custom Git Commands?
&lt;/h3&gt;

&lt;p&gt;Before diving into the technical details, it's important to understand why creating custom Git commands can be useful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Automation:&lt;/strong&gt; Save time on repetitive tasks by wrapping multiple &lt;code&gt;Git&lt;/code&gt; commands into one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplification:&lt;/strong&gt; Reduce complex command sequences into a single, easy-to-remember command.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; Ensure that your team follows the same workflow by creating shared commands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Personalization:&lt;/strong&gt; Tailor Git’s behavior to match your specific workflow needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, we’ll walk through how to create a custom Git command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fast Push Command
&lt;/h2&gt;

&lt;p&gt;Let’s create a command called &lt;code&gt;fpush&lt;/code&gt; for quickly pushing changes. This command will perform the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pull data from the current branch&lt;/li&gt;
&lt;li&gt;Stage all unstaged changes&lt;/li&gt;
&lt;li&gt;Commit these changes&lt;/li&gt;
&lt;li&gt;Push the commit to the server&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Create the Command File
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a new folder to hold files with custom commands &lt;em&gt;(for example, "E:/git-custom-commands")&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Inside this folder, create a new command file named &lt;code&gt;git-fastpush.cmd&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the following content to the file:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; %1
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Explanation of Commands:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git pull&lt;/code&gt;:&lt;/strong&gt; Fetch changes from a remote repository into the current branch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git add .&lt;/code&gt;:&lt;/strong&gt; Stage all unstaged changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit -m %1&lt;/code&gt;: Commit changes, where &lt;code&gt;%1&lt;/code&gt; is the first argument passed to the command (e.g., &lt;code&gt;git fpush "this_is_commit_message"&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push&lt;/code&gt;: Push the local commit to the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Add a New Alias to the Git Config
&lt;/h2&gt;

&lt;p&gt;Next, we need to add the new &lt;code&gt;alias&lt;/code&gt; to the &lt;strong&gt;Git configuration&lt;/strong&gt; with reference to our file. Run the following command in the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.fpush &lt;span class="s2"&gt;"!E:/git-custom-commands/git-fastpush.cmd"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Run the New Command
&lt;/h2&gt;

&lt;p&gt;You're all set! Now you can execute your new Git command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git fpush "your_comment"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we go. Feel free to create your own custom commands!&lt;/p&gt;

</description>
      <category>git</category>
      <category>windows</category>
    </item>
    <item>
      <title>Host Telegram Bot on Raspberry Pi 5</title>
      <dc:creator>Dmitry Koleev</dc:creator>
      <pubDate>Tue, 24 Sep 2024 17:02:40 +0000</pubDate>
      <link>https://dev.to/dmitry-koleev/host-telegram-bot-on-raspberry-pi-5-16ld</link>
      <guid>https://dev.to/dmitry-koleev/host-telegram-bot-on-raspberry-pi-5-16ld</guid>
      <description>&lt;h3&gt;
  
  
  Table of Contents:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Intruduction&lt;/li&gt;
&lt;li&gt;Install OS on Raspberry Pi 5&lt;/li&gt;
&lt;li&gt;Connect to Raspberry Pi via &lt;code&gt;SSH&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Prepare envariement&lt;/li&gt;
&lt;li&gt;Create and Run the Bot&lt;/li&gt;
&lt;li&gt;Keep the bot running in the background using &lt;code&gt;tmux&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Automatically Start the Bot on Boot (Optional)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Intruduction
&lt;/h2&gt;

&lt;p&gt;In my previous article, I demonstrated how to create and run a Telegram Bot using Python. You can find it &lt;a href="https://dev.to/dmitry-koleev/create-a-telegram-bot-on-python-44l4"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this guide, I’ll walk you through hosting your Telegram bot on your own Raspberry Pi server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install OS on Raspberry Pi 5
&lt;/h2&gt;

&lt;p&gt;Follow &lt;a href="https://www.raspberrypi.com/documentation/computers/getting-started.html#raspberry-pi-imager" rel="noopener noreferrer"&gt;this guide&lt;/a&gt; to create an image with Raspberry Pi Imager.&lt;br&gt;&lt;br&gt;
I recommend choosing &lt;code&gt;Raspberry Pi OS Lite&lt;/code&gt; OS because it is the best option in terms of lightweight simplicity. &lt;/p&gt;

&lt;p&gt;In the imager settings check the box next to &lt;strong&gt;Enable SSH&lt;/strong&gt; and select &lt;strong&gt;use password authentification&lt;/strong&gt;. This will allow you to connect to your Raspberry Pi via &lt;code&gt;SSH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After creating the image on a USB flash drive, insert the flash card into your Raspberry Pi and power it on.&lt;/p&gt;
&lt;h2&gt;
  
  
  Connect to Raspberry Pi via &lt;code&gt;SSH&lt;/code&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open the console (cmd or PowerShell on Windows)&lt;/li&gt;
&lt;li&gt;Ping your Raspberry Pi the following command:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ping raspberrypi.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You’ll receive ping statistics along with the IP address of your Raspberry Pi.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use this IP address to connect via SSH:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SSH pi@&amp;lt;your_raspberry_pi_ip&amp;gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;for &lt;/span&gt;example: SSH pi@192.168.0.10&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Enter the password (default is &lt;code&gt;raspberry&lt;/code&gt;). I strongly recommend changing this later.&lt;/li&gt;
&lt;li&gt;If the password is correct, you will be connected to your Raspberry Pi via &lt;code&gt;SSH&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Prepare Envariement
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Update your Raspberry Pi
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Install Python
Raspberry Pi OS usually comes with &lt;code&gt;Python&lt;/code&gt; pre-installed. Check if it's installed:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If &lt;code&gt;Python&lt;/code&gt; is not installed, you can install it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;python3 python3-pip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Set Up a Virtual Environment (Optional but Recommended)
It’s a good practice to create a virtual environment to keep your project dependencies isolated:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;python3-venv
python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv telegram-bot-env
&lt;span class="nb"&gt;source &lt;/span&gt;telegram-bot-env/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install the &lt;a href="https://python-telegram-bot.org/" rel="noopener noreferrer"&gt;Python Telegram Bot Library&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;python-telegram-bot &lt;span class="nt"&gt;--upgrade&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create and Run the Bot
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a new &lt;code&gt;Python&lt;/code&gt; file using the &lt;code&gt;nano&lt;/code&gt; text editor
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano bot.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Write your bot code in this new file _(you can use code from my &lt;a href="https://dev.to/dmitry-koleev/create-a-telegram-bot-on-python-44l4"&gt;previous article&lt;/a&gt;). Press &lt;code&gt;CTRL + O&lt;/code&gt; then hit &lt;code&gt;Enter&lt;/code&gt; to save changes. To exit press &lt;code&gt;CTRL + X&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Run the bot
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 bot.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your bot is now running, and you can test it on Telegram.  &lt;/p&gt;

&lt;p&gt;However, this method will terminate the bot when you close the terminal.      &lt;/p&gt;

&lt;p&gt;To keep it running in the background we can use &lt;a href="https://github.com/tmux/tmux/wiki" rel="noopener noreferrer"&gt;&lt;code&gt;tmux&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the Bot Running in the Background Using &lt;code&gt;tmux&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create an Executable Shell Script to Start Your Bot
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;code&gt;tmux&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;tmux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a new shell script to start your bot. You can name it start_bot.sh
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano start_bot.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Add the following lines to the script, replacing &lt;code&gt;bot.py&lt;/code&gt; with the name of your Python bot file and &lt;code&gt;telegram-bots-env&lt;/code&gt; with your env name:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;source &lt;/span&gt;telegram-bots-env/bin/activate
python3 bot.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Save and exit &lt;code&gt;(CTRL + O, Enter, CTRL + X)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Make the script executable:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x start_bot.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run Bot via &lt;code&gt;tmux&lt;/code&gt;:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Start a new &lt;code&gt;tmux&lt;/code&gt; session:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux new &lt;span class="nt"&gt;-s&lt;/span&gt; my_bot_session
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Inside the &lt;code&gt;tmux&lt;/code&gt; session, run your bot script:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./start_bot.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Detach from the &lt;code&gt;tmux&lt;/code&gt; session by pressing &lt;code&gt;CTRL + B&lt;/code&gt;, then &lt;code&gt;D&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Reattach to the &lt;code&gt;tmux&lt;/code&gt; Session (if needed)
To reattach to your bot’s &lt;code&gt;tmux&lt;/code&gt; session later, use:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux attach &lt;span class="nt"&gt;-t&lt;/span&gt; my_bot_session
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Automatically Start the Bot on Boot (Optional)
&lt;/h2&gt;

&lt;p&gt;If you want your bot to start automatically on boot, you can use a systemd service. Here’s how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new service file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/systemd/system/my_bot.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Add the following configuration, modifying paths as needed:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[Unit]&lt;/span&gt;
&lt;span class="py"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;My Bot Service&lt;/span&gt;

&lt;span class="nn"&gt;[Service]&lt;/span&gt;
&lt;span class="py"&gt;ExecStart&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/bin/tmux new-session -d -s my_bot_session '/path/to/start_bot.sh'&lt;/span&gt;
&lt;span class="py"&gt;WorkingDirectory&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/path/to/my_bot&lt;/span&gt;
&lt;span class="py"&gt;User&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;pi&lt;/span&gt;

&lt;span class="nn"&gt;[Install]&lt;/span&gt;
&lt;span class="py"&gt;WantedBy&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;multi-user.target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Save and exit the file.&lt;/li&gt;
&lt;li&gt;Reload the systemd daemon:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Enable the service to start on boot:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;my_bot.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Start the service:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start my_bot.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>telegram</category>
      <category>raspberrypi</category>
      <category>python</category>
      <category>bot</category>
    </item>
    <item>
      <title>Create a Telegram Bot on Python</title>
      <dc:creator>Dmitry Koleev</dc:creator>
      <pubDate>Thu, 19 Sep 2024 11:16:41 +0000</pubDate>
      <link>https://dev.to/dmitry-koleev/create-a-telegram-bot-on-python-44l4</link>
      <guid>https://dev.to/dmitry-koleev/create-a-telegram-bot-on-python-44l4</guid>
      <description>&lt;h3&gt;
  
  
  Table of Contents:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What Is a Telegram Bot?&lt;/li&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Creating a Bot on Telegram&lt;/li&gt;
&lt;li&gt;Setting Up Python Environment&lt;/li&gt;
&lt;li&gt;Writing the Bot Code&lt;/li&gt;
&lt;li&gt;Deploying the Bot&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  1. What Is a Telegram Bot?
&lt;/h2&gt;

&lt;p&gt;Bots are small applications that run entirely within the Telegram app. Users interact with bots through flexible interfaces that can support any kind of task or service. &lt;/p&gt;

&lt;p&gt;You can read more about bots in the official documentation:&lt;br&gt;
&lt;a href="https://core.telegram.org/bots" rel="noopener noreferrer"&gt;Bots&lt;/a&gt;&lt;br&gt;
&lt;a href="https://core.telegram.org/bots/api" rel="noopener noreferrer"&gt;Telegram Bot API&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  2. Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before diving into bot creation, you'll need the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A Telegram Account&lt;/strong&gt;: You can easily create one by downloading the Telegram app on your phone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python Installed&lt;/strong&gt;: We will use Python 3, so make sure it’s installed on your computer. &lt;em&gt;&lt;a href="https://www.python.org/downloads/" rel="noopener noreferrer"&gt;download link&lt;/a&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basic Python Knowledge&lt;/strong&gt;: Understanding Python syntax and packages will help you navigate the code. I can recommend this book &lt;a href="https://automatetheboringstuff.com/" rel="noopener noreferrer"&gt;Automate the Boring Stuff with Python&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BotFather Access&lt;/strong&gt;: BotFather is a built-in Telegram bot that helps you manage and create new bots.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VS Code(Optional)&lt;/strong&gt;: I use it for writing my bots. But feel free to choose any other editor. But I'd recommended to use this one.
&lt;em&gt;&lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;Here&lt;/a&gt; you can download the latest version of VS Code, and &lt;a href="https://code.visualstudio.com/docs/python/python-tutorial" rel="noopener noreferrer"&gt;here&lt;/a&gt; is instruction on how to set it for Python.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  3. Creating a Bot on Telegram
&lt;/h2&gt;

&lt;p&gt;To create your own bot, you need to use &lt;strong&gt;BotFather&lt;/strong&gt;, the official tool for registering and managing bots on Telegram.&lt;/p&gt;
&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open Telegram and search for the &lt;strong&gt;BotFather&lt;/strong&gt; bot. (Enter &lt;a class="mentioned-user" href="https://dev.to/botfather"&gt;@botfather&lt;/a&gt; into the search menu)&lt;/li&gt;
&lt;li&gt;Start a chat with BotFather by typing &lt;code&gt;/start&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create a new bot by typing &lt;code&gt;/newbot&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You will be prompted to provide a name for your bot. Enter a unique name (e.g., &lt;code&gt;Hello World&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;BotFather will ask for a username for the bot. The username must end with "bot" (e.g., &lt;code&gt;HelloWorldBot&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;After completing these steps, BotFather will give you a &lt;strong&gt;token&lt;/strong&gt;. This token is crucial as it authenticates your bot and allows you to interact with Telegram’s API.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Keep your token private and do not share it publicly!&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  4. Setting Up Python Environment
&lt;/h2&gt;

&lt;p&gt;Next, we need to set up our Python environment to interact with the Telegram API. We will use the &lt;code&gt;python-telegram-bot&lt;/code&gt; library, which provides a simple and easy-to-use interface for developing Telegram bots.&lt;/p&gt;
&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Install the python-telegram-bot library&lt;/strong&gt;:&lt;br&gt;
 Run the following command to install the necessary library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; pip &lt;span class="nb"&gt;install &lt;/span&gt;python-telegram-bot 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create a new Python file:&lt;/strong&gt; You can name it something like my_bot.py to hold your bot's code.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Writing the Bot Code
&lt;/h2&gt;

&lt;p&gt;Now that our environment is ready, let’s write the bot code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sample Code
&lt;/h3&gt;

&lt;p&gt;Here’s a basic bot that responds to /start and /help commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;telegram&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Update&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;telegram.ext&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ApplicationBuilder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CommandHandler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ContextTypes&lt;/span&gt;

&lt;span class="c1"&gt;# Enable logging
&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;basicConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%(asctime)s - %(name)s - %(levelname)s - %(message)s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;INFO&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Define a start function to respond to the /start command
&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ContextTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DEFAULT_TYPE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reply_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello! I am your bot. How can I help you today?&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Define a help function to respond to the /help command
&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;help_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ContextTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DEFAULT_TYPE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reply_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;You can use the following commands:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;/start - Start the bot&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;/help - Get help&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Create the application and pass the bot token
&lt;/span&gt;    &lt;span class="n"&gt;application&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ApplicationBuilder&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;token&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;YOUR_BOT_TOKEN_HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Add command handlers for /start and /help
&lt;/span&gt;    &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CommandHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;start&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CommandHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;help&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help_command&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="c1"&gt;# Start the bot and run it until manually stopped
&lt;/span&gt;    &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run_polling&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allowed_updates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ALL_TYPES&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Imports:&lt;/strong&gt; We import &lt;code&gt;telegram&lt;/code&gt; and &lt;code&gt;telegram.ext&lt;/code&gt; modules to build our bot. These provide the classes and functions necessary to interact with the Telegram API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging:&lt;/strong&gt; Logging is enabled to track events and errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start and Help Commands:&lt;/strong&gt; We define two functions (&lt;code&gt;start&lt;/code&gt; and &lt;code&gt;help_command&lt;/code&gt;) that send a message when users trigger the corresponding commands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Token:&lt;/strong&gt; Replace &lt;code&gt;'YOUR_BOT_TOKEN_HERE'&lt;/code&gt; with the token you received from BotFather.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Polling:&lt;/strong&gt; The bot uses polling to constantly check for new messages and responds to them as they come.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Running the Bot:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Replace the placeholder token in the code with your bot’s token.&lt;/li&gt;
&lt;li&gt;Run your Python script:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; python my_bot.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your bot is now up and running! Open Telegram, send the &lt;code&gt;/start&lt;/code&gt; or &lt;code&gt;/help&lt;/code&gt; commands to the bot, and it will respond.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Deploying the Bot
&lt;/h2&gt;

&lt;p&gt;Running the bot on your local machine is great for testing, but what if you want it to be available 24/7? To achieve this, you can deploy the bot to a server or cloud service.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Deployment Options:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Heroku:&lt;/strong&gt; A free cloud platform where you can host your bot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS (Amazon Web Services):&lt;/strong&gt; More scalable but may require some setup for beginners.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPS (Virtual Private Server):&lt;/strong&gt; Gives you full control over your server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PythonAnywhere:&lt;/strong&gt; A beginner-friendly option with free tiers.
Each platform offers unique ways to deploy Python applications. You can follow deployment tutorials specific to your chosen service.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7. Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You’ve successfully created a basic Telegram bot using Python. You learned how to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up a Telegram bot using BotFather.&lt;/li&gt;
&lt;li&gt;Write Python code to handle commands.&lt;/li&gt;
&lt;li&gt;Run the bot locally and interact with it on Telegram.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Next, I'd recommend you to learn the &lt;a href="https://docs.python-telegram-bot.org/en/stable/examples.html" rel="noopener noreferrer"&gt;example bots&lt;/a&gt; from &lt;code&gt;python-telegram-bot&lt;/code&gt; &lt;/p&gt;




&lt;p&gt;This is a series of articles. In the next articles, I'll explain how to host your bot on &lt;strong&gt;PythonAnywhere&lt;/strong&gt;, host bots on your own &lt;strong&gt;Raspberry PI&lt;/strong&gt; server, and create more complicated bots.&lt;/p&gt;

</description>
      <category>python</category>
      <category>telegram</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
