PHPackages                             sh20raj/phpgram - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. sh20raj/phpgram

ActiveLibrary[API Development](/categories/api)

sh20raj/phpgram
===============

A PHP library for interacting with the Telegram Bot API.

v1(1y ago)5201MITPHPPHP &gt;=7.0

Since Jul 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SH20RAJ/phpgram)[ Packagist](https://packagist.org/packages/sh20raj/phpgram)[ Docs](https://github.com/SH20RAJ/phpgram)[ RSS](/packages/sh20raj-phpgram/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PhpGram
=======

[](#phpgram)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/SH20RAJ/phpgram/blob/main/LICENSE)[![PHP](https://camo.githubusercontent.com/2537678d7ce70a6411558a76d2639bc45f61cfbb2d492590a27b9404e68dbf69/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344253230372e302d3838393242462e737667)](https://www.php.net/)[![Telegram Bot API](https://camo.githubusercontent.com/1fb2d84cf8f9a9c43492041a3567d232eba11541d75966f168d8701ecc71de4d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54656c656772616d253230426f742532304150492d253345253344253230352e302d3030383863632e737667)](https://core.telegram.org/bots/api)[![Visitors](https://camo.githubusercontent.com/e7d402debfedf3eae67d0ef6d63147b27ca41375034ac53af804ee33baa7af63/68747470733a2f2f6170692e76697369746f7262616467652e696f2f6170692f76697369746f72733f706174683d68747470732533412532462532466769746875622e636f6d2532465348323052414a2532467068706772616d266c6162656c436f6c6f723d25323332636363653426636f756e74436f6c6f723d253233663437333733267374796c653d666c61742d737175617265)](https://visitorbadge.io/status?path=https%3A%2F%2Fgithub.com%2FSH20RAJ%2Fphpgram)[![Latest Stable Version](https://camo.githubusercontent.com/1ba5f18964cf72a480a5beb7d5bb6a59b0939a782b2538c589f4cc3adad61e42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7368323072616a2f7068706772616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sh20raj/phpgram)

PhpGram is a PHP library for interacting with the Telegram Bot API, providing easy-to-use methods for sending messages, media, managing chats, stickers, inline queries, payments, and more.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Initialization](#initialization)
    - [Basic Usage](#basic-usage)
    - [Sending Messages and Media](#sending-messages-and-media)
    - [Managing Chats and Members](#managing-chats-and-members)
    - [Handling Stickers](#handling-stickers)
    - [Inline Mode](#inline-mode)
    - [Payments](#payments)
    - [Games](#games)
    - [Handling Updates](#handling-updates)
- [Contributing](#contributing)
- [License](#license)

Installation
------------

[](#installation)

Install PhpGram via [Composer](https://packagist.org/packages/sh20raj/phpgram):

```
composer require sh20raj/phpgram
```

Alternatively, you can clone the repository:

```
git clone https://github.com/SH20RAJ/phpgram.git
```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

First, include the library in your PHP file and initialize `PhpGram` with your bot token:

```
require __DIR__ . '/../src/PhpGram.php';

use PhpGram\PhpGram;

$token = 'YOUR_BOT_TOKEN';
$bot = new PhpGram($token);
```

### Basic Usage

[](#basic-usage)

> Try Example: [Toss Bot](./examples/tossbot.php) (Toss a coin and get the result or roll a dice)

```
// Example: Get bot information
$botInfo = $bot->getMe();
echo 'Bot Username: ' . $botInfo['result']['username'] . PHP_EOL;
```

### Sending Messages and Media

[](#sending-messages-and-media)

#### Sending Text Messages

[](#sending-text-messages)

```
// Send a text message
$chatId = 'YOUR_CHAT_ID';
$message = 'Hello from PhpGram!';
$response = $bot->sendMessage($chatId, $message);
```

#### Sending Photos

[](#sending-photos)

```
// Send a photo
$photoPath = 'path/to/photo.jpg';
$response = $bot->sendPhoto($chatId, $photoPath, ['caption' => 'Check out this photo!']);
```

#### Sending Audio

[](#sending-audio)

```
// Send an audio file
$audioPath = 'path/to/audio.mp3';
$response = $bot->sendAudio($chatId, $audioPath, ['caption' => 'Listen to this audio!']);
```

#### Sending Documents

[](#sending-documents)

```
// Send a document
$documentPath = 'path/to/document.pdf';
$response = $bot->sendDocument($chatId, $documentPath, ['caption' => 'Here is your document.']);
```

#### Sending Videos

[](#sending-videos)

```
// Send a video
$videoPath = 'path/to/video.mp4';
$response = $bot->sendVideo($chatId, $videoPath, ['caption' => 'Watch this video!']);
```

#### Sending Animations

[](#sending-animations)

```
// Send an animation
$animationPath = 'path/to/animation.gif';
$response = $bot->sendAnimation($chatId, $animationPath, ['caption' => 'Enjoy this animation!']);
```

#### Sending Voice Messages

[](#sending-voice-messages)

```
// Send a voice message
$voicePath = 'path/to/voice.ogg';
$response = $bot->sendVoice($chatId, $voicePath, ['caption' => 'Listen to this voice message!']);
```

#### Sending Video Notes

[](#sending-video-notes)

```
// Send a video note
$videoNotePath = 'path/to/video_note.mp4';
$response = $bot->sendVideoNote($chatId, $videoNotePath);
```

#### Sending Media Groups

[](#sending-media-groups)

```
// Send a media group
$mediaGroup = [
    ['type' => 'photo', 'media' => 'path/to/photo1.jpg'],
    ['type' => 'photo', 'media' => 'path/to/photo2.jpg'],
];
$response = $bot->sendMediaGroup($chatId, $mediaGroup);
```

#### Sending Locations

[](#sending-locations)

```
// Send a location
$response = $bot->sendLocation($chatId, 40.712776, -74.005974); // New York City coordinates
```

#### Sending Venues

[](#sending-venues)

```
// Send a venue
$response = $bot->sendVenue($chatId, 40.712776, -74.005974, 'Venue Name', 'Venue Address');
```

#### Sending Contacts

[](#sending-contacts)

```
// Send a contact
$response = $bot->sendContact($chatId, 'PHONE_NUMBER', 'FirstName', ['last_name' => 'LastName']);
```

#### Sending Polls

[](#sending-polls)

```
// Send a poll
$response = $bot->sendPoll($chatId, 'Your Question?', ['Option 1', 'Option 2']);
```

#### Sending Dice

[](#sending-dice)

```
// Send a dice
$response = $bot->sendDice($chatId);
```

### Managing Chats and Members

[](#managing-chats-and-members)

```
// Kick a member from a chat
$userId = 'USER_ID_TO_KICK';
$response = $bot->kickChatMember($chatId, $userId);

// Unban a member from a chat
$response = $bot->unbanChatMember($chatId, $userId);

// Restrict a member in a chat
$permissions = ['can_send_messages' => false];
$response = $bot->restrictChatMember($chatId, $userId, $permissions);

// Promote a member to an admin
$response = $bot->promoteChatMember($chatId, $userId);

// Set custom title for an admin
$response = $bot->setChatAdministratorCustomTitle($chatId, $userId, 'Custom Title');
```

### Handling Stickers

[](#handling-stickers)

```
// Send a sticker
$stickerPath = 'path/to/sticker.webp';
$response = $bot->sendSticker($chatId, $stickerPath);

// Get a sticker set
$stickerSetName = 'sticker_set_name';
$response = $bot->getStickerSet($stickerSetName);

// Upload a sticker file
$stickerFilePath = 'path/to/sticker.png';
$response = $bot->uploadStickerFile($userId, $stickerFilePath);

// Create a new sticker set
$stickerParams = [
    'name' => 'sticker_set_name',
    'title' => 'Sticker Set Title',
    'png_sticker' => 'path/to/sticker.png',
    'emojis' => '😀',
];
$response = $bot->createNewStickerSet($userId, $stickerParams);

// Add a sticker to a set
$response = $bot->addStickerToSet($userId, 'sticker_set_name', 'path/to/sticker.png', '😀');

// Set sticker position in a set
$response = $bot->setStickerPositionInSet('sticker_file_id', 0);

// Delete a sticker from a set
$response = $bot->deleteStickerFromSet('sticker_file_id');
```

### Inline Mode

[](#inline-mode)

```
// Answer an inline query
$inlineQueryId = 'INLINE_QUERY_ID';
$results = [ /* Array of InlineQueryResult objects */ ];
$response = $bot->answerInlineQuery($inlineQueryId, $results);
```

### Payments

[](#payments)

```
// Send an invoice
$invoiceParams = [
    'title' => 'Product Name',
    'description' => 'Description of the product',
    'payload' => 'unique_payload',
    'provider_token' => 'PROVIDER_PAYMENT_TOKEN',
    'start_parameter' => 'start_param',
    'currency' => 'USD',
    'prices' => json_encode([ ['label' => 'Product Price', 'amount' => 1000] ]),
];
$response = $bot->sendInvoice($chatId, $invoiceParams);

// Answer a shipping query
$shippingQueryId = 'SHIPPING_QUERY_ID';
$response = $bot->answerShippingQuery($shippingQueryId, true);

// Answer a pre-checkout query
$preCheckoutQueryId = 'PRE_CHECKOUT_QUERY_ID';
$response = $bot->answerPreCheckoutQuery($preCheckoutQueryId, true);
```

### Games

[](#games)

```
// Send a game
$gameShortName = 'game_short_name';
$response = $bot->sendGame($chatId, $gameShortName);

// Set game score
$response = $bot->setGameScore($userId, 100);

// Get game high scores
$response = $bot->getGameHighScores($userId);
```

### Handling Updates

[](#handling-updates)

```
// Get updates
$updates = $bot->getUpdates();

// Set a webhook
$response = $bot->setWebhook('https://yourdomain.com/webhook');

// Delete a webhook
$response = $bot->deleteWebhook();

// Get webhook info
$response = $bot->getWebhookInfo();
```

Contributing
------------

[](#contributing)

Contributions are welcome! Fork the repository, make your changes, and submit a pull request.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](https://github.com/SH20RAJ/phpgram/blob/main/LICENSE) file for details.

---

### Important Links

[](#important-links)

>

>

> Video Documentation :-

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

668d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0555228e45586a9e63253bcdcd33f019c3c4268a81c3b2fa6126efce551438f8?d=identicon)[sh20raj](/maintainers/sh20raj)

---

Top Contributors

[![SH20RAJ](https://avatars.githubusercontent.com/u/66713844?v=4)](https://github.com/SH20RAJ "SH20RAJ (10 commits)")

---

Tags

phppitelegramtelegram-bottelegram-bot-apiphpapibottelegram

### Embed Badge

![Health badge](/badges/sh20raj-phpgram/health.svg)

```
[![Health](https://phpackages.com/badges/sh20raj-phpgram/health.svg)](https://phpackages.com/packages/sh20raj-phpgram)
```

###  Alternatives

[borsaco/telegram-bot-api-bundle

A simple wrapper for telegram-bot-api.

5633.0k](/packages/borsaco-telegram-bot-api-bundle)[klev-o/telegram-bot-api

Simple and convenient object-oriented implementation Telegram bot API with php version ^7.4 support. You'll like it)

457.8k1](/packages/klev-o-telegram-bot-api)[klev-o/crypto-pay-api

Simple and convenient implementation of the Crypto Pay payment system (@CryptoBot)

205.1k](/packages/klev-o-crypto-pay-api)[kuvardin/telegram-bots-api

SDK for Telegram bots API

145.5k](/packages/kuvardin-telegram-bots-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
