PHPackages                             pomerla/telegram\_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. [API Development](/categories/api)
4. /
5. pomerla/telegram\_bot\_php

ActiveLibrary[API Development](/categories/api)

pomerla/telegram\_bot\_php
==========================

A very simple PHP Telegram Bot API

09PHP

Since Dec 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/wpdew/TelegramBotPHP)[ Packagist](https://packagist.org/packages/pomerla/telegram_bot_php)[ RSS](/packages/pomerla-telegram-bot-php/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#telegrambotphp)

[![API](https://camo.githubusercontent.com/38f5981a84bda812dc177d788f9447ffda83909f9b8f6ee266888c5e62da65b9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54656c656772616d253230426f742532304150492d4175677573742532303233253243253230323031372d3336616465312e737667)](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/e3a6ad59b17f075bf226a4fc801c33ba5db15ee9a60f9ee7ca29e961ba1b41e5/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131323337383033372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/112378037)

> A very simple PHP [Telegram Bot API](https://core.telegram.org/bots).
> Compliant with the August 23, 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_token);
```

- 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\_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($bot_token);
$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_token);
$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 (Down as 16/09/17)
- [Partners\_shakibonline\_bot](https://telegram.me/Partners_shakibonline_bot) - Lang : Persian/Farsi (Down as 16/09/17)
- [Pishvazrobot](https://t.me/pishvazrobot) - Lang : Persian/Farsi - the most comprehensive bot for searching and listening to more than 100,000 RBT sound for two most popular and famous mobile operator in iran - MTN Irancell and Hamrahe Aval
- [iHarfBot](https://t.me/iHarfBot) - Lang: Persian/Farsi
- [AsansorBot](https://t.me/AsansorBot) - Lang: Persian/Farsi
- [IDPbot](https://t.me/IDPbot) - Lang: Persian/Farsi
- [Evil Insult Generator](https://telegram.me/EvilInsultGeneratorBot) - Lang English/German
- [ibelitbot](https://telegram.me/ibelitbot) -Lang Persian
- [skydrivebot](https://telegram.me/skydrivebot) - Lang Persian - Instagram Post Downloader - Youtube Link Generator
- [Advanced Pools Bot](https://telegram.me/apollbot) - Lang Italian/English([Contribute](https://poeditor.com/join/project/NMAUjrAZ5f))

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/)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

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

---

Top Contributors

[![wpdew](https://avatars.githubusercontent.com/u/3592963?v=4)](https://github.com/wpdew "wpdew (7 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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