title: Telegram Bot sending a message without needing a ,message to trigger it
body: <p>I am trying to let a Telegram bot send a message to a group without the need of a message by a user to trigger it. To be more specific i am trying to set up a birthday reminder where the bot querys a database, compares entries to the current date and broadcaststs a "Happy birthday" message in the group. As said i would like to do it via a cronjob that opens up the PHP script everyday and lets the bot broadcast it.</p>
  
  <p>My problem is I checked all of Telegrams documentations and demo codes (<a href="https://core.telegram.org/bots/samples" rel="nofollow">https://core.telegram.org/bots/samples</a>) but all of it are based on a User triggering the bot by sending a message.</p>
  
  <p>My question is, if anyone was already able to implement a similar functionality and could aid me in extending my code? What might be worth mentioning is that the Bot is already integrated into the Group Chat and i have the chat id that would be needed for the bot to target the chat.
  My code is as follows (i have to admit i copied it over from the demo examples):</p>
  
  <pre><code>&lt;?php
  
  define('BOT_TOKEN', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
  define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
  
  function apiRequestWebhook($method, $parameters) {
    if (!is_string($method)) {
      error_log("Method name must be a string\n");
      return false;
    }
  
    if (!$parameters) {
      $parameters = array();
    } else if (!is_array($parameters)) {
      error_log("Parameters must be an array\n");
      return false;
    }
  
    $parameters["method"] = $method;
  
    header("Content-Type: application/json");
    echo json_encode($parameters);
    return true;
  }
  
  function exec_curl_request($handle) {
    $response = curl_exec($handle);
  
    if ($response === false) {
      $errno = curl_errno($handle);
      $error = curl_error($handle);
      error_log("Curl returned error $errno: $error\n");
      curl_close($handle);
      return false;
    }
  
    $http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
    curl_close($handle);
  
    if ($http_code &gt;= 500) {
      // do not wat to DDOS server if something goes wrong
      sleep(10);
      return false;
    } else if ($http_code != 200) {
      $response = json_decode($response, true);
      error_log("Request has failed with error {$response['error_code']}: {$response['description']}\n");
      if ($http_code == 401) {
        throw new Exception('Invalid access token provided');
      }
      return false;
    } else {
      $response = json_decode($response, true);
      if (isset($response['description'])) {
        error_log("Request was successfull: {$response['description']}\n");
      }
      $response = $response['result'];
    }
  
    return $response;
  }
  
  function apiRequest($method, $parameters) {
    if (!is_string($method)) {
      error_log("Method name must be a string\n");
      return false;
    }
  
    if (!$parameters) {
      $parameters = array();
    } else if (!is_array($parameters)) {
      error_log("Parameters must be an array\n");
      return false;
    }
  
    foreach ($parameters as $key =&gt; &amp;$val) {
      // encoding to JSON array parameters, for example reply_markup
      if (!is_numeric($val) &amp;&amp; !is_string($val)) {
        $val = json_encode($val);
      }
    }
    $url = API_URL.$method.'?'.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);
  
    return exec_curl_request($handle);
  }
  
  function apiRequestJson($method, $parameters) {
    if (!is_string($method)) {
      error_log("Method name must be a string\n");
      return false;
    }
  
    if (!$parameters) {
      $parameters = array();
    } else if (!is_array($parameters)) {
      error_log("Parameters must be an array\n");
      return false;
    }
  
    $parameters["method"] = $method;
  
    $handle = curl_init(API_URL);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($handle, CURLOPT_TIMEOUT, 60);
    curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
    curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
  
    return exec_curl_request($handle);
  }
  
  function processMessage($message) {
    // process incoming message
    $message_id = $message['message_id'];
    $chat_id = $message['chat']['id'];
    if (isset($message['text'])) {
    apiRequest("sendChatAction", array('chat_id' =&gt; $chat_id, "action" =&gt; "typing"));
      // incoming text message
      $text = $message['text'];
  
      //Command for intializing the backend code for the birthday check (just to check its functionality but would prefer the code to run without a command)
      if (strpos($text, "/geburtstagscheck") === 0) {
        include 'skripte/start.php';
          } 
  }}
  
  
  
  
  
  define('WEBHOOK_URL', 'XXXXXXXXXXXXXX');
  
  if (php_sapi_name() == 'cli') {
    // if run from console, set or delete webhook
    apiRequest('setWebhook', array('url' =&gt; isset($argv[1]) &amp;&amp; $argv[1] == 'delete' ? '' : WEBHOOK_URL));
    exit;
  }
  
  
  $content = file_get_contents("php://input");
  $update = json_decode($content, true);
  
  if (!$update) {
    // receive wrong update, must not happen
    exit;
  }
  
  if (isset($update["message"])) {
    processMessage($update["message"]);
  } ?&gt;
  </code></pre>