Launch of telegram bota hosted by ucoz. How much do Telegram bots really cost? Mandatory commands for bots

We have collected two and a half dozen of the most interesting bots for Telegram... And others were discovered quite recently. Take it apart.

1. Fast AID - an assistant for Telegram designed to provide first aid. Saved more than one life.

2. GrammarNaziBot - spell checking bot. You can add it to the general chat so that everyone is ashamed of incorrect spelling.

3. Controller Bot - a bot designed for Telegram channel administrators, supporting delayed publications and more.

4. Telegram Store Bot - but with the help of this smart bot you can search for other bots. A very convenient assistant who helped create this collection.

5. Arena Game - an extraordinary gaming bot, with the help of which you can be distracted for a few minutes by extraordinary gameplay.

6. CryptoBot - a bot that monitors the cost of Bitcoin and Ethereum, and also shows a graph of changes in the price of the first.

7. Weatherman - this bot sends the weather in selected cities according to schedule. It will be useful in the changeable autumn.

8. TempMail - a bot for Telegram, with which you can create a temporary mailbox in seconds for registering on dubious services.

9. Movie buff - but this bot will tell you what movie or TV series to watch tonight. He follows new products not only on official resources.

10. Yandex.Translate - bot for translation from Russian into English, from English into Russian and vice versa. One of the most useful in the collection.

11. Accents - the bot will tell you about the accents in the most tricky Russian words. It will be a great help in ridiculous arguments with friends.

12. InstaSave is an interesting bot for Telegram, with which you can download photos and even stories from Instagram.

13. Pomodoro - an extraordinary bot timer for the most productive work. It will help you work for 25 minutes and rest for 5 minutes.

14. MyCookBot - a unique bot that can suggest some interesting recipe based on the list of products lying around in your refrigerator.

15. Vinci - a companion bot for the mobile application of the same name, which is designed for processing photos with neural networks.

16. DeLorean - a real time machine that will help you send messages to yourself in the future. Convenient instead of reminders.

17. To PDF - a bot designed to convert DOC, DOCX, ODT, TXT, JPG and other file types to PDF.

18. Dr.Web - a proprietary bot of popular antivirus software designed to scan files up to 10 MB for viruses.

19. Programming - a bot that is designed not only for professional, but also for novice programmers.

20. SoundCloud - a smart assistant for searching and downloading tracks from a popular service directly through the messenger.

21. EasyStrongPasswordBot - a mobile assistant designed to create complex passwords that cannot be hacked.

22. Wolfram Alpha - an assistant who will solve mathematical problems and talk about scientific principles via Telegram.

23. PollBot - a simple bot designed to create questionnaires in group chats. Very convenient.

24. Translator - the fastest possible translation between Russian and English. Very simple and convenient.

25. Instagram Girls - a bot for those who are sad or bored. He shows photos of beautiful girls from Instagram.

And also why they die after some time and what is needed to create the simplest telegram bot. About everything in order in our article.

Telegram bots have already become a part of our lives and are capable of performing various automated tasks, such as checking the status of a website, the presence of new comments on social networks, downloading videos from YouTube, and even independently selling goods in an online store. Each of us has most likely used such services at least once. What can I say, even if the government is already using this mechanism to make an appointment with a doctor.

What does this wonderful robot consist of?

And what is needed to create it? Having your own Telegram bot is not just about registering in a special chat @BotFather. And not the usual creation of a new channel or chat. This is a whole chain of settings and mechanisms that interact with each other.

