Question:
There is a site created without the use of engines. I want to attach a feedback form so that the visitor leaves his number and name in a special form, and this data is then transferred to the manager in Telegram. Can you explain in detail how this is done?
Answer:
- You create a new bot in Telegram, write here: t.me/botFather first /start, then /newbot.
- Find out your Telegram account ID. You can do this by writing to the bot t.me/userinfobot
- You create a link to the Telegram API to send a message to a chat with you (you first need to start a chat with your Telegram bot, for this you need to press /start). The link looks like this:
https://api.telegram.org/bot[Токен бота]/sendMessage?chat_id=[Твой ID]&text=[Текст]
-
Then you need to set up your form handler. It’s already on your part, we just take the data, for example:
$phone = $_POST['phone']; $email = $_POST['email']; $firstname = $_POST['firstname'];
-
Then we generate the message that we want to send to Telegram. Again, for example:
$msg = "Новая заявка на сайте! \nE-mail: $email \nТелефон: $phone \n Имя: $name";
-
Then you need to send this data to telegram. There are many ways to do this, the easiest one is:
$token = *Вставь сюда токен своего бота*; $telegram_admin_id = *Сюда твой ID, взятый из userinfobot*; $msg = "Новая заявка на сайте! \nE-mail: $email \nТелефон: $phone \n Имя: $name"; file_get_contents(https://api.telegram.org/bot'. $token .'/sendMessage? chat_id='. $telegram_admin_id .'&text=' . urlencode($msg));