The scenario is as follows, I want to send messages or notifications (without commands sent by users) every minute on a Telegram channel.
It happens that I can send the messages every time I enter the URL and the message is sent, but I want it to be sent automatically (without entering the URL) every minute. I do not know how to do that, thanks in advance.
<?php $botToken="<<BOT-TOKEN>>" ; $website="https://api.telegram.org/bot" .$botToken; $chatId="337957895" ; //**===>
NOTE: this chatId MUST be the chat_id of a person, NOT another bot chatId !!!** $params=[ ‘chat_id’=>$chatId, ‘text’=>’This is my message !!!’, ]; $ch = curl_init($website . ‘/sendMessage’); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, ($params)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); ?>
I have to enter the URL still for the message to be sent …
https://bot.unpixelmas.com/bot.php
2
Answers
If the URL is always the same, you should use cronjob and set it to open that URL every minute.
If we say that the URL you want to enter is
<YOUR CUSTOM URL>
, then you can make a PHP file and use the following code:Then using
crontab -e
command you can open cronjob file and add your PHP file as record: