PHP code example of estaheri / easytel

1. Go to this page and download the library: Download estaheri/easytel 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/ */

    

estaheri / easytel example snippets




use EasyTel\Telegram;
$tg = new Telegram($bot_token,$updates,$botapi_url,$request_method,$guzzle_client_options,$output);
#---------------------------------------------------------------------------------
$bot_token = '123456789:xxxxxxxxxxxxxxxx'; // Telegram bot token (You can get it from @botfather)
$updates = file_get_contents('php://input'); // (Optional) Pure telegram webhook updates you can use any method you want to getting updates
$botapi_url = 'https://api.telegram.org'; // (Optional) Your bot api url https://core.telegram.org/bots/api#using-a-local-bot-api-server (Mostly use telegram official server)
$request_method = 'POST'; // (Optional) Request method of http requests sends to telegram bot api url, Can be POST or GET
$guzzle_client_options = ['verify' => false]; // (Optional) Your custom guzzlehttp client options https://docs.guzzlephp.org/en/stable/request-options.html
$output = Telegram::OUTPUT_ARRAY; // (Optional) Output result of your requests send and received by telegram when using methods

use \EasyTel\Types\ReplyParameters;
# ------------------------- Methods -------------------------
$methods = $tg->methods; // Access to all telegram methods
$methods->sendMessage($chat_id, $text)
    ->parse_mode('markdown')
    ->reply_parameters(ReplyParameters::make($message_id, $chat_id));
# ------------------------- Updates -------------------------
$updates = $tg->updates; // Access to all webhook updates received
// IDE will suggest every property you see here because of full structured properties from their classes
$message = $updates->message;
$chat_id = $message->chat->id;
$message_id = $message->message_id;
$text = $message->text;
$reply_text = $message->reply_to_message->text;



    $updates = file_get_contents('php://input');
    if(!empty($updates)) {
       $tg = new Telegram($bot_token, $updates);
       //...
    } else {
       http_response_code(400);
       echo 'Bad Request!';
    }
    

  $tg = new Telegram($bot_token);
  $tg->webhook->setWebhook('https://example.com/webhook.php');
  

  $tg = new Telegram($bot_token);
  $tg->webhook->setWebhook('https://example.com/webhook.php');
  $result = $tg->methods->getUpdates()->_result();
  if ($result->success && $result->ok) {
     echo "Success";
  } else {
     $error = $result->ok ? $result->response()->description : $result->fail()->error;
     echo "Error: $error";
  }
  
bash
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"