PHPackages                             shakibonline/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. [API Development](/categories/api)
4. /
5. shakibonline/telegrambotphp

ActiveLibrary[API Development](/categories/api)

shakibonline/telegrambotphp
===========================

A very simple PHP Telegram Bot API

v0.1.0(9y ago)029MITPHPPHP &gt;=5.0

Since May 18Pushed 9y ago1 watchersCompare

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

READMEChangelog (3)DependenciesVersions (4)Used By (0)

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

[](#telegrambotphp)

[![API](https://camo.githubusercontent.com/897b2b11e8bb7140d077bc5c7c6430e2c91f52ab293a77d9762433fcee90f482/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54656c656772616d253230426f742532304150492d4d61792532303138253243253230323031372d3336616465312e737667)](https://core.telegram.org/bots/api)[![PHP](https://camo.githubusercontent.com/7001dc230291c2a963ca66407574a82f5dfef7c1a7ab0b0356a4f4818a2ca106/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344352e332d3838393262662e737667)](https://camo.githubusercontent.com/7001dc230291c2a963ca66407574a82f5dfef7c1a7ab0b0356a4f4818a2ca106/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344352e332d3838393262662e737667)[![CURL](https://camo.githubusercontent.com/f5a3b595480ac21ec43e745984c47d97fcc96f430547805750cd31928d67b28f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6355524c2d72657175697265642d677265656e2e737667)](https://camo.githubusercontent.com/f5a3b595480ac21ec43e745984c47d97fcc96f430547805750cd31928d67b28f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6355524c2d72657175697265642d677265656e2e737667)

[![Total Downloads](https://camo.githubusercontent.com/aa6169b72f364f258571f68f0797bdd27c83d2453b06539cdae2899a1655df96/68747470733a2f2f706f7365722e707567782e6f72672f656c65697262616738392f74656c656772616d626f747068702f646f776e6c6f616473)](https://packagist.org/packages/eleirbag89/telegrambotphp)[![License](https://camo.githubusercontent.com/2039c8e4877c6425a1786bc8cfc0b99143ec8a35b226df2addb158ad4b09bbb3/68747470733a2f2f706f7365722e707567782e6f72672f656c65697262616738392f74656c656772616d626f747068702f6c6963656e7365)](https://packagist.org/packages/eleirbag89/telegrambotphp)

> A very simple PHP [Telegram Bot API](https://core.telegram.org/bots) for sending messages.
> (Almost) Compliant with the May 18, 2017 Telegram Bot API update.

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

[](#requirements)

- PHP5
- Curl for PHP5 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 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:

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

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

[](#installation)

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

```
include("Telegram.php");
$telegram = new Telegram($bot_id);
```

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

#### Using Composer

[](#using-composer)

From your project directory, run

```
composer require eleirbag89/telegrambotphp

```

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

[](#configuration-webhook)

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

Examples
--------

[](#examples)

```
$telegram = new Telegram($bot_id);
$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($bot_id);
$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 wanna 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 the `serveUpdate` function inside a for cycle.

```
$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)

For a complete and up-to-date functions documentation check

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 rapresent the rows and columns.
For instance you can arrange a ReplyKeyboard like this: [![ReplyKeabordExample](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) [![InlineKeabordExample](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.

List of Bots using the library
------------------------------

[](#list-of-bots-using-the-library)

Let me know using this [Issue](https://github.com/Eleirbag89/TelegramBotPHP/issues/80) if you have made a bot using this API, I will add it to this section.

- [Notifyadbot](https://telegram.me/notifyadbot) - Lang : Persian/Farsi
- [Partners\_shakibonline\_bot](https://telegram.me/Partners_shakibonline_bot) - Lang : Persian/Farsi

Emoticons
---------

[](#emoticons)

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

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

[](#contact-me)

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

Support me
----------

[](#support-me)

You can buy me a beer or two using [Paypal](https://paypal.me/eleirbag89)
or support me using Flattr.

[![Flattr this git repo](https://camo.githubusercontent.com/7e3f46a36526479d701ef7f90a0f8c3ac2fbab3087446e2a9fceed75cd1ab802/687474703a2f2f6170692e666c617474722e636f6d2f627574746f6e2f666c617474722d62616467652d6c617267652e706e67)](https://flattr.com/submit/auto?user_id=eleirbag89&url=https://github.com/Eleirbag89/TelegramBotPHP&title=TelegramBotPHP&language=&tags=github&category=software)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.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 ~1 days

Total

3

Last Release

3327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/82803ca3428032359908222d5d36e99b2309be0a0e608ad2cce611d8bc6004d9?d=identicon)[shakibonline](/maintainers/shakibonline)

---

Top Contributors

[![Eleirbag89](https://avatars.githubusercontent.com/u/10547598?v=4)](https://github.com/Eleirbag89 "Eleirbag89 (155 commits)")[![abbas980301](https://avatars.githubusercontent.com/u/17107543?v=4)](https://github.com/abbas980301 "abbas980301 (29 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)")[![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)")[![xpyctum](https://avatars.githubusercontent.com/u/6584811?v=4)](https://github.com/xpyctum "xpyctum (2 commits)")

---

Tags

botphptelegram

### Embed Badge

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

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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