Skip to content
/ apigram Public

🤖 APIGram - simple PHP SDK for Telegram API

License

Notifications You must be signed in to change notification settings

teh9/apigram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APIGram Simple PHP Telegram API SDK

A lightweight and simple library for working with the Telegram Bot API, is under active development. But some methods are already available for work, see paragraph 3.

Downloads Version Build

1. Prerequisites

  • PHP >= 7.2.5

2. Installation

composer require teh9/apigram

3. Initialization

$client = \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
1. Messages
Send message:
$chatId = 1;

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

$response->getMessageId(); // Get message id
Edit message:
$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
2. Webhook
Set webhook:
$webhookUrl = 'https://yourwebhook.net';

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

var_dump($response->status()); // true/false
Remove webhook:
$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->webhook()->remove();

var_dump($response->status()); // true/false
3. Bot
Get me (info about bot):
$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
4. Assets
Send photo:
$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());

License

The MIT License (MIT). Please see License File for more information.