PHP code example of yabx / telegram

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

    

yabx / telegram example snippets


use Yabx\Telegram\BotApi;

// Create an BotApi client instance
$tg = new BotApi('123:qwe');

// Sending message
$message = $tg->sendMessage(12345, 'Hello World!');

use Yabx\Telegram\BotApi;

// Create an BotApi client instance
$tg = new BotApi('123:qwe');

// Set webhook
$tg->setWebhook('https://tg.myservice.com/bot123');

// Get webhook info
$webhook = $tg->getWebhookInfo();

use Yabx\Telegram\BotApi;

// Parse telegram webhook
$update = BotApi::getUpdateFromRequest();
// or
$update = BotApi::getUpdateFromJson($json);

// Get Message object
$message = $update->getMessage();

// Get Sender and Chat objects
$sender = $message->getFrom();
$chat = $message->getChat();

// Get some message attributes
$text = $message->getText();
$video = $message->getVideo();
$photos = $message->getPhotos();
$document = $message->getDocument();