PHPackages                             arefshojaei/tgram - 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. arefshojaei/tgram

ActiveLibrary[API Development](/categories/api)

arefshojaei/tgram
=================

PHP Telegram Bot

1.2.4(2w ago)17MITPHPPHP &gt;=8.2

Since Jul 10Pushed 2w agoCompare

[ Source](https://github.com/ArefShojaei/TGram)[ Packagist](https://packagist.org/packages/arefshojaei/tgram)[ RSS](/packages/arefshojaei-tgram/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

TGram - PHP Telegram Bot Library
================================

[](#tgram---php-telegram-bot-library)

[![PHP Version](https://camo.githubusercontent.com/12ba79b4c8771d8067d75af9042c66480c860df180785c6462538e847ea1a5d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![GitHub](https://camo.githubusercontent.com/a2bc06fa7f0e2d3692ae038d8e633d9de83f8f814d8d3a5dcd3fc341ec66bcd2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769746875622d544772616d2d626c61636b3f6c6f676f3d676974687562)](https://github.com/ArefShojaei/TGram)

A Powerful and Easy-to-Use PHP Library for Building Telegram Bot

[![TGram](https://private-user-images.githubusercontent.com/134844185/609174784-e878e717-25ed-41e9-a203-4c9df6aa3bf8.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50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wNzEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDcxMlQxMzIyMzVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kYjRjYmQzZDc0YTNkOTQ5NDAzNTIxMmU2OTAxNDQ4MWY1MDA4MDBhNGE1NTMyZmE4M2M5NzY2YWUzNTE5NzM1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.baozjkXgdA6Sf1k8Z8fJt1xIVaqPi-JFSzOoCClUPtM)---

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

[](#table-of-contents)

- [Introduction](#introduction)
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Core Concepts](#core-concepts)
- [Basic Usage](#basic-usage)
- [Handling Messages](#handling-messages)
- [Sending Messages](#sending-messages)
- [Keyboards](#keyboards)
- [Advanced Features](#advanced-features)
- [Configuration](#configuration)
- [Examples](#examples)
- [Testing](#testing)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [License](#license)

---

Introduction
------------

[](#introduction)

**TGram** is a modern, user-friendly PHP framework for building Telegram bots. Whether you're creating a simple bot that responds to messages or building a complex interactive application, TGram provides all the tools you need with an intuitive API.

With TGram, you can:

- Easily create Telegram bots in PHP
- Handle messages and commands with simple syntax
- Build interactive keyboards and menus
- Manage user interactions effortlessly
- Deploy using polling or webhook methods

---

Features
--------

[](#features)

✨ **Key Features:**

- **Simple API**: Clean, intuitive syntax for developers of all levels
- **Command Handling**: Built-in support for bot commands (`/start`, `/help`, etc.)
- **Command Parameters**: Extract dynamic values from commands (`/user/{id}`, `/post/{slug}`)
- **Message Listeners**: Listen for exact messages or regex patterns
- **Regex Support**: Match messages using custom regular expressions
- **Keyboard Support**: Create inline and reply keyboards with buttons
- **Message Types ( Media )**: Handle photos, documents, videos and more
- **Chat Management**: Manage chat information and user interactions
- **Multiple Modes**: Support for both Polling and Webhook processing
- **Error Handling**: Robust exception handling and error reporting
- **Modern PHP**: Built with PHP 8.0+ features (attributes, typed properties, etc.)
- **Well-Structured**: Organized codebase with clear separation of concerns
- **Fully Tested**: Comprehensive test suite with 100+ tests

---

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

[](#requirements)

Before you start, make sure you have:

- **PHP 8.2** or higher
- **Composer** (dependency manager for PHP)
- **Active Telegram Bot Token** (create one via [BotFather](https://t.me/BotFather))

---

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

[](#installation)

### Option 1: Using Composer (Recommended)

[](#option-1-using-composer-recommended)

The easiest way to install TGram is through Composer:

```
composer require arefshojaei/tgram
```

This will download TGram and all its dependencies automatically.

### Option 2: Manual Clone

[](#option-2-manual-clone)

If you prefer to clone the repository directly:

```
git clone https://github.com/ArefShojaei/TGram.git
cd TGram
composer install
```

---

Quick Start
-----------

[](#quick-start)

Here's the simplest way to get your first bot running:

```
