This PHP library provides a convenient and easy-to-use interface for interacting with the Telegram BOT API. It is designed to be used with the Bitrix CMS or the GuzzleHTTP client.
- Easy Integration: Seamlessly integrates with Bitrix CMS and GuzzleHTTP client.
- Full API Coverage: Supports all Telegram BOT API 8.2 methods.
- Customizable: Easily extendable and customizable to fit your specific needs.
You can install the package via Composer:
composer require devbx/telegram
use DevBX\Telegram;
$client = new Telegram\BitrixClient([
'token' => '1234567890:zzz',
'client_options' => [ // Bitrix client options
'disableSslVerification' => false
]
]);
$result = $client->sendPhoto([
'chat_id' => 1234567890,
'photo' => [
'filename' => 'media.jpg',
'resource' => fopen('media.jpg', 'r+'),
'contentType' => 'image/jpeg',
],
]);
echo $result->messageId."\n";
foreach ($result->photo as $photo) {
echo "File ID - {$photo->fileId}\nWidth - {$photo->width}\nHeight - {$photo->height}\nFile size - {$photo->fileSize}\n\n";
}
use DevBX\Telegram;
$client = new \DevBX\Telegram\GuzzleClient([
'token' => '1234567890:zzz',
'client_options' => [ // Guzzle client options
'verify' => false
]
]);
$result = $client->sendPhoto([
'chat_id' => 1234567890,
'photo' => [
'filename' => 'media.jpg',
'resource' => fopen('media.jpg', 'r+'),
'contentType' => 'image/jpeg',
],
]);
echo $result->messageId."\n";
foreach ($result->photo as $photo) {
echo "File ID - {$photo->fileId}\nWidth - {$photo->width}\nHeight - {$photo->height}\nFile size - {$photo->fileSize}\n\n";
}
use DevBX\Telegram;
$client = new Telegram\BitrixClient([
'token' => '1234567890:zzz',
'api_url' => 'http://localhost:8081/bot'
]);
$client->sendMessage([
'chat_id' => '1234567890',
'text' => 'message from Local Bot API Server'
]);
use DevBX\Telegram;
$client = new Telegram\GuzzleClient([
'token' => '1234567890:zzz',
'api_url' => 'http://localhost:8081/bot'
]);
$client->sendMessage([
'chat_id' => '1234567890',
'text' => 'message from Local Bot API Server'
]);
use DevBX\Telegram;
$result = Telegram\Api::getWebhookUpdate();
foreach ($result as $updateType => $update) {
if (!is_object($update))
continue;
switch ($updateType)
{
case 'message':
/* @var Telegram\Types\Message $update */
echo "Message from: {$update->from->id}\nText: {$update->text}\n";
break;
}
}