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://api.telegram.org/bot<token>/setWebHook?url=<Your URL.
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).
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.
Then we create a new method “ANY” And select the call to our Lambda function (Image 3).
Next, we can test our bot in the same way as in Visual Studio (Image 4):
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:
The address for WebHook should be taken in the Invoke URL section (Image 5):
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.