<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gabriel Rossetto on Medium]]></title>
        <description><![CDATA[Stories by Gabriel Rossetto on Medium]]></description>
        <link>https://medium.com/@gabriel.dadamosrossetto?source=rss-ae4f24dcdd7e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wCDqJkV7oqgFtsznoKEl7g.jpeg</url>
            <title>Stories by Gabriel Rossetto on Medium</title>
            <link>https://medium.com/@gabriel.dadamosrossetto?source=rss-ae4f24dcdd7e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:21:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gabriel.dadamosrossetto/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a Simple Telegram Bot using Node.js: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@gabriel.dadamosrossetto/creating-a-simple-telegram-bot-using-node-js-a-step-by-step-guide-b476447955c6?source=rss-ae4f24dcdd7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b476447955c6</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[telegram-bot]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Gabriel Rossetto]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 21:14:58 GMT</pubDate>
            <atom:updated>2023-07-10T21:14:58.726Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this step-by-step guide, we’ll walk through the process of creating a simple Telegram bot using Node.js. By the end of this tutorial, you’ll have a fully functional bot that can respond to user commands and engage with Telegram users.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eZyGEF5iyWKpDOXp.jpg" /></figure><h3>Step 1: Setting Up a New Node.js Project 📁</h3><p>1 - Create a new directory for your project. You can choose a name that reflects your bot’s purpose.</p><p>2 - Open a command line interface and navigate to the project directory you just created.</p><p>3 - Run the command npm init to initialize a new Node.js project. You&#39;ll be prompted to provide information about your project, such as the name, version, and entry point. You can simply press Enter to accept the default values for most prompts.</p><p>4 - Once the initialization is complete, you’ll have a package.json file in your project directory, which keeps track of your project&#39;s dependencies and settings.</p><h3>Step 2: Creating the Bot and Obtaining the Token 🛠️</h3><p>1 - Open the Telegram app on your device and search for the BotFather.</p><p>2 - Start a chat with the BotFather and follow the instructions to create a new bot.</p><p>3 - Once your bot is created, the BotFather will provide you with an API token. This token serves as the authentication mechanism for your bot. Make sure to keep it secure as it grants access to your bot’s functionality.</p><h3>Step 3: Let’s code! 💻</h3><p>1 - Create a new JavaScript file in your project directory. You can name it something like bot.js.</p><p>2 - Open the bot.js file in a code editor of your choice.</p><p>3 - Begin by requiring the node-telegram-bot-api package at the top of your file:</p><pre>const TelegramBot = require(&#39;node-telegram-bot-api&#39;);</pre><p>4 - Initialize the bot by passing your API token and enabling the polling option. This allows the bot to listen for and receive new messages:</p><pre>const token = &#39;YOUR_TELEGRAM_BOT_TOKEN&#39;; // Replace with your own bot token<br>const bot = new TelegramBot(token, { polling: true });</pre><p>5 - Add an event listener to handle incoming messages. This listener will be triggered whenever a user sends a message to your bot:</p><pre>bot.on(&#39;message&#39;, (msg) =&gt; {<br>  const chatId = msg.chat.id;<br>  const messageText = msg.text;<br><br>  // Process the incoming message here<br><br>});</pre><p>6 - Implement the logic to respond to user messages within the event listener. For example, if a user sends the /start command, you can respond with a welcome message:</p><pre>bot.on(&#39;message&#39;, (msg) =&gt; {<br>  const chatId = msg.chat.id;<br>  const messageText = msg.text;<br><br>  if (messageText === &#39;/start&#39;) {<br>    bot.sendMessage(chatId, &#39;Welcome to the bot!&#39;);<br>  }<br>});</pre><p>By following the previous steps, your bot.js file will look like this:</p><pre>const TelegramBot = require(&#39;node-telegram-bot-api&#39;);<br><br>const token = &#39;YOUR_TELEGRAM_BOT_TOKEN&#39;; // Replace with your own bot token<br>const bot = new TelegramBot(token, { polling: true });<br><br>bot.on(&#39;message&#39;, (msg) =&gt; {<br>  const chatId = msg.chat.id;<br>  const messageText = msg.text;<br><br>  if (messageText === &#39;/start&#39;) {<br>    bot.sendMessage(chatId, &#39;Welcome to the bot!&#39;);<br>  }<br>});</pre><h3>Step 4: Running the Bot 🤖</h3><p>1 - Open a terminal or command prompt and navigate to your project directory.</p><p>2 - Run the command node bot.js to start the bot. You should see a message indicating that the bot is running and waiting for incoming messages.</p><p>3 - Switch to the Telegram app on your device and find your bot by its username or display name.</p><p>4 - Send a message to your bot and observe its response. If you implemented the /start command, you should receive a welcome message.</p><h3>That’s it! 🥳</h3><p>Congratulations! You have successfully created a simple Telegram bot using Node.js. With this foundation, you can now explore further possibilities such as adding more commands, integrating external APIs, or personalizing your bot’s responses based on user interactions.</p><p>Telegram’s Bot API documentation (<a href="https://core.telegram.org/bots/api">https://core.telegram.org/bots/api</a>) is an excellent resource for discovering additional features and capabilities available to enhance your bot. Enjoy experimenting and building your own interactive Telegram bot!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b476447955c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>