Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teh9/apigram
🤖 APIGram - simple PHP SDK for Telegram API
https://github.com/teh9/apigram
api bot client composer guzzle guzzlehttp integration legacy library php sdk telegram telegram-api telegram-bot telegram-bot-api
Last synced: 30 days ago
JSON representation
🤖 APIGram - simple PHP SDK for Telegram API
- Host: GitHub
- URL: https://github.com/teh9/apigram
- Owner: teh9
- License: mit
- Created: 2024-01-22T18:38:57.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-20T07:59:40.000Z (11 months ago)
- Last Synced: 2024-12-16T16:44:15.610Z (about 1 month ago)
- Topics: api, bot, client, composer, guzzle, guzzlehttp, integration, legacy, library, php, sdk, telegram, telegram-api, telegram-bot, telegram-bot-api
- Language: PHP
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://img.shields.io/packagist/dt/teh9/apigram)
![Version](https://img.shields.io/github/v/release/teh9/apigram)
![Build](https://github.com/teh9/apigram/actions/workflows/php.yml/badge.svg)## 1. Prerequisites
- PHP >= 7.2.5## 2. Installation
```
composer require teh9/apigram
```## 3. Initialization
```php
$client = \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
```1. Messages
##### Send message:```php
$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:```php
$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:
```php
$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:
```php
$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):
```php
$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:
```php
$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.