To set up your own bot you will need (in simple words):

  1. Domain first level for a website (on average costs from 100 to 600 rubles per year)
    The first level is the website.
    A second-level domain will not work, or it will still require a separate SSL certificate (the second level is level2..
  2. Certificate SSL is a service package that establishes a verified connection to the site (in the browser we see https instead of http and a shield or padlock sign). Allows you to confirm that the site is owned by a real person or company that meets all the rules and requirements of the network.
    There are free certificates, but Telegram bots often fail them, and installing them on your own is very difficult for the average network user.
    Paid costs from 1900 rubles per year.
  3. Hosting– the place where data is stored, and commands (scripts) sent by the bot are launched. The average price of reliable hosting that supports scripts and a database is 300 rubles per month.

The next stage is writing the code for the bot itself, which is not much different in price from programming and creating your own website. Just don’t confuse this with setting up WordPress or another website builder. In the case of a Telegram bot, it will be necessary to write code and algorithms.

The final minimum cost of a telegram bot is:
300 + 1900 + 3600 = 5800 rubles per year

Without taking into account the price of its production, which can be either 1000 rubles or 100,000. Depending on the complexity of the implementation.

What you should pay attention to

If a company or individual is developing telegram bots, then they still pay these 6,000 rubles a year for technical services. And they can create at least 1000 bots on them. Depends on their workload. Therefore, they quite possibly do not take into account the price of hardware in your order.

It becomes clear why many good bots die. Someone wrote something, more than once, and then simply realized that the projects did not take off, and stopped paying for hosting, and with it for your bot, which was sold earlier.

How to protect yourself from such a situation?
1. Conclude an agreement, possibly with a subscription fee
2. Pay for renting hosting and a domain with a certificate yourself

The second case is the most reliable, although costly. But your bot will always be under your control. And if improvements are needed, you can always hire someone for a one-time job.

+ Another important point

“I want the bot to send comments from Instagram, and also check Direct”
Great! We will do it all for you! - the freelancer answers.

But it doesn’t always mean that in order to read data from Instagram, you also need technical social network accounts, for servicing which you will need an up-to-date library, and also a proxy. And if the actions are complex, then mobile proxies are completely expensive. Which will add about 500 rubles per month to your subscription fee.

Plus, Instagram often blocks such profiles. They need to be re-created and re-configured. Will the developer be ready to fix everything for you inexpensively in a couple of months, having already received a nominal 30,000 rubles for everything?

When planning to create a telegram bot for your purposes, you should always understand that this entails monthly maintenance. And if it interacts with third-party services, there will also be their maintenance and support.

If you decide to get yourself a bot, then make an informed decision. A bot is not a fashionable feature, it is a means of automating your daily routine operations. By understanding the benefits of bot farming, knowing the costs and pitfalls described in this article, you can avoid unnecessary losses and increase your own efficiency.

Last time we looked at a simpler way to create a telegram bot, which did not require programming knowledge because... I used a third-party service and a visual designer. Today I propose to raise the bar and talk about how to write a bot for Telegram in PHP (this is a programming language). If you are not a programmer, then the material below will not be clear to you, so I advise you to read another article. So, let's begin.

Preparing to write a bot

We will access the Telegram API using TelegramBotApi. Accordingly, in order to clone a project from Github we need Composer. Composer is usually not installed without the php.exe file. The easiest way to fix this is to install Open Server.

Cloning a project from Github

Open the command line, use the cd command to go to the folder in which we will install the code and execute the following commands sequentially:

Php -r "copy("https://getcomposer.org/installer", "composer-setup.php");"
php composer-setup.php
php -r "unlink("composer-setup.php");"

Php composer.phar require telegram-bot/api

We go into the folder and make sure that all files are successfully installed.


Now we place these files on our hosting in the folder in which our bot will be located. Now that the preparation is complete, let’s start coding.

Coding Telegram bot in php

In the folder with the bot, we will create a file index.php in which we will write the code of our bot. Important! File encoding - utf-8 without bom!

header("Content-Type: text/html; charset=utf-8");
// connect to the API
require_once("vendor/autoload.php");
// create a bot variable
$token = "token issued by BotFather";
$bot = new \TelegramBot\Api\Client($token);

Once we have created the bot variable $bot, we can access the api, but first we need to register a webhook.

What is a webhook?

WebHook– this is the mechanism by which the bot is connected to telegram. When a user enters a command in Telegram, it must somehow be transmitted to the server and receive a response. This is exactly what Webhook is for. He tells the telegram where to send the commands. Since Telegram DOES NOT KNOW exactly where our bot code is located, we need to fix this.

For this purpose we have a command: $bot->setWebhook

// if the bot is not registered yet, register it
if(!file_exists("registered.trigger"))(
/**
* the registered.trigger file will be created after the bot is registered.
* if this file does not exist, then the bot is not
*registered in Telegram
*/
// URL of the current page
$page_url = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$result = $bot->setWebhook($page_url);
if($result)(
file_put_contents("registered.trigger",time()); // create a file to stop repeated registrations
}
}

Before we continue writing the code, let’s save the index file and run it in the form in which it is now. After launching, another file should appear in the folder with the bot - registered.trigger. If the file appears, it means everything was done correctly and Telegram knows where our bot is.

Mandatory commands for bots

Now we need to teach our bot to respond to the /start and /help commands that are mandatory for all bots.

// required. Running a bot
$bot->
$answer = "Welcome!";
$bot->sendMessage($message->getChat()->getId(), $answer);
});
// help
$bot->command("help", function ($message) use ($bot) (
$answer = "Commands:
/help - help";
$bot->sendMessage($message->getChat()->getId(), $answer);
});
// start processing
$bot->run();

