{"id":93,"date":"2018-09-27T14:55:00","date_gmt":"2018-09-27T14:55:00","guid":{"rendered":"https:\/\/159.69.80.24\/blog\/how-to-create-and-deploy-a-telegram-bot\/"},"modified":"2024-10-17T08:05:05","modified_gmt":"2024-10-17T08:05:05","slug":"how-to-create-and-deploy-a-telegram-bot","status":"publish","type":"post","link":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/","title":{"rendered":"How to Deploy Webhook-Integrated Telegram Bot in Python\/Django"},"content":{"rendered":"<p>Telegram Bots are simple automated software applications that communicate with the target audience through Telegram messenger. But despite their simplicity, they can be used for various tasks, from virtual assistants to full-fledged business tools for client communication and sales. With their help, it\u2019s possible even to get customer payments, so Telegram has become a convenient and valuable multipurpose tool.<!--\n\n\n<h2 id=\"header0\">Introduction or Why You Should Try a Bot<\/h2>\n\n\n<strong>(you may skip it if you already know what to do with your bot)<\/strong>\nBots are everywhere. It seems that only yesterday we did not even know about their existence; now we can barely imagine our life without them. They\u2019ve become widely popular among numerous active users of messengers since they have various scopes of use - from entertaining content including step-by-step games and collecting bonus points in restaurants, to keeping a diet plan, tracking deliveries, and even making payments for different services.<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_1.png\" alt=\"Python Telegram bot\" \/> --><br \/>\n<div class=\"info_box_shortcode_holder\" style=\"background-image: url(https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2023\/08\/Web-Development_1.png)\">\n    <div class=\"info_box_label\">\n    Services\n    <\/div>\n    <div class=\"info_box_logo\">\n    \n    <\/div>\n    \n    <div class=\"info_box_title font_size_\">\n   <span class=\"info_box_title_inner\">Boost your web development.&lt;br \/&gt;\n<\/span>\n    <\/div>\n    <div class=\"info_box_link\">\n        <a href=\"https:\/\/djangostars.com\/services\/web-development\/\" target=\"_blank\" >\n            <span>Learn More<\/span>\n            <div class=\"button_animated\">\n                <svg width=\"24\" height=\"12\" viewBox=\"0 0 24 12\" fill=\"none\"\n                     xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M23.725 5.33638C23.7248 5.3361 23.7245 5.33577 23.7242 5.33549L18.8256 0.460497C18.4586 0.0952939 17.865 0.096653 17.4997 0.463684C17.1345 0.830668 17.1359 1.42425 17.5028 1.7895L20.7918 5.06249H0.9375C0.419719 5.06249 0 5.48221 0 5.99999C0 6.51777 0.419719 6.93749 0.9375 6.93749H20.7917L17.5029 10.2105C17.1359 10.5757 17.1345 11.1693 17.4998 11.5363C17.865 11.9034 18.4587 11.9046 18.8256 11.5395L23.7242 6.66449C23.7245 6.66421 23.7248 6.66388 23.7251 6.6636C24.0923 6.29713 24.0911 5.70163 23.725 5.33638Z\"\n                          fill=\"#282828\"><\/path>\n                <\/svg>\n                <div class=\"shape\"><\/div>\n            <\/div>\n        <\/a>\n    <\/div>\n<\/div><br \/>\nIn this post, we will share our personal experience creating a Python Telegram bot. Why are they so popular? What\u2019s their secret? I think the more relevant question is why they are more convenient than an app. And there are a few reasons.<\/p>\n<h2 id=\"header0\">Benefits of Telegram Bots on Python\/Django<\/h2>\n<p>Let\u2019s explore some reasons why you should invest in Telegram bots and adopt them in your business processes.<\/p>\n<p><strong>1) Minimalistic and simple design.<\/strong><\/p>\n<p>In comparison to numerous apps with different designs when you have to remember where and what to tap, bots are more universal and easy; they offer simple communication via texts.<\/p>\n<p>Thus, no one requires bots to have colorful designs. However, from <a href=\"https:\/\/telegram.org\/blog\/posts-in-stories-and-more\/\">December 2023<\/a>, an owner of a Telegram bot can flexibly set up its visual appearance. With the announced Telegram Premium features, it\u2019s possible to customize bots\u2019 wallpapers, emoji statuses, and profile logos. At the same time, users can repost channel messages in their stories and more. <!--Thus, no one required bots to have colorful designs. However, from spring 2022, --><\/p>\n<p><a href=\"https:\/\/telegram.org\/blog\/notifications-bots\">Telegram provided<\/a> bot developers with the tools to create infinitely flexible interfaces with JavaScript. Now, if you have some experience creating bots for Telegram, Python knowledge, and the desire, you can create a full-fledged replacement for a regular website.<\/p>\n<p>Read Also: <a href=\"https:\/\/djangostars.com\/blog\/10-popular-sites-made-on-django\/\">Popular Websites Made on Django<\/a><\/p>\n<p><strong>2)A bot has minimum of advertising and focuses on the users\u2019 needs.<\/strong><\/p>\n<p>You do not have to install hundreds of apps for each service if you can receive all the necessary assistance from a bot. This is particularly useful for restaurants and shops. Clients are rarely eager to install apps from a bunch of places they\u2019ve visited. Due to this, business owners miss clients\u2019 feedback and lose communication with them. If each of these places had their own bot available in different messengers, it would be more convenient and friendly to users.<\/p>\n<div style=\"padding-left: 40px;\">On March 31, 2024, businesses <a href=\"https:\/\/telegram.org\/blog\/telegram-business\/uk?setln=en\">received a vital update<\/a>. Companies can create business accounts with additional business features. For example, companies may deploy a Telegram bot, specify their location and open hours, create custom start pages, code quick automated replies, etc.Moreover, this update considerably widened the possibilities of business bots and mini-applications. These new features are available for all users with Premium subscriptions.<\/div>\n<p>Nobody likes to fill up the storage of their phones with unnecessary apps that will be used once or twice. However, clients need to engage with the service owners and they will appreciate doing this through their favorite messenger.<\/p>\n<p><strong>3) No need for signing up, authorization, and constant relogin<\/strong><\/p>\n<p>When setting up a Telegram bot, Python and its libraries can be used to automatize authorization. That allows a user to pass authorization only once when the bot is added to the chat. Client can use the bot as much as it is necessary, and when there is no need in it anymore, user just blocks the bot. That\u2019s all, easy! No password resets anymore.<br \/>\n<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_2.png\" alt=\"Password Resets\" \/><br \/>\nNo need to remember passwords or logins used. Adding bot to the site or app increases the number of the user audience as it makes communication with clients and providing them with the assistance much easier and user-friendly.<\/p>\n<p>In addition, the app&#8217;s popularity also plays a role. And if we&#8217;re talking about Telegram bots, Telegram <a href=\"https:\/\/telegram.org\/blog\/700-million-and-premium\" rel=\"nofollow\">announced<\/a> having over 700 million monthly active users in the summer of 2022.<\/p>\n<p>Some european countries discuss to ban or restrict access to Telegram, but it\u2019s still a powerful rapidly developing tool that is almost indispensable for business.<\/p>\n<p>So, we described main advantages of the bots and now you must be willing to create your own bot. Let\u2019s move on to the practice. But first, we\u2019ll take a look at issues that must be addressed in the pre-development stage.<!--[cta-banner title=\"Boost your <u>web development.<\/u>\" image=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2019\/05\/5_1_bg.png\" button=\"Learn more\" link=\"https:\/\/djangostars.com\/services\/web-development\/\" small_text=\"Get an experienced technical partner.\"]--><\/p>\n<h2 id=\"header1\">Nuances of Telegram Bot Deployment with Python<\/h2>\n<p>Above, we\u2019ve determined the reasons for creating the bot. This also applies to the creating a Telegram bot using Python. In this part, we are planning to cover how to <a href=\"https:\/\/djangostars.com\/blog\/how-much-it-costs-to-build-a-web-application\/\">build the application<\/a> and what development tools to use. Further, we\u2019ll show how to create a Telegram bot on Python and will teach it to turn our message backwards.<\/p>\n<p>Since it\u2019s a Django Telegram bot tutorial for beginners, the code examples aren\u2019t supposed to be complicated. We\u2019ll run the server with a single endpoint that will receive our telegram messages and will make an answer.<\/p>\n<p>To deploy Python telegram bot, <!--For that, -->we will use the following tools:<\/p>\n<ul>\n<li><a href=\"https:\/\/bottlepy.org\/docs\/dev\/\" rel=\"nofollow\">bottle<\/a> &#8211; for our server; a simple and lightweight WSGI micro <a href=\"https:\/\/djangostars.com\/blog\/what-is-a-web-framework\/\">web-framework<\/a><\/li>\n<li><a href=\"http:\/\/docs.python-requests.org\/en\/master\/\" rel=\"nofollow\">requests<\/a> &#8211; for sending requests to telegram. <code>request<\/code> lib does not need to be overrepresented. It is universally used throughout the world in a variety of projects.<\/li>\n<\/ul>\n<p>Note: you have to install these tools on your computer. We will need them later. For that, open your bash console and install it via pip<\/p>\n<pre><code>pip install bottle requests\r\n<\/code><\/pre>\n<ul>\n<li><code>ngrok<\/code> &#8211; this is an app which provides us with public URLs for our interaction with Telegram WebHook throughout the development phase (look for info on WebHook Telegram Bot below). It is useful, as Telegram will not be able to make a connection with our local server because we cannot specify our local address in the Telegram API configuration.<br \/>\nYou should download <code>ngrok<\/code> from the <a href=\"https:\/\/ngrok.com\/download\" rel=\"nofollow\">official site<\/a> and put the installed app in the folder with the project.<\/li>\n<\/ul>\n<p>Read Also: <a href=\"https:\/\/djangostars.com\/blog\/debugging-python-applications-with-pdb\/\">Debugging Python Applications with the PDB Module<\/a><br \/>\n<div class=\"info_box_shortcode_holder\" style=\"background-image: url(https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2023\/08\/Python-Development.png)\">\n    <div class=\"info_box_label\">\n    Services\n    <\/div>\n    <div class=\"info_box_logo\">\n    \n    <\/div>\n    \n    <div class=\"info_box_title font_size_\">\n   <span class=\"info_box_title_inner\">Python: Battle-tested solutions for any needs.&lt;br \/&gt;\n<\/span>\n    <\/div>\n    <div class=\"info_box_link\">\n        <a href=\"https:\/\/djangostars.com\/services\/python-development\/\" target=\"_blank\" >\n            <span>Learn More<\/span>\n            <div class=\"button_animated\">\n                <svg width=\"24\" height=\"12\" viewBox=\"0 0 24 12\" fill=\"none\"\n                     xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M23.725 5.33638C23.7248 5.3361 23.7245 5.33577 23.7242 5.33549L18.8256 0.460497C18.4586 0.0952939 17.865 0.096653 17.4997 0.463684C17.1345 0.830668 17.1359 1.42425 17.5028 1.7895L20.7918 5.06249H0.9375C0.419719 5.06249 0 5.48221 0 5.99999C0 6.51777 0.419719 6.93749 0.9375 6.93749H20.7917L17.5029 10.2105C17.1359 10.5757 17.1345 11.1693 17.4998 11.5363C17.865 11.9034 18.4587 11.9046 18.8256 11.5395L23.7242 6.66449C23.7245 6.66421 23.7248 6.66388 23.7251 6.6636C24.0923 6.29713 24.0911 5.70163 23.725 5.33638Z\"\n                          fill=\"#282828\"><\/path>\n                <\/svg>\n                <div class=\"shape\"><\/div>\n            <\/div>\n        <\/a>\n    <\/div>\n<\/div><\/p>\n<h2 id=\"header2\">How to Create a Telegram Bot with Python<\/h2>\n<p><!--How About to Create Your First Bot?-->If you are keen on this, explore this part where we will provide a detailed Telegram bot development tutorial and show useful Python development tools for it.<\/p>\n<p>First things first. To create a Telegram bot with Python, you need to register on Telegram (obviously). I recommend to use <a href=\"https:\/\/web.telegram.org\/\" target=\"_blank\" rel=\"nofollow noopener\">Telegram web client<\/a> for testing the basic concepts.<\/p>\n<p>Open Telegram app, search for <strong>@BotFather<\/strong> and start the chat. Send <strong>\/newbot<\/strong> command and follow the instructions. After completing the initial steps, you\u2019ll get \u2014<\/p>\n<ul>\n<li>Your own TOKEN<\/li>\n<li>telegram api URL \u2014 <strong>api.telegram.org\/&lt;your token &gt;<\/strong><\/li>\n<li><a href=\"https:\/\/core.telegram.org\/bots\/api\" target=\"_blank\" rel=\"nofollow noopener\">link on documentation<\/a><\/li>\n<\/ul>\n<p>Wells, that\u2019s actually it. At the moment the bot is 100% passive.<\/p>\n<p>You need to initialize a conversation with your bot. Open search and type in the name of your bot. Start a conversation by clicking on <strong>\/start<\/strong> button. Type in something like \u201cHello\u201d. This message is important as it\u2019s the first update your bot is going to receive.<\/p>\n<p>If it\u2019s your first experience with <a href=\"https:\/\/djangostars.com\/blog\/rest-apis-django-development\/\">building APIs<\/a>, you can easily get the idea using your web browser. Open a new tab in your browser and use the Telegram api URL &#8211;<\/p>\n<p><strong> api.telegram. org\/bot&lt;your token &gt; \/getUpdates <\/strong><\/p>\n<p>When you open this URL in your web browser, you make a request to Telegram server, that responds back with JSON. Response resembles Python dictionary. You should see something like this:<\/p>\n<pre><code class=\"language-json\">{\"ok\":true,\"result\":[{\"update_id\":523349956,\r\n\"message\":{\"message_id\":51,\"from\":{\"id\":303262877,\"first_name\":\"YourName\"},\"chat\":{\"id\":303262877,\"first_name\":\"YourName\",\"type\":\"private\"},\"date\":1486829360,\"text\":\"Hello\"}}]}\r\n<\/code><\/pre>\n<p>If you open bots documentation and check <strong>\/sendMessage<\/strong> method <a href=\"https:\/\/core.telegram.org\/bots\/api#sendmessage\" target=\"_blank\" rel=\"nofollow noopener\">section<\/a> you\u2019ll notice that this method requires 2 additional parameters <strong>chat_id<\/strong> and <strong>text<\/strong>. In a browser search bar you can chain parameters using <strong>?<\/strong> for the first one and <strong>&amp;<\/strong> for all the consequent. Send message would look like this &#8211;<\/p>\n<pre><code>\/sendMessage?chat_id=303262877&amp;text=test\r\n<\/code><\/pre>\n<p>Try to get the reply from your bot by substituting <strong>chat_id<\/strong> with one you get by calling <strong>\/getUpdates<\/strong>. In my case it is 303262877. Text parameter is up to you. The request should look like this<\/p>\n<p><strong>api.telegram. org\/ bot&lt;your-token&gt;\/sendMessage?chat_id=&amp;text=&lt;your-text&gt;<\/strong><\/p>\n<p>Read also: <a href=\"https:\/\/djangostars.com\/blog\/why-python-is-good-for-artificial-intelligence-and-machine-learning\/\">8 Reasons Why Python is Good for AI and ML<\/a><\/p>\n<h2 id=\"header4\">Deploying a Telegram Bot Webhook<\/h2>\n<p><!--<strong>(You can skip this part if you\u2019re familiar with WebHook)<\/strong>-->To put it short, a WebHook is an API concept that grows in popularity. The concept of a WebHook is simple. A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST.<\/p>\n<p>To explain a bit more, sometimes an interaction between apps online requires immediate response to the event, while solutions for constant and continuous connections are mostly cumbersome, exacting and hard to support. In this case, the best and the easiest solution is immediate callback via HTTP (most often POST).<\/p>\n<p>In other words, this solution ensures response to any event inside the one app by means of sending HTTP POST request to other connected app in order to inform it or to make it respond.<\/p>\n<p>This exact concept is called WebHook. It is widely used for:<\/p>\n<ul>\n<li>receiving data in real time<\/li>\n<li>receiving data and passing it on<\/li>\n<li>processing data and giving something in return<\/li>\n<\/ul>\n<p>Seems that it is the best solution for interaction of the Telegram client (Telegram app) with our project. Let&#8217;s try to create a Telegram bot using webhooks.<br \/>\n<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_3.png\" alt=\"The Best Solution for Interaction\" \/><br \/>\n<div class=\"info_box_shortcode_holder\" style=\"background-image: url(https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2023\/08\/Django-Development.png)\">\n    <div class=\"info_box_label\">\n    Services\n    <\/div>\n    <div class=\"info_box_logo\">\n    \n    <\/div>\n    \n    <div class=\"info_box_title font_size_\">\n   <span class=\"info_box_title_inner\">Django: The Best Quality-Value Ratio.&lt;br \/&gt;\n<\/span>\n    <\/div>\n    <div class=\"info_box_link\">\n        <a href=\"https:\/\/djangostars.com\/services\/python-django-development\/\" target=\"_blank\" >\n            <span>Learn More<\/span>\n            <div class=\"button_animated\">\n                <svg width=\"24\" height=\"12\" viewBox=\"0 0 24 12\" fill=\"none\"\n                     xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M23.725 5.33638C23.7248 5.3361 23.7245 5.33577 23.7242 5.33549L18.8256 0.460497C18.4586 0.0952939 17.865 0.096653 17.4997 0.463684C17.1345 0.830668 17.1359 1.42425 17.5028 1.7895L20.7918 5.06249H0.9375C0.419719 5.06249 0 5.48221 0 5.99999C0 6.51777 0.419719 6.93749 0.9375 6.93749H20.7917L17.5029 10.2105C17.1359 10.5757 17.1345 11.1693 17.4998 11.5363C17.865 11.9034 18.4587 11.9046 18.8256 11.5395L23.7242 6.66449C23.7245 6.66421 23.7248 6.66388 23.7251 6.6636C24.0923 6.29713 24.0911 5.70163 23.725 5.33638Z\"\n                          fill=\"#282828\"><\/path>\n                <\/svg>\n                <div class=\"shape\"><\/div>\n            <\/div>\n        <\/a>\n    <\/div>\n<\/div><\/p>\n<h2 id=\"header5\">Coding Part<\/h2>\n<p>At last, we start the most practical part where you will be able to develop a Telegram bot.<\/p>\n<p><em>Main task: teach our bot to turn our message backwards<\/em><\/p>\n<p>Firstly, create a folder for our bot project.<\/p>\n<p>Secondly, create bot.py file to make a bottle server.<br \/>\n<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_4.png\" alt=\"Bottle Server\" \/><br \/>\nNext, we develop bot.py<\/p>\n<pre><code class=\"language-language python\">from bottle import run, post\r\n@post('\/')  # our python function based endpoint\r\ndef main():\r\n    return\r\nif __name__ == '__main__':\r\n    run(host='localhost', port=8080, debug=True)\r\n<\/code><\/pre>\n<p>1. Let\u2019s try to start our server. For this, open bash in your bot folder.<\/p>\n<pre><code>python bot.py\r\n<\/code><\/pre>\n<p>In the result, you should see something like this:<br \/>\n<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_5-0.png\" alt=\"telegram bot python development\" \/><br \/>\n2. Then, open a new tab. In the next tab, we will start <code>ngrok<\/code><br \/>\n<code>.\/ngrok http &lt;our_server_port&gt;<\/code><\/p>\n<pre><code>.\/ngrok http 8080\r\n<\/code><\/pre>\n<p>After, you\u2019ll see something like this:<br \/>\n<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_5-1.png\" alt=\"telegram bot development\" \/><br \/>\n3. Now, let\u2019s set WebHook.<br \/>\nOpen your browser and follow the link<\/p>\n<p><b>https:\/\/api.telegram.org\/bot<span style=\"color: green;\">&lt;YOUR_TOKEN&gt;<\/span>\/setWebHook?url=https:\/\/<span style=\"color: green;\">&lt;your ngrok url&gt;<\/span>.ngrok.io\/<\/b><br \/>\n<!-- https:\/\/api.telegram.org\/bot<YOUR_TOKEN>\/setWebHook?url=https:\/\/<your ngrok url>.ngrok.io\/  <strong>api. telegram. org\/bot&lt;your_token&gt;\/setWebHook?url=https:\/\/&lt;your_ngrok_url.ngrok.io\/<\/strong> --><\/p>\n<ul>\n<li>Note: to find ngrok URL, you have to launch ngrok. Then, on the screen similar to the one below, you\u2019ll find URL (it is highlighted on our screenshot). This URL you use in the link for setting WebHook.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_5-2.png\" alt=\"telegram bot development\" \/><br \/>\nResponse to following the link should be like:<br \/>\n<code>{\"ok\":true,\"result\":true,\"description\":\"Webhook was set\"}<\/code><br \/>\nLet&#8217;s check if you succeeded in setting up WebHook<!--webhook telegram bot-->. Follow this link using your token:<\/p>\n<p><b>https:\/\/api.telegram.org\/bot<span style=\"color: green;\">&lt;YOUR_TOKEN&gt;<\/span>\/getWebhookInfo<\/b><br \/>\n<!-- https:\/\/api.telegram.org\/bot<YOUR_TOKEN>\/getWebhookInfo  <strong>api. telegram. org\/bot&lt;your_token&gt;\/getWebhookInfo<\/strong> --><br \/>\nIf everything is right, you\u2019ll see the same ngrok address value in front of URL key that you specified when configuring.<\/p>\n<p>Congrats, it\u2019s alive!<br \/>\n<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_6.gif\" alt=\"\" \/><br \/>\nNow, we need to implement a message request\/response mechanism.<br \/>\nBasically, our endpoint gets data in json format. So, normally, you\u2019ll see data message.<\/p>\n<pre><code class=\"language-language python\">from bottle import run, post, request as bottle_request  # &lt;--- we add bottle request\r\n@post('\/')\r\ndef main():\r\n    data = bottle_request.json  # &lt;--- extract all request data\r\n    print(data)\r\n    return\r\nif __name__ == '__main__':\r\n    run(host='localhost', port=8080, debug=True)\r\n<\/code><\/pre>\n<p>It should be something like that in your console tab where the server is launched.<\/p>\n<pre><code class=\"language-json\">{'update_id': &lt;integer&gt;, 'message': {'message_id': &lt;integer&gt;, 'from': {'id': &lt;your telegram id&gt;, 'is_bot': False, 'first_name': '&lt;your telegram name&gt;', 'last_name': '&lt;...&gt;', 'username': '&lt;...&gt;', 'language_code': 'en-En'}, 'chat': {'id': &lt;integer chat id&gt;, 'first_name': '&lt;...&gt;', 'last_name': '&lt;...&gt;', 'username': '&lt;...&gt;', 'type': 'private'}, 'date': 1535022558, 'text': '1'}}\r\n<\/code><\/pre>\n<p>More detailed information on the parameters you may find in the <a href=\"https:\/\/core.telegram.org\/bots\/api\" rel=\"nofollow\">official documentation of Telegram<\/a>. And if you need some help, <a href=\"https:\/\/djangostars.com\/services\/python-development\/\">feel free to contact us<\/a> and ask.<!--[cta-banner title=\"<u>Python &amp; Django<\/u> development\" image=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2019\/05\/2_1_bg.png\" button=\"Learn more\" link=\"https:\/\/djangostars.com\/services\/python-django-development\/\" small_text=\"Your chance to enter the market faster\"]--><br \/>\n<div class=\"info_box_shortcode_holder\" style=\"background-image: url(https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2023\/08\/Bespoke-Software-Development.png)\">\n    <div class=\"info_box_label\">\n    Services\n    <\/div>\n    <div class=\"info_box_logo\">\n    \n    <\/div>\n    \n    <div class=\"info_box_title font_size_\">\n   <span class=\"info_box_title_inner\">Benefit from our expertise at every development stage.&lt;br \/&gt;\n<\/span>\n    <\/div>\n    <div class=\"info_box_link\">\n        <a href=\"https:\/\/djangostars.com\/get-in-touch\/\" target=\"_blank\" >\n            <span>Get a Consultation<\/span>\n            <div class=\"button_animated\">\n                <svg width=\"24\" height=\"12\" viewBox=\"0 0 24 12\" fill=\"none\"\n                     xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M23.725 5.33638C23.7248 5.3361 23.7245 5.33577 23.7242 5.33549L18.8256 0.460497C18.4586 0.0952939 17.865 0.096653 17.4997 0.463684C17.1345 0.830668 17.1359 1.42425 17.5028 1.7895L20.7918 5.06249H0.9375C0.419719 5.06249 0 5.48221 0 5.99999C0 6.51777 0.419719 6.93749 0.9375 6.93749H20.7917L17.5029 10.2105C17.1359 10.5757 17.1345 11.1693 17.4998 11.5363C17.865 11.9034 18.4587 11.9046 18.8256 11.5395L23.7242 6.66449C23.7245 6.66421 23.7248 6.66388 23.7251 6.6636C24.0923 6.29713 24.0911 5.70163 23.725 5.33638Z\"\n                          fill=\"#282828\"><\/path>\n                <\/svg>\n                <div class=\"shape\"><\/div>\n            <\/div>\n        <\/a>\n    <\/div>\n<\/div><br \/>\nNow, we have to extract <code>chat_id<\/code> and <code>text<\/code> in order to turn our message backwards and send the answer.<\/p>\n<pre><code class=\"language-language python\">from bottle import (\r\n    run, post, response, request as bottle_request\r\n)\r\ndef get_chat_id(data):\r\n    \"\"\"\r\n    Method to extract chat id from telegram request.\r\n    \"\"\"\r\n    chat_id = data['message']['chat']['id']\r\n    return chat_id\r\ndef get_message(data):\r\n    \"\"\"\r\n    Method to extract message id from telegram request.\r\n    \"\"\"\r\n    message_text = data['message']['text']\r\n    return message_text\r\ndef change_text_message(text):\r\n    \"\"\"\r\n    To turn our message backwards.\r\n    \"\"\"\r\n    return text[::-1]\r\n@post('\/')\r\ndef main():\r\n    data = bottle_request.json\r\n    answer_data = prepare_data_for_answer(data)\r\n    return response  # status 200 OK by default\r\n<\/code><\/pre>\n<p>Now, we\u2019ve already prepared the answer. Let\u2019s send it to Telegram bot.<\/p>\n<pre><code class=\"language-language python\">import requests\r\nfrom bottle import (\r\n    run, post, response, request as bottle_request\r\n)\r\nBOT_URL = 'https:\/\/api.telegram.org\/bot&lt;YOUR_TOKEN&gt;\/' # &lt;--- add your telegram token here; it should be like https:\/\/api.telegram.org\/bot12345678:SOMErAn2dom\/\r\ndef get_chat_id(data):\r\n    \"\"\"\r\n    Method to extract chat id from telegram request.\r\n    \"\"\"\r\n    chat_id = data['message']['chat']['id']\r\n    return chat_id\r\ndef get_message(data):\r\n    \"\"\"\r\n    Method to extract message id from telegram request.\r\n    \"\"\"\r\n    message_text = data['message']['text']\r\n    return message_text\r\ndef send_message(prepared_data):\r\n    \"\"\"\r\n    Prepared data should be json which includes at least `chat_id` and `text`\r\n    \"\"\"\r\n    message_url = BOT_URL + 'sendMessage'\r\n    requests.post(message_url, json=prepared_data)  # don't forget to make import requests lib\r\ndef change_text_message(text):\r\n    \"\"\"\r\n    To enable turning our message inside out\r\n    \"\"\"\r\n    return text[::-1]\r\ndef prepare_data_for_answer(data):\r\n    answer = change_text_message(get_message(data))\r\n    json_data = {\r\n        \"chat_id\": get_chat_id(data),\r\n        \"text\": answer,\r\n    }\r\n    return json_data\r\n@post('\/')\r\ndef main():\r\n    data = bottle_request.json\r\n    answer_data = prepare_data_for_answer(data)\r\n    send_message(answer_data)  # &lt;--- function for sending answer\r\n    return response  # status 200 OK by default\r\nif __name__ == '__main__':\r\n    run(host='localhost', port=8080, debug=True)\r\n<\/code><\/pre>\n<p>After all preparations and coding, if everything works, let\u2019s try to chat with our bot.<br \/>\n<img decoding=\"async\" src=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2022\/09\/How-to-Create-and-Deploy-a-Telegram-Bot_7.png\" alt=\"\" \/><br \/>\nNow, let\u2019s make our code more readable and implement OOP structure.<\/p>\n<pre><code class=\"language-language python\">import requests\r\nfrom bottle import Bottle, response, request as bottle_request\r\nclass BotHandlerMixin:\r\n    BOT_URL = None\r\n    def get_chat_id(self, data):\r\n        \"\"\"\r\n        Method to extract chat id from telegram request.\r\n        \"\"\"\r\n        chat_id = data['message']['chat']['id']\r\n        return chat_id\r\n    def get_message(self, data):\r\n        \"\"\"\r\n        Method to extract message id from telegram request.\r\n        \"\"\"\r\n        message_text = data['message']['text']\r\n        return message_text\r\n    def send_message(self, prepared_data):\r\n        \"\"\"\r\n        Prepared data should be json which includes at least `chat_id` and `text`\r\n        \"\"\"\r\n        message_url = self.BOT_URL + 'sendMessage'\r\n        requests.post(message_url, json=prepared_data)\r\nclass TelegramBot(BotHandlerMixin, Bottle):\r\n    BOT_URL = 'https:\/\/api.telegram.org\/bot000000000:aaaaaaaaaaaaaaaaaaaaaaaaaa\/'\r\n    def __init__(self, *args, **kwargs):\r\n        super(TelegramBot, self).__init__()\r\n        self.route('\/', callback=self.post_handler, method=\"POST\")\r\n    def change_text_message(self, text):\r\n        return text[::-1]\r\n    def prepare_data_for_answer(self, data):\r\n        message = self.get_message(data)\r\n        answer = self.change_text_message(message)\r\n        chat_id = self.get_chat_id(data)\r\n        json_data = {\r\n            \"chat_id\": chat_id,\r\n            \"text\": answer,\r\n        }\r\n        return json_data\r\n    def post_handler(self):\r\n        data = bottle_request.json\r\n        answer_data = self.prepare_data_for_answer(data)\r\n        self.send_message(answer_data)\r\n        return response\r\nif __name__ == '__main__':\r\n    app = TelegramBot()\r\n    app.run(host='localhost', port=8080)\r\n<\/code><\/pre>\n<p>That&#8217;s pretty much it. Now you&#8217;ve made a working bot for Telegram, Python-based, and even able to spell &#8220;racecar&#8221; backwards. Congrats!<\/p>\n<p>Read also: <a href=\"https:\/\/djangostars.com\/blog\/python-rule-engine\/\">Python Rule Engine: Logic Automation &amp; Examples<\/a><\/p>\n<h2 id=\"header6\">In Conclusion<\/h2>\n<p>Telegram bots are easy to create and pretty cheap, but they are utterly useful tools. For most businesses, they can revolutionize the ways of contact with a target audience and help free managers from routine and repeatable tasks.<\/p>\n<p>Are you interested in creating more serious software solutions and products like those in our company&#8217;s <a href=\"https:\/\/djangostars.com\/case-studies\/\">portfolio<\/a> and adding them to your business? <b><a href=\"https:\/\/djangostars.com\/get-in-touch\/\">Get in touch<\/a> with Django Stars and <a href=\"https:\/\/djangostars.com\/services\/hire-python-developers\/\">hire Python developers<\/a> to create business projects in Python and Django.<\/b> <div class=\"lead-form-wrapper lets_disqus\">\n    <div class=\"lead-form transparent-footer\">\n        <p class=\"discuss-title paragraph-discuss col-md-12\">Have an idea? Let&#039;s discuss!<\/p>\n\n        \n<div class=\"wpcf7 no-js\" id=\"wpcf7-f2589-o1\" lang=\"en-US\" dir=\"ltr\" data-wpcf7-id=\"2589\">\n<div class=\"screen-reader-response\"><p role=\"status\" aria-live=\"polite\" aria-atomic=\"true\"><\/p> <ul><\/ul><\/div>\n<form action=\"\/blog\/wp-json\/wp\/v2\/posts\/93#wpcf7-f2589-o1\" method=\"post\" class=\"wpcf7-form init\" aria-label=\"Contact form\" enctype=\"multipart\/form-data\" novalidate=\"novalidate\" data-status=\"init\">\n<div style=\"display: none;\">\n<input type=\"hidden\" name=\"_wpcf7\" value=\"2589\" \/>\n<input type=\"hidden\" name=\"_wpcf7_version\" value=\"6.0.6\" \/>\n<input type=\"hidden\" name=\"_wpcf7_locale\" value=\"en_US\" \/>\n<input type=\"hidden\" name=\"_wpcf7_unit_tag\" value=\"wpcf7-f2589-o1\" \/>\n<input type=\"hidden\" name=\"_wpcf7_container_post\" value=\"0\" \/>\n<input type=\"hidden\" name=\"_wpcf7_posted_data_hash\" value=\"\" \/>\n<input type=\"hidden\" name=\"form_start_time\" value=\"1777136919\" \/>\n<input type=\"hidden\" name=\"_wpcf7_recaptcha_response\" value=\"\" \/>\n<\/div>\n<div class=\"form_holder\">\n    <div class=\"input_section input_row\">\n        <div class=\"input_holder\">\n                            <span class=\"input_label\">\n                               Your name *\n                            <\/span>\n            <input size=\"40\" maxlength=\"400\" class=\"wpcf7-form-control wpcf7-text wpcf7-validates-as-required\" id=\"your-name\" aria-required=\"true\" aria-invalid=\"false\" value=\"\" type=\"text\" name=\"text-898\" \/>\n\n            <input class=\"wpcf7-form-control wpcf7-hidden\" id=\"uniq_ga_id\" value=\"\" type=\"hidden\" name=\"uniq_ga_id\" \/>\n        <\/div>\n        <div class=\"input_holder\">\n                            <span class=\"input_label\">\n                                Your email *\n                            <\/span>\n            <input size=\"40\" maxlength=\"400\" class=\"wpcf7-form-control wpcf7-email wpcf7-validates-as-required wpcf7-text wpcf7-validates-as-email\" id=\"your-email\" aria-required=\"true\" aria-invalid=\"false\" value=\"\" type=\"email\" name=\"email-882\" \/>\n        <\/div>\n    <\/div>\n    <div class=\"input_section single_input_row\">\n        <div class=\"input_holder\">\n            <span class=\"input_label\">How can we help you? *<\/span>\n            <input size=\"40\" maxlength=\"400\" class=\"wpcf7-form-control wpcf7-text\" id=\"message\" aria-invalid=\"false\" value=\"\" type=\"text\" name=\"message\" \/>\n        <\/div>\n    <\/div>\n    <div class=\"file_attach\">\n        <input size=\"40\" class=\"wpcf7-form-control wpcf7-file\" accept=\"audio\/*,video\/*,image\/*\" aria-invalid=\"false\" type=\"file\" name=\"file-930\" \/>\n        <div class=\"file_placeholder\">\ud83d\udcce <span>Attach File<\/span>\n            <span class=\"file_formats\">Formats: pdf, doc, docx, rtf, ppt, pptx.<\/span><\/div>\n    <\/div>\n    <div class=\"checkbox_row\">\n        <div class=\"single_checkbox\"><div class=\"checkbox_indicator\"><div class=\"checked_indicator\"><svg width=\"14\" height=\"12\" viewBox=\"0 0 14 12\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M4.66804 12L0 7.26951L1.22426 6.05269L4.54927 9.40456L12.6737 0L14 1.10613L4.66804 12Z\" fill=\"#1E232C\"\/><\/svg><\/div><\/div><input type=\"checkbox\" name=\"agree\" id=\"privacy\" value=\"agree privacy\"><label for=\"privacy\" class=\"\">I have read and accepted <a href=\"https:\/\/djangostars.com\/privacy-policy\/\" style=\"margin-left: 6px;\"> Privacy Policy*<\/a><\/label><\/div>\n        <div class=\"single_checkbox\"><div class=\"checkbox_indicator\"><div class=\"checked_indicator\"><svg width=\"14\" height=\"12\" viewBox=\"0 0 14 12\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M4.66804 12L0 7.26951L1.22426 6.05269L4.54927 9.40456L12.6737 0L14 1.10613L4.66804 12Z\" fill=\"#1E232C\"\/><\/svg><\/div><\/div><input type=\"checkbox\" name=\"agree\" id=\"marketing\" value=\"agree for marketing\"><label for=\"marketing\" class=\"\">I agree to receive marketing content from Django Stars<\/label><\/div>\n    <\/div>\n    <div class=\"submit\"><button type=\"submit\"><span>send message<\/span><\/button><div class=\"safeguard\">We safeguard your privacy<\/div><\/div>\n<\/div>\n<div style=\"position: absolute; left: -5000px;\" aria-hidden=\"true\">\n    <input size=\"40\" maxlength=\"400\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" value=\"\" type=\"text\" name=\"website_url\" \/>\n<\/div><script type='text\/javascript'>\n\n\t\t\t\t\t\tif(contactform === undefined){\n\t\t\t\t\t\t\tvar contactform = [];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvar innerVal = [2589,'mail_sent_ok','Thank you for your message. It has been sent.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'mail_sent_ng','There was an error trying to send your message. Please try again later.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'validation_error','One or more fields have an error. Please check and try again.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'spam','There was an error trying to send your message. Please try again later.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'accept_terms','You must accept the terms and conditions before sending your message.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_required','The field is required.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_too_long','The field is too long.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_too_short','The field is too short.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'upload_failed','There was an unknown error uploading the file.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'upload_file_type_invalid','You are not allowed to upload files of this type.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'upload_file_too_large','The file is too big.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'upload_failed_php_error','There was an error uploading the file.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_date','The date format is incorrect.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'date_too_early','The date is before the earliest one allowed.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'date_too_late','The date is after the latest one allowed.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_number','The number format is invalid.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'number_too_small','The number is smaller than the minimum allowed.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'number_too_large','The number is larger than the maximum allowed.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'quiz_answer_not_correct','The answer to the quiz is incorrect.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_email','The e-mail address entered is invalid.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_url','The URL is invalid.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'invalid_tel','The telephone number is invalid.'];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\tvar innerVal = [2589,'gdpr',''];\n\t\t\t\t\t\tcontactform.push(innerVal);\n\t\t\t\t\t\t<\/script><div class=\"wpcf7-response-output\" aria-hidden=\"true\"><\/div>\n<\/form>\n<\/div>\n    <\/div>\n\n    <div class=\"success_disqus\">\n        Thank you for your message.\n        <span>We\u2019ll contact you shortly<\/span>.\n    <\/div>\n<\/div>\n\n<script>\n    \/\/ (function ($) {\n    function click_input() {\n        jQuery('.file_placeholder').on('click', function () {\n            jQuery(this).parent().find('input').click();\n        })\n    }\n\n    document.addEventListener(\"DOMContentLoaded\", click_input);\n\n    \/\/ })(jQuery)\n<\/script>\n\n\n<div class=\"dj-main-article-faq\" style=\"padding-top: 0px;\">\n\t\t<div class=\"dj-main-article-faq-title\">\n\t\tFrequently Asked Questions\n\t\t<\/div>\n\t\t<div class=\"dj-main-article-faq-items\">\n\t\t\t<div class=\"dj-main-article-faq-accordeon accordeon\"><dl>\n\t\t\t\t<dt>Is it possible to create a Telegram bot without coding and without using Python\/Django? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>Telegram bots can be written in different programming languages (e.g., PHP, Java, and Go) or without coding using bot constructors. However, Python is easy to learn and gives more flexibility due to a large number of open-source libraries and ready-made solutions. This is why writing bots for Telegram in Python is so popular. Our Python\/Django Telegram bot tutorial for beginners will help you create your own bot in Python.<\/dd>\n\t\t\t<\/dl><dl>\n\t\t\t\t<dt>I need a telegram bot to deliver and order food. Is it possible to do this using Python? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>Yes. Telegram bots have various scopes of use \u2013 from entertaining content, including step-by-step games and collecting bonus points in restaurants, to keeping a diet plan, tracking deliveries, and even making payments for different services. And among other things, you can create a bot to help customers order and deliver food.<\/dd>\n\t\t\t<\/dl><dl>\n\t\t\t\t<dt>Do you have experience creating a Telegram chatbot for financial services? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>Fintech is one of the domains our Python development team specializes in. For example, our <a href=\"https:\/\/djangostars.com\/case-studies\/\">case studies<\/a> include the UK's first digital mortgage lender Molo and Switzerland's biggest mortgage broker Money Park. Therefore, don't hesitate to contact Django Stars if you need help creating a bot for financial services.<\/dd>\n\t\t\t<\/dl><dl>\n\t\t\t\t<dt>Why are Telegram bots so popular? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>Some think bots are more convenient than apps. And there are a few reasons: <ol> <li>Minimalistic and simple design.<\/li> <li>Bot has a minimum of advertising and focuses on the users\u2019 needs.<\/li> <li>No need for signing up, authorization, and constant relogin.<\/li><\/ol> And the Telegram app\u2019s popularity also plays a role. <\/ol><\/dd>\n\t\t\t<\/dl><\/div>\n\t\t\t<\/div>\n\t\t<\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Telegram Bots are simple automated software applications that communicate with the target audience through Telegram messenger. But despite their simplicity, they can be used for various tasks, from virtual assistants to full-fledged business tools for client communication and sales. With their help, it\u2019s possible even to get customer payments, so Telegram has become a convenient [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":3536,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[68,44],"tags":[30,7],"class_list":["post-93","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-engineering","category-python-django","tag-backend","tag-case-studies"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Software Development Blog &amp; IT Tech Insights | Django Stars<\/title>\n<meta name=\"description\" content=\"A complete Webhook Telegram bot tutorial. Check it out and learn how to create and deploy a simple greeting bot using Python\/Django.\" \/>\n<link rel=\"canonical\" href=\"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/93\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Deploy Webhook-Integrated Telegram Bot in Python\" \/>\n<meta property=\"og:description\" content=\"A complete Webhook Telegram bot tutorial. Check it out and learn how to create and deploy a simple greeting bot using Python\/Django.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/\" \/>\n<meta property=\"og:site_name\" content=\"Software Development Blog &amp; IT Tech Insights | Django Stars\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/djangostars\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-27T14:55:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-17T08:05:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1440\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sergey Kubrak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@djangostars\" \/>\n<meta name=\"twitter:site\" content=\"@djangostars\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sergey Kubrak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/\"},\"author\":{\"name\":\"Sergey Kubrak\",\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/4d67ed98a6588e28d3f5e04bec4e80cd\"},\"headline\":\"How to Deploy Webhook-Integrated Telegram Bot in Python\/Django\",\"datePublished\":\"2018-09-27T14:55:00+00:00\",\"dateModified\":\"2024-10-17T08:05:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/\"},\"wordCount\":2077,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg\",\"keywords\":[\"Backend\",\"Case Study\"],\"articleSection\":[\"Expert Python \ud83d\udc0d Engineering &amp; Software Dev &amp; Tech Insights\",\"Python &amp; Django\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/\",\"url\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/\",\"name\":\"How to Deploy Webhook-Integrated Telegram Bot in Python\",\"isPartOf\":{\"@id\":\"https:\/\/djangostars.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg\",\"datePublished\":\"2018-09-27T14:55:00+00:00\",\"dateModified\":\"2024-10-17T08:05:05+00:00\",\"author\":{\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/4d67ed98a6588e28d3f5e04bec4e80cd\"},\"description\":\"A complete Webhook Telegram bot tutorial. Check it out and learn how to create and deploy a simple greeting bot using Python\/Django.\",\"breadcrumb\":{\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage\",\"url\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg\",\"contentUrl\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg\",\"width\":1440,\"height\":620,\"caption\":\"How-to-Create-and-Deploy-a-Telegram-Bot-using-Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/djangostars.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Deploy Webhook-Integrated Telegram Bot in Python\/Django\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/djangostars.com\/blog\/#website\",\"url\":\"https:\/\/djangostars.com\/blog\/\",\"name\":\"Software Development Blog &amp; IT Tech Insights | Django Stars\",\"description\":\"Welcome behind the scenes of software product development. We share our best practices, tech solutions, management tips, and every useful insight we\u2018ve got while working on our projects.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/djangostars.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/4d67ed98a6588e28d3f5e04bec4e80cd\",\"name\":\"Sergey Kubrak\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5842fa273aa83af40f5c19068b136dcaf6d1f57c79fd46dd6ccb0c688aca0173?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5842fa273aa83af40f5c19068b136dcaf6d1f57c79fd46dd6ccb0c688aca0173?s=96&d=mm&r=g\",\"caption\":\"Sergey Kubrak\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sergey-kubrak-787560b5\/\"],\"url\":\"https:\/\/djangostars.com\/blog\/author\/sergey-kubrak\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Software Development Blog &amp; IT Tech Insights | Django Stars","description":"A complete Webhook Telegram bot tutorial. Check it out and learn how to create and deploy a simple greeting bot using Python\/Django.","canonical":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/93","og_locale":"en_US","og_type":"article","og_title":"How to Deploy Webhook-Integrated Telegram Bot in Python","og_description":"A complete Webhook Telegram bot tutorial. Check it out and learn how to create and deploy a simple greeting bot using Python\/Django.","og_url":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/","og_site_name":"Software Development Blog &amp; IT Tech Insights | Django Stars","article_publisher":"https:\/\/www.facebook.com\/djangostars\/","article_published_time":"2018-09-27T14:55:00+00:00","article_modified_time":"2024-10-17T08:05:05+00:00","og_image":[{"width":1440,"height":620,"url":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg","type":"image\/jpeg"}],"author":"Sergey Kubrak","twitter_card":"summary_large_image","twitter_creator":"@djangostars","twitter_site":"@djangostars","twitter_misc":{"Written by":"Sergey Kubrak","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#article","isPartOf":{"@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/"},"author":{"name":"Sergey Kubrak","@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/4d67ed98a6588e28d3f5e04bec4e80cd"},"headline":"How to Deploy Webhook-Integrated Telegram Bot in Python\/Django","datePublished":"2018-09-27T14:55:00+00:00","dateModified":"2024-10-17T08:05:05+00:00","mainEntityOfPage":{"@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/"},"wordCount":2077,"commentCount":0,"image":{"@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage"},"thumbnailUrl":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg","keywords":["Backend","Case Study"],"articleSection":["Expert Python \ud83d\udc0d Engineering &amp; Software Dev &amp; Tech Insights","Python &amp; Django"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/","url":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/","name":"How to Deploy Webhook-Integrated Telegram Bot in Python","isPartOf":{"@id":"https:\/\/djangostars.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage"},"image":{"@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage"},"thumbnailUrl":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg","datePublished":"2018-09-27T14:55:00+00:00","dateModified":"2024-10-17T08:05:05+00:00","author":{"@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/4d67ed98a6588e28d3f5e04bec4e80cd"},"description":"A complete Webhook Telegram bot tutorial. Check it out and learn how to create and deploy a simple greeting bot using Python\/Django.","breadcrumb":{"@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#primaryimage","url":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg","contentUrl":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/How-to-Create-and-Deploy-a-Telegram-Bot-using-Python.jpg","width":1440,"height":620,"caption":"How-to-Create-and-Deploy-a-Telegram-Bot-using-Python"},{"@type":"BreadcrumbList","@id":"https:\/\/djangostars.com\/blog\/how-to-create-and-deploy-a-telegram-bot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/djangostars.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Deploy Webhook-Integrated Telegram Bot in Python\/Django"}]},{"@type":"WebSite","@id":"https:\/\/djangostars.com\/blog\/#website","url":"https:\/\/djangostars.com\/blog\/","name":"Software Development Blog &amp; IT Tech Insights | Django Stars","description":"Welcome behind the scenes of software product development. We share our best practices, tech solutions, management tips, and every useful insight we\u2018ve got while working on our projects.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/djangostars.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/4d67ed98a6588e28d3f5e04bec4e80cd","name":"Sergey Kubrak","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5842fa273aa83af40f5c19068b136dcaf6d1f57c79fd46dd6ccb0c688aca0173?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5842fa273aa83af40f5c19068b136dcaf6d1f57c79fd46dd6ccb0c688aca0173?s=96&d=mm&r=g","caption":"Sergey Kubrak"},"sameAs":["https:\/\/www.linkedin.com\/in\/sergey-kubrak-787560b5\/"],"url":"https:\/\/djangostars.com\/blog\/author\/sergey-kubrak\/"}]}},"_links":{"self":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/93","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/comments?post=93"}],"version-history":[{"count":38,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/93\/revisions"}],"predecessor-version":[{"id":8317,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/93\/revisions\/8317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/media\/3536"}],"wp:attachment":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/media?parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/categories?post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/tags?post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}