Download the PHP package longman/telegram-bot without Composer

On this page you can find all versions of the php package longman/telegram-bot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.


After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?
Rate from 1 - 5
Rated 5.00 based on 3 reviews

Informations about the package telegram-bot

PHP Telegram Bot

PHP Telegram Bot logo

A Telegram Bot based on the official Telegram Bot API

API Version Join the bot support group on Telegram

Tests Code Coverage Code Quality Latest Stable Version Dependencies Total Downloads Downloads Month Minimum PHP Version License

Table of Contents


This is a pure PHP Telegram Bot, fully extensible via plugins.

Telegram announced official support for a Bot API, allowing integrators of all sorts to bring automated interactions to the mobile platform. This Bot aims to provide a platform where one can simply write a bot and have interactions in a matter of minutes.

The Bot can:

This code is available on GitHub. Pull requests are welcome.


Create your first bot

  1. Message @BotFather with the following text: /newbot

    If you don't know how to message by username, click the search field on your Telegram app and type @BotFather, where you should be able to initiate a conversation. Be careful not to send it to the wrong contact, because some users have similar usernames to BotFather.

    BotFather initial conversation

  2. @BotFather replies with:

  3. Type whatever name you want for your bot.

  4. @BotFather replies with:

  5. Type whatever username you want for your bot, minimum 5 characters, and must end with bot. For example: telesample_bot

  6. @BotFather replies with:

  7. Note down the 'token' mentioned above.

Optionally set the bot privacy:

  1. Send /setprivacy to @BotFather.

    BotFather later conversation

  2. @BotFather replies with:

  3. Type (or select) @telesample_bot (change to the username you set at step 5 above, but start it with @)

  4. @BotFather replies with:

  5. Type (or select) Disable to let your bot receive all messages sent to a group.

  6. @BotFather replies with:

Require this package with Composer

Install this package through Composer. Edit your project's composer.json file to require longman/telegram-bot.

Create composer.json file

and run composer update


run this command in your command line:

Choose how to retrieve Telegram updates

The bot can handle updates with getUpdates method:

Webhook getUpdates
Description Telegram sends the updates directly to your host You have to fetch Telegram updates manually
Host with https Required Not required
MySQL Not required (Not) Required

Using a custom Bot API server

For advanced users only!

As from Telegram Bot API 5.0, users can run their own Bot API server to handle updates. This means, that the PHP Telegram Bot needs to be configured to serve that custom URI. Additionally, you can define the URI where uploaded files to the bot can be downloaded (note the {API_KEY} placeholder).

Note: If you are running your bot in --local mode, you won't need the Request::downloadFile() method, since you can then access your files directly from the absolute path returned by Request::getFile().

Webhook installation

Note: For a more detailed explanation, head over to the example-bot repository and follow the instructions there.

In order to set a Webhook you need a server with HTTPS and composer support. (For a self signed certificate you need to add some extra code)

Create set.php with the following contents:

Open your set.php via the browser to register the webhook with Telegram. You should see Webhook was set.

Now, create hook.php with the following contents:

Self Signed Certificate

Upload the certificate and add the path as a parameter in set.php:

Unset Webhook

Edit unset.php with your bot credentials and execute it.

getUpdates installation

For best performance, the MySQL database should be enabled for the getUpdates method!

Create getUpdatesCLI.php with the following contents:

Next, give the file permission to execute:

Lastly, run it!

getUpdates without database

If you choose to / or are obliged to use the getUpdates method without a database, you can replace the $telegram->enableMySql(...); line above with:

Filter Update

:exclamation: Note that by default, Telegram will send any new update types that may be added in the future. This may cause commands that don't take this into account to break!

It is suggested that you specifically define which update types your bot can receive and handle correctly.

You can define which update types are sent to your bot by defining them when setting the getUpdates.

Alternatively, Update processing can be allowed or denied by defining a custom update filter.

Let's say we only want to allow messages from a user with ID 428, we can do the following before handling the request:

The reason for denying an update can be defined with the $reason parameter. This text gets written to the debug log.



All types are implemented according to Telegram API 7.1 (February 2024).

Inline Query

Full support for inline query according to Telegram API 7.1 (February 2024).


All methods are implemented according to Telegram API 7.1 (February 2024).

Send Message

Messages longer than 4096 characters are split up into multiple messages.

Send Photo

To send a local photo, add it properly to the $data parameter using the file path:

If you know the file_id of a previously uploaded file, just use it directly in the data array:

To send a remote photo, use the direct URL instead:

sendAudio, sendDocument, sendAnimation, sendSticker, sendVideo, sendVoice and sendVideoNote all work in the same way, just check the API documentation for the exact usage. See the ImageCommand.php for a full example.

Send Chat Action


Retrieve the user photo. (see WhoamiCommand.php for a full example)

getFile and downloadFile

Get the file path and download it. (see WhoamiCommand.php for a full example)

Send message to all active chats

To do this you have to enable the MySQL connection. Here's an example of use (check DB::selectChats() for parameter usage):

You can also broadcast a message to users, from the private chat with your bot. Take a look at the admin commands below.


MySQL storage (Recommended)

If you want to save messages/users/chats for further usage in commands, create a new database (utf8mb4_unicode_520_ci), import structure.sql and enable MySQL support BEFORE handle() method:

You can set a custom prefix to all the tables while you are enabling MySQL:

You can also store inline query and chosen inline query data in the database.

External Database connection

It is possible to provide the library with an external MySQL PDO connection. Here's how to configure it:

Channels Support

All methods implemented can be used to manage channels. With admin commands you can manage your channels directly with your bot private chat.


Predefined Commands

The bot is able to recognise commands in a chat with multiple bots (/command@mybot).

It can also execute commands that get triggered by events, so-called Service Messages.

Custom Commands

Maybe you would like to develop your own commands. There is a guide to help you create your own commands.

Also, be sure to have a look at the example commands to learn more about custom commands and how they work.

You can add your custom commands in different ways:

Commands Configuration

With this method you can set some command specific parameters, for example:

Admin Commands

Enabling this feature, the bot admin can perform some super user commands like:

Take a look at all default admin commands stored in the src/Commands/AdminCommands/ folder.

Set Admins

You can specify one or more admins with this option:

Telegram user id can be retrieved with the /whoami command.

Channel Administration

To enable this feature follow these steps:

Upload and Download directory path

To use the Upload and Download functionality, you need to set the paths with:


Take a look at the repo Wiki for further information and tutorials! Feel free to improve!


All project assets can be found in the assets repository.

Example bot

We're busy working on a full A-Z example bot, to help get you started with this library and to show you how to use all its features. You can check the progress of the example-bot repository).

Projects with this library

Here's a list of projects that feats this library, feel free to add yours!


If you like living on the edge, please report any bugs you find on the PHP Telegram Bot issues page.


See CONTRIBUTING for more information.


See SECURITY for more information.


All work on this bot consists of many hours of coding during our free time, to provide you with a Telegram Bot library that is easy to use and extend. If you enjoy using this library and would like to say thank you, donations are a great way to show your support.

Donations are invested back into the project :+1:

Thank you for keeping this project alive :pray:

For enterprise

Available as part of the Tidelift Subscription.

The maintainers of PHP Telegram Bot and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.


Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.


Credit list in CREDITS

All versions of telegram-bot with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-pdo Version *
ext-curl Version *
ext-json Version *
ext-mbstring Version *
psr/log Version ^1.1|^2.0|^3.0
guzzlehttp/guzzle Version ^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package longman/telegram-bot contains the following files

Loading the files please wait ....