skip to Main Content

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


  1. If the URL is always the same, you should use cronjob and set it to open that URL every minute.

    Login or Signup to reply.
  2. 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:

    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => '<YOUR CUSTOM URL>',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    
    ?>
    

    Then using crontab -e command you can open cronjob file and add your PHP file as record:

    * * * * *  <PHP bin path> <your PHP source file path>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search