Let's save the index file again and try to test our bot! Hurray, everything is working! Further coding depends on the task you set, and therefore it’s time to talk about how our API library is structured

How the TelegramBotApi library works

Commands are given by the block:

$bot->command("start", function ($message) use ($bot) (
});

All commands must be before calling $bot->run(); , otherwise it won't work. Those. $bot->run(); should close our code.

Sending a message to the TelegramBot API

Sending a message is done with the command:

$bot->sendMessage(id of the user to whom we are sending, message text);

Sending pictures to TelegramBot API

Sending pictures is carried out by sending a Telegram link to this picture. The messenger independently downloads the image and gives it to the user! For example, we will send the user a picture if he enters the /getpic command.
// send the image
$bot->command("getpic", function ($message) use ($bot) (
$pic = "http://binetmed15.beget.tech/wp-content/uploads/forbot.jpg";
$bot->sendPhoto($message->getChat()->getId(), $pic);
});

Sending documents and voice messages

Documents, unlike pictures, must be sent via POST. Fortunately, the TelegramBotApi library will do everything you need without our participation. First, let's upload the document to the folder with our bot (see picture below)

To send a document we use the following code:

// transfer the document
$bot->command("getdoc", function ($message) use ($bot) (
$document = new \CURLFile("sendfrombot.txt");
$bot->sendDocument($message->getChat()->getId(), $document);
});

Please note that the line

$document = new \CURLFile("sendfrombot.txt");

involves placing the sendfrombot txt file in the bot's root folder. However, you can also pass a regular URL to a variable. The situation with the transmission of voice messages (voices) is similar:

// send a voice
$bot->command("getvoice", function ($message) use ($bot) (
$voice = "http://binetmed15.beget.tech/wp-content/uploads/glazunov_maxim-prividenie.mp3";
$bot->sendVoice(
$message->getChat()->getId(),
$voice //,
//$duration,
//$replyToMessageId,
//$replyMarkup,
//$disableNotification
);
});

Receiving messages from chat

To get data from a chat, there is a command in the API .on(). With its help, we can attach a neural network to our Telegram bot to analyze messages or build a simple chat room using the Markov algorithm to send random messages in response to user messages. It might look something like this:

// chatter
$bot->on(function($Update) use ($bot)(
$message = $Update->getMessage();
$mtext = $message->getText();
$cid = $message->getChat()->getId();
if(mb_stripos($mtext,"hello bot") !== false)(
$bot->sendMessage($message->getChat()->getId(), "cheers to you too, dude!");
}
), function($message) use ($name)(
return true; // when this is true - the command passes
});

We inform Botfather of the list of our teams

After the commands are registered, you need to inform Botfather about their presence (strictly speaking, this is not mandatory, but it is still advisable to add it). Open the chat with Botfather and type /setcommands (in case of a typo, use the /setcommands command to override).

Now let's test our telegram bot.

As we can see, everything is ok! Now you know how to create your own bot in php for telegram. Good luck with your development! Next time we will continue to refine our bot and figure out how to add buttons, but for now I recommend downloading the source code of the current lesson.