PHPackages                             parsapoorsh/telegrambotphp - 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. parsapoorsh/telegrambotphp

ActiveLibrary

parsapoorsh/telegrambotphp
==========================

A very simple PHP Telegram Bot API

2.6.0(3y ago)312MITPHPPHP &gt;=7.4

Since Jul 20Pushed 1y agoCompare

[ Source](https://github.com/parsapoorsh/TelegramBotPHP)[ Packagist](https://packagist.org/packages/parsapoorsh/telegrambotphp)[ RSS](/packages/parsapoorsh-telegrambotphp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (28)Used By (0)

TelegramBotPHP
==============

[](#telegrambotphp)

[![API](https://camo.githubusercontent.com/c43ae3e304cf88852c0fcfce06fbf82baeda2cc934525c61d186e64038eb988e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54656c656772616d253230426f742532304150492d417072696c25323032312c253230323032332d3336616465312e737667)](https://core.telegram.org/bots/api)[![PHP](https://camo.githubusercontent.com/6c7e8ab59af0decb32b0637fa2ef48a9b15feb2682ccdaa5ce7bf6f8c5059849/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e342d3838393262662e737667)](https://camo.githubusercontent.com/6c7e8ab59af0decb32b0637fa2ef48a9b15feb2682ccdaa5ce7bf6f8c5059849/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e342d3838393262662e737667)[![CURL](https://camo.githubusercontent.com/f5a3b595480ac21ec43e745984c47d97fcc96f430547805750cd31928d67b28f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6355524c2d72657175697265642d677265656e2e737667)](https://camo.githubusercontent.com/f5a3b595480ac21ec43e745984c47d97fcc96f430547805750cd31928d67b28f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6355524c2d72657175697265642d677265656e2e737667)

[![Total Downloads](https://camo.githubusercontent.com/57a9160e3528b8d3f5c27d25103066971558a999106fb0f61946bdfbf306328b/68747470733a2f2f706f7365722e707567782e6f72672f7061727361706f6f7273682f74656c656772616d626f747068702f646f776e6c6f616473)](https://packagist.org/packages/parsapoorsh/telegrambotphp)[![License](https://camo.githubusercontent.com/2a527103c1f24597c3f98b2f2f3e1130851ad8f25abc0ad2fb437cbb3eb590fa/68747470733a2f2f706f7365722e707567782e6f72672f7061727361706f6f7273682f74656c656772616d626f747068702f6c6963656e7365)](https://packagist.org/packages/parsapoorsh/telegrambotphp)[![StyleCI](https://camo.githubusercontent.com/e5293b6d9a780b934cf971d4d92adb4f7b3aaaabc3741274eb3233e7b76d1cad/68747470733a2f2f7374796c6563692e696f2f7265706f732f3633353037393037342f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/635079074)

A very simple PHP [Telegram Bot API](https://core.telegram.org/bots).
Compliant with the April 21, 2023 Telegram Bot API update.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- Curl extension for PHP7 must be enabled.
- Telegram API key, you can get one simply with [@BotFather](https://core.telegram.org/bots#botfather) with simple commands right after creating your bot.

For the WebHook:

- An VALID SSL certificate (Telegram API requires this). You can use [Cloudflare's Free Flexible SSL](https://www.cloudflare.com/ssl) which crypts the web traffic from end user to their proxies if you're using CloudFlare DNS.
    Since the August 29 update you can use a self-signed ssl certificate.

For the getUpdates(Long Polling):

- Some way to execute the script in order to serve messages (for example cronjob)

Download
--------

[](#download)

#### Using Composer

[](#using-composer)

From your project directory, run:

```
composer require parsapoorsh/telegrambotphp

```

or

```
php composer.phar require parsapoorsh/telegrambotphp

```

Note: If you don't have Composer you can download it [HERE](https://getcomposer.org/download/).

#### Using release archives

[](#using-release-archives)

#### Using Git

[](#using-git)

From a project directory, run:

```
git clone https://github.com/parsapoorsh/TelegramBotPHP.git

```

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

[](#installation)

#### Via Composer's autoloader

[](#via-composers-autoloader)

After downloading by using Composer, you can include Composer's autoloader:

```
include (__DIR__ . '/vendor/autoload.php');

$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');
```

#### Via TelegramBotPHP class

[](#via-telegrambotphp-class)

Copy Telegram.php into your server and include it in your new bot script:

```
include 'Telegram.php';

$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');
```

Note: To enable error log file, also copy TelegramErrorLogger.php in the same directory of Telegram.php file.

Configuration (WebHook)
-----------------------

[](#configuration-webhook)

Navigate to [https://api.telegram.org/bot(BOT\_TOKEN)/setWebhook?url=https://yoursite.com/your\_update.php](https://api.telegram.org/bot(BOT_TOKEN)/setWebhook?url=https://yoursite.com/your_update.php)Or use the Telegram class setWebhook method.

Examples
--------

[](#examples)

```
$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');

$chat_id = $telegram->ChatID();
$content = array('chat_id' => $chat_id, 'text' => 'Test');
$telegram->sendMessage($content);
```

If you want to get some specific parameter from the Telegram response:

```
$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');

$result = $telegram->getData();
$text = $result['message'] ['text'];
$chat_id = $result['message'] ['chat']['id'];
$content = array('chat_id' => $chat_id, 'text' => 'Test');
$telegram->sendMessage($content);
```

To upload a Photo or some other files, you need to load it with CurlFile:

```
// Load a local file to upload. If is already on Telegram's Servers just pass the resource id
$img = curl_file_create('test.png','image/png');
$content = array('chat_id' => $chat_id, 'photo' => $img );
$telegram->sendPhoto($content);
```

To download a file on the Telegram's servers

```
$file = $telegram->getFile($file_id);
$telegram->downloadFile($file['result']['file_path'], './my_downloaded_file_on_local_server.png');
```

See update.php or update cowsay.php for the complete example. If you want to see the CowSay Bot in action [add it](https://telegram.me/cowmooobot).

If you want to use getUpdates instead of the WebHook you need to call the `serveUpdate` function inside a for cycle.

```
$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');

$req = $telegram->getUpdates();

for ($i = 0; $i < $telegram-> UpdateCount(); $i++) {
	// You NEED to call serveUpdate before accessing the values of message in Telegram Class
	$telegram->serveUpdate($i);
	$text = $telegram->Text();
	$chat_id = $telegram->ChatID();

	if ($text == '/start') {
		$reply = 'Working';
		$content = array('chat_id' => $chat_id, 'text' => $reply);
		$telegram->sendMessage($content);
	}
	// DO OTHER STUFF
}
```

See getUpdates.php for the complete example.

Functions
---------

[](#functions)

Build keyboards
---------------

[](#build-keyboards)

Telegram's bots can have two different kind of keyboards: Inline and Reply.
The InlineKeyboard is linked to a particular message, while the ReplyKeyboard is linked to the whole chat.
They are both an array of array of buttons, which represent the rows and columns.
For instance, you can arrange a ReplyKeyboard like this: [![ReplyKeyboardExample](https://camo.githubusercontent.com/876574a4ada98e2ab56162e73272c30e7a27d2f0ae02df54ad684244b918cdb1/68747470733a2f2f7069636c6f61642e6f72672f696d6167652f72696c636c6377722f7265706c796b6579626f6172642e706e67)](https://camo.githubusercontent.com/876574a4ada98e2ab56162e73272c30e7a27d2f0ae02df54ad684244b918cdb1/68747470733a2f2f7069636c6f61642e6f72672f696d6167652f72696c636c6377722f7265706c796b6579626f6172642e706e67)using this code:

```
$option = array(
    //First row
    array($telegram->buildKeyboardButton("Button 1"), $telegram->buildKeyboardButton("Button 2")),
    //Second row
    array($telegram->buildKeyboardButton("Button 3"), $telegram->buildKeyboardButton("Button 4"), $telegram->buildKeyboardButton("Button 5")),
    //Third row
    array($telegram->buildKeyboardButton("Button 6")) );
$keyb = $telegram->buildKeyBoard($option, $onetime=false);
$content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "This is a Keyboard Test");
$telegram->sendMessage($content);
```

When a user click on the button, the button text is send back to the bot.
For an InlineKeyboard it's pretty much the same (but you need to provide a valid URL or a Callback data) [![InlineKeyboardExample](https://camo.githubusercontent.com/5fbbda2da27550d942b390c0c86c635b619a5f18824485ff52e7866ff1472b92/68747470733a2f2f7069636c6f61642e6f72672f696d6167652f72696c636c6377612f7265706c796b6579626f617264696e6c696e652e706e67)](https://camo.githubusercontent.com/5fbbda2da27550d942b390c0c86c635b619a5f18824485ff52e7866ff1472b92/68747470733a2f2f7069636c6f61642e6f72672f696d6167652f72696c636c6377612f7265706c796b6579626f617264696e6c696e652e706e67)

```
$option = array(
    //First row
    array($telegram->buildInlineKeyBoardButton("Button 1", $url="http://link1.com"), $telegram->buildInlineKeyBoardButton("Button 2", $url="http://link2.com")),
    //Second row
    array($telegram->buildInlineKeyBoardButton("Button 3", $url="http://link3.com"), $telegram->buildInlineKeyBoardButton("Button 4", $url="http://link4.com"), $telegram->buildInlineKeyBoardButton("Button 5", $url="http://link5.com")),
    //Third row
    array($telegram->buildInlineKeyBoardButton("Button 6", $url="http://link6.com")) );
$keyb = $telegram->buildInlineKeyBoard($option);
$content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "This is a Keyboard Test");
$telegram->sendMessage($content);
```

This is the list of all the helper functions to make keyboards easily:

```
buildKeyBoard(array $options, $onetime=true, $resize=true, $selective=true)
```

Send a custom keyboard. $option is an array of array KeyboardButton.
Check [ReplyKeyBoardMarkUp](https://core.telegram.org/bots/api#replykeyboardmarkup) for more info.

```
buildInlineKeyBoard(array $inline_keyboard)
```

Send a custom keyboard. $inline\_keyboard is an array of array InlineKeyboardButton.
Check [InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) for more info.

```
buildInlineKeyBoardButton($text, $url, $callback_data, $switch_inline_query)
```

Create an InlineKeyboardButton.
Check [InlineKeyBoardButton](https://core.telegram.org/bots/api#inlinekeyboardbutton) for more info.

```
buildKeyBoardButton($text, $url, $request_contact, $request_location)
```

Create a KeyboardButton.
Check [KeyBoardButton](https://core.telegram.org/bots/api#keyboardbutton) for more info.

```
buildKeyBoardHide($selective=true)
```

Hide a custom keyboard.
Check [ReplyKeyBoarHide](https://core.telegram.org/bots/api#replykeyboardhide) for more info.

```
buildForceReply($selective=true)
```

Show a Reply interface to the user.
Check [ForceReply](https://core.telegram.org/bots/api#forcereply) for more info.

Emoticons
---------

[](#emoticons)

For a list of emoticons to use in your bot messages, please refer to the column Bytes of this table:

License
-------

[](#license)

This open-source software is distributed under the MIT License. See LICENSE.md

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

[](#contributing)

All kinds of contributions are welcome - code, tests, documentation, bug reports, new features, etc...

- Send feedbacks.
- Submit bug reports.
- Write/Edit the documents.
- Fix bugs or add new features.

About fork
----------

[](#about-fork)

This repo is based on [Eleirbag89/TelegramBotPHP](https://github.com/Eleirbag89/TelegramBotPHP/). I forked it because the main repo hadn't been updated for 10 months while Telegram Bot API had 8 updates during that time.

Contact me
----------

[](#contact-me)

You can contact me [via Telegram](https://telegram.me/pparsa) but if you have an issue please [open](https://github.com/parsapoorsh/TelegramBotPHP/issues) one.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 70.5% 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

Every ~84 days

Recently: every ~0 days

Total

26

Last Release

1100d ago

Major Versions

1.4.4 → 2.0.02023-05-02

PHP version history (2 changes)1.3.2PHP &gt;=5.0

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a5026c0f9d6ed69f539c18abb2ec8710731ac1150242f991fbb5a995f404ac5?d=identicon)[parsapoorsh](/maintainers/parsapoorsh)

---

Top Contributors

[![Eleirbag89](https://avatars.githubusercontent.com/u/10547598?v=4)](https://github.com/Eleirbag89 "Eleirbag89 (261 commits)")[![parsapoorsh](https://avatars.githubusercontent.com/u/59599626?v=4)](https://github.com/parsapoorsh "parsapoorsh (27 commits)")[![abbas980301](https://avatars.githubusercontent.com/u/17107543?v=4)](https://github.com/abbas980301 "abbas980301 (25 commits)")[![lyucean](https://avatars.githubusercontent.com/u/955310?v=4)](https://github.com/lyucean "lyucean (8 commits)")[![siamakdals](https://avatars.githubusercontent.com/u/65611369?v=4)](https://github.com/siamakdals "siamakdals (7 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (6 commits)")[![Mohsen322](https://avatars.githubusercontent.com/u/25117421?v=4)](https://github.com/Mohsen322 "Mohsen322 (5 commits)")[![hijera](https://avatars.githubusercontent.com/u/1131462?v=4)](https://github.com/hijera "hijera (5 commits)")[![blopa](https://avatars.githubusercontent.com/u/3838114?v=4)](https://github.com/blopa "blopa (3 commits)")[![ynvv](https://avatars.githubusercontent.com/u/7413262?v=4)](https://github.com/ynvv "ynvv (3 commits)")[![caco3](https://avatars.githubusercontent.com/u/1783586?v=4)](https://github.com/caco3 "caco3 (3 commits)")[![zeyudada](https://avatars.githubusercontent.com/u/64437653?v=4)](https://github.com/zeyudada "zeyudada (2 commits)")[![happy-code-com](https://avatars.githubusercontent.com/u/2848403?v=4)](https://github.com/happy-code-com "happy-code-com (2 commits)")[![ivmaks](https://avatars.githubusercontent.com/u/13006295?v=4)](https://github.com/ivmaks "ivmaks (2 commits)")[![moeinporkamel](https://avatars.githubusercontent.com/u/202500882?v=4)](https://github.com/moeinporkamel "moeinporkamel (2 commits)")[![oraziocontarino](https://avatars.githubusercontent.com/u/18686793?v=4)](https://github.com/oraziocontarino "oraziocontarino (2 commits)")[![xpyctum](https://avatars.githubusercontent.com/u/6584811?v=4)](https://github.com/xpyctum "xpyctum (2 commits)")[![Yousha](https://avatars.githubusercontent.com/u/18091267?v=4)](https://github.com/Yousha "Yousha (2 commits)")[![hossein142001](https://avatars.githubusercontent.com/u/4927133?v=4)](https://github.com/hossein142001 "hossein142001 (1 commits)")[![sibche2013](https://avatars.githubusercontent.com/u/12953313?v=4)](https://github.com/sibche2013 "sibche2013 (1 commits)")

---

Tags

botcomposer-packagetelegramtelegram-bottelegram-bot-php

### Embed Badge

![Health badge](/badges/parsapoorsh-telegrambotphp/health.svg)

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

PHPackages © 2026

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