V
V
vedrok2022-02-24 15:14:29
PHP
vedrok, 2022-02-24 15:14:29

Will this script work as it should?

Will this script work in such a way that it sends a message to the telegram chat with the bot and notifies about the entrance to the site / transition to the link? And if so, how to connect it to the site so that it functions?

$BOT_TOOKEN = '-------------token from bot father ------------';
$to =  тид получателя;
$message = 'that you need ';
$parameters = array('chat_id' => $to, 'parse_mode' => 'HTML', "text" => $message);
$url = "https://api.telegram.org/bot" . trim($BOT_TOOKEN) . '/sendMessage?' . http_build_query($parameters);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
$response = curl_exec($handle);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2022-02-24
@vabka

will this script work so that it sends a message to a telegram chat with a bot

Well, check it out. What bad can happen if you run this code?
At least I don't see you exposing the http method, which seems to be mandatory.
And if so, how to connect it to the site so that it would function

You wrap this code of yours in a function and use it in those places on the site where the "entry to the site / transition to the link" occurs
PS

В чём кайф использовать curl вместо объектно-ориентированных http-клиентов, типа того же guzzle?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question