PHP code example of alikm6 / php-telegram-bot

1. Go to this page and download the library: Download alikm6/php-telegram-bot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alikm6 / php-telegram-bot example snippets


$tg = new TelegramBot\Telegram('your-bot-token');

$update = $tg->parseUpdate();

TelegramBot\Telegram::limit_access_to_telegram_only();

$m = $tg->sendMessage([
      'chat_id' => 1233456,
      'text' => "Hello World"
]);

$options = [
    'send_error' => true,  // If set to true, errors will be sent to the specified chat ID as a Telegram message.
    'run_in_background' => false,  // If set to true, requests will be processed in the background and responses will not be returned to the caller.
    'return' => 'result_array',  // The type of result to return from API requests.
];

$ms = $tg->sendMessage([
     [
          'chat_id' => 1233456,
          'text' => "Message 1"
     ],  [
          'chat_id' => 654321,
          'text' => "Message 2"
     ]
]);