paint-brush
How to Easily Deploy Telegram Bot Using AWS Lambdaby@vdoomik
3,031 reads
3,031 reads

How to Easily Deploy Telegram Bot Using AWS Lambda

by Uladzislau Baryshchyk3mJuly 18th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Telegram has become popular these days and has more than 500 million users. The messenger opened its API for developers, and now everyone can create their own bot. It may seem that deploying a telegram bot in C # is difficult, but I want to show that it is not. In this article, I will give an example of publishing it on AWS. The next step is we need to create a WeBHook. For this we use the following address:https://api.telegram.org/bot<token>/setWebHook?url=<Your URL.
featured image - How to Easily Deploy Telegram Bot Using AWS Lambda
Uladzislau Baryshchyk HackerNoon profile picture


Telegram has become popular these days and has more than 500 million users. One of the main “tricks” of Telegram is its supposed security — according to Pavel Durov, all correspondence between users is encrypted. Moreover, no one will have access to your messages. But this article is not about that.


Today I would like to talk about an equally cool feature in Telegram, namely bots. In addition to the fact that the internet is already full of information about various kinds of Telegram bots, the messenger opened its API for developers, and now everyone can create their own bot. It may seem that deploy a telegram bot in C # is difficult, but I want to show that it is not. In this article, I will give an example of publishing it on AWS.

Registration

First of all, you have to register your bot in telegram. For this step, go to the telegram application. It doesn’t matter what kind of application you use and find the @BotFather bot. Using /start command, you can start registration (Image 1).

Image 1 -Registration of a bot

Next, choose /newbot command and set up a bot name. Then you will receive a token to access the HTTP API. This you need to use later.

Bot’s deployment

There are many ways how to deploy a telegram bot, one of them is to connect the AWS tool kit to the Visual Studio, the second is to create a Lambda function and deploy the code from the .zip file. It doesn’t matter how you do this, but before deploying, the function with the bot should already be in the AWS Lambda. Then, we need to configure the AWS service. Go to the AWS Management Console and find the API Gateway service and create a new Rest API there (Image 2). You can choose any name for your API.

Image 2 -Creating API for the bot

Then we create a new method “ANY” And select the call to our Lambda function (Image 3).

Image 3 - Creating ANY method

Next, we can test our bot in the same way as in Visual Studio (Image 4):

Image 4 - Testing the bot

Then, let’s send our API to Deploy. The next step is we need to create a WeBHook. For this we use the following address:

<https://api.telegram.org/bot<token>/setWebHook?url=<Your url>>

The address for WebHook should be taken in the Invoke URL section (Image 5):

Image 5 -Url for the bot

After successful installation of WebHook, the telegram website should write a message:

{"ok":true,"result":true,"description":"Webhook was set"}

Now you can check the bot. The bot is ready and re-sends messages back from the user.

Conclusion

In conclusion, you will now see how easy it is to deploy it to AWS. In this article, I showed how easy it is to create a Telegram bot in C # /. Net and publish it using AWS services. In the open spaces of the internet, I did not find such an article, and this was the motivation for writing this article.


A part of this article is also published on https://www.codeproject.com/Tips/5303407/How-to-Easily-Create-Telegram-Bot-using-Csharp.