PHPackages                             saber13812002/telegram-bale-bot-php - 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. saber13812002/telegram-bale-bot-php

ActiveLibrary

saber13812002/telegram-bale-bot-php
===================================

A very simple PHP Telegram Bot API

101.4(2y ago)1687↓100%MITPHPPHP &gt;=5.0

Since Jul 7Pushed 2y agoCompare

[ Source](https://github.com/saber13812002/TelegramBotPHP)[ Packagist](https://packagist.org/packages/saber13812002/telegram-bale-bot-php)[ Fund](https://flattr.com/@Eleirbag89)[ Fund](https://paypal.me/eleirbag89)[ RSS](/packages/saber13812002-telegram-bale-bot-php/feed)WikiDiscussions master Synced today

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

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

[](#telegrambotphp)

[![API](https://camo.githubusercontent.com/3640af1f53ac1a0c30100d03c8446465b07d6507403df11f8e54319d3b43a809/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54656c656772616d253230426f742532304150492d417072696c2532303136253243253230323032322d3336616465312e737667)](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)[![StyleCI](https://camo.githubusercontent.com/b66e8593819a913e643d6a02e84dd2364bc52dba08eb76a8431eff3d0723fed9/68747470733a2f2f7374796c6563692e696f2f7265706f732f33383439323039352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/38492095)

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

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

[](#requirements)

- PHP &gt;= 5.3
- Curl extension 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 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 saber13812002/telegram-bale-bot-php

```

or

```
php composer.phar require saber13812002/telegram-bale-bot-php

```

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/saber13812002/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');

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

#### 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');

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

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');

$bale = new Telegram('YOUR TELEGRAM TOKEN HERE', 'bale');

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

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

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

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

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.

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

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.

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.

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 support me using via LiberaPay [![Donate using Liberapay](https://camo.githubusercontent.com/f42d4c8650291eed95d5feb7658604d653ad107d3308fb7e8f269623d7ed65cf/68747470733a2f2f6c69626572617061792e636f6d2f6173736574732f776964676574732f646f6e6174652e737667)](https://liberapay.com/eleirbag89/donate)

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

###  Health Score

32

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 74.9% 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 ~137 days

Recently: every ~30 days

Total

17

Last Release

965d ago

Major Versions

1.3.10 → 100.32023-04-01

100.3 → 101.12023-04-01

v100.4 → 101.42023-07-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/e7e5641b8ce7d13a4d02cfd10151438c72b0543b172af62384b81cfd986a15b5?d=identicon)[saber13812002](/maintainers/saber13812002)

---

Top Contributors

[![Eleirbag89](https://avatars.githubusercontent.com/u/10547598?v=4)](https://github.com/Eleirbag89 "Eleirbag89 (260 commits)")[![abbas980301](https://avatars.githubusercontent.com/u/17107543?v=4)](https://github.com/abbas980301 "abbas980301 (25 commits)")[![saber13812002](https://avatars.githubusercontent.com/u/3294604?v=4)](https://github.com/saber13812002 "saber13812002 (8 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)")[![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)")[![ynvv](https://avatars.githubusercontent.com/u/7413262?v=4)](https://github.com/ynvv "ynvv (3 commits)")[![blopa](https://avatars.githubusercontent.com/u/3838114?v=4)](https://github.com/blopa "blopa (3 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (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)")

### Embed Badge

![Health badge](/badges/saber13812002-telegram-bale-bot-php/health.svg)

```
[![Health](https://phpackages.com/badges/saber13812002-telegram-bale-bot-php/health.svg)](https://phpackages.com/packages/saber13812002-telegram-bale-bot-php)
```

PHPackages © 2026

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