PHP code example of teh9 / apigram

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

    

teh9 / apigram example snippets

 
$client = \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');

$chatId = 1;

$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->messages()->to($chatId)->send('text');

$response->getMessageId(); // Get message id


$chatId = 1;
$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->messages()->edit('TELEGRAM_CHAT_ID', 'MESSAGE_ID', 'lorem ipsum new text');

var_dump($response->getMessageText()); // lorem ipsum new text


$webhookUrl = 'https://yourwebhook.net';

$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->webhook()->set($webhookUrl);

var_dump($response->status()); // true/false

$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->webhook()->remove();

var_dump($response->status()); // true/false

$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->bot()->getMe();

var_dump($response->getId()); // Bot id
var_dump($response->getFirstName()); // Bot name
var_dump($response->getUserName()); // Bot login

$imagePath = 'https://i.imgur.com/SVm9n13_d.jpg';

$apigram = new TelegramClient(getenv('TELEGRAM_BOT_TOKEN'));
$response = $apigram->assets()->to(getenv('TELEGRAM_CHAT_ID'))->sendPhoto($imagePath);
// or
$response = $apigram->assets()->to(getenv('TELEGRAM_CHAT_ID'))->caption('test caption')->sendPhoto($imagePath);


var_dump($response->status());
var_dump($response->getMessageId());