L
L
Lici2017-07-21 20:05:09
Messengers
Lici, 2017-07-21 20:05:09

Notifications from WordPress to Telegram Bot?

It is necessary that applications come not as usual to the mail, but to the Telegram bot in WordPress. Technically, you just need to refer to the URL with the parameters to do so. I did it according to this instruction, the script sends everything perfectly, now you just need to somehow stick it into contact forms 7 so that everything does not break during the update.

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 t.me/userinfobot bot.
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 bot in Telegram, for this you need to press /start). The link looks like this: https://api.telegram.org/bot[Bot Token]/sendMessage?chat_id=[Your ID]&text=[Text]
Then you need to set up your form handler. It's up to you, 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. Yet again,
$msg = "New request on the site! \nE-mail: $email \nPhone: $phone \n Name:
$name";
Then you need to send this data to telegram. There are many ways to do this, the easiest one is:
$token = *Insert your bot's token here*;
$telegram_admin_id = *Here is your ID taken from userinfobot*;
$msg = "New request on the site! \nE-mail: $email \nPhone: $phone \n
Name: $name";
file_get_contents( https://api.telegram.org/bot '. $token .'/sendMessage?
chat_id='. $telegram_admin_id .'&text=' . urlencode($msg));

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Denis Yudin, 2017-07-29
@denisday

CF7 has the ability to programmatically intercept all messages from forms and do whatever you want with them.
add_action( 'wpcf7_before_send_mail', 'wpcf7_handle_forms_data' );
I use this feature to write all the data sent from all forms to the CRM module in WP. Nothing complicated, if you need help - welcome!

D
Denis Yanchevsky, 2017-07-21
@deniscopro

I didn’t go into details, but on one site I met that applications with CF7 were sent to telegrams using the Telegram for WP plugin . Perhaps useful.

A
abubekovdd, 2018-11-21
@abubekovdd

You can also buy for such a thing https://coderun.ru/product/woocommerce-uvedomleniy...
PS. Later I noticed that the question is old, but still relevant for someone else

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question