Download the PHP package klev-o/telegram-bot-api without Composer

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

FAQ

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.

Example:
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?

Informations about the package telegram-bot-api

klev-o/telegram-bot-api

Simple and convenient implementation Telegram bot API with php version ^7.4 support. You'll like it)

Based on the Official Telegram api

License Packagist Downloads GitHub release (latest by date including pre-releases) Scrutinizer code quality (GitHub/Bitbucket) GitHub last commit

📖Intro

This bot is full support Official Telegram api. Fully object-oriented and simple code. All available types and methods are described using classes with documentation of all fields. You don't even need to refer to the official documentation - all descriptions are present in the bot! But still, for each class, the url to the documentation is indicated, where you can study the nuances, etc.

You just have to relax and create super bots!

Attention! At the moment, the bot only supports receiving updates through Webhook. Webhook is more efficient than Long-Polling, reduces server load and guarantees almost instant data refresh for your application. But it is worth considering some of the nuances, in more detail here

🛠 Installation

Run this command in your command line:

🔌Usage

Setting up a webhook

First, you need to install Webhook, to which the telegram will send updates. This can be done using the following code:

To prevent the webhook from being installed on every request, we add a simple check. Now open the file in your browser and you should see 'webhook was set'. If any error has occurred, then it can be caught in the corresponding block

Getting Webhook Updates

To receive updates, you must use the method getWebhookUpdates():

The $update variable will be an object Update

In general, by reading the official documentation, you can see the types for the fields of objects, or the return values ​​of methods - all this is completely consistent with the code.

For example, $update->message is of type Message, which corresponds to Klev\TelegramBotApi\Types\Message.

Just look at the documentation and call the methods you want!

A real example

Let's say we want the bot to reply "Hello, your username" to every message to the bot.

Let's write the following code:

As you can see, everything is very simple and straightforward. Remember, methods have many parameters that you can further customize to your preference. Description of each parameter is present in the code in phpdoc, or on the website of the official API documentation

Sending files

Sending files is very simple: you need to specify the path to the file or url in the field (if the method supports accepting files by url, see the description). Next, it will automatically check if the file exists locally and add all the necessary headers.

If the file is unreadable, you will get the error "File -filename- is not readable."

In the example below, the bot sends a local document if the user writes "doc" to the bot:

Also, nothing prevents passing a link to the file instead of a local file - the code will be absolutely the same, only this part will change:

📟Advanced

As you can see, the $bot->getWebhookUpdates() method returns the result as an Update object. In the simplest case, we can check which field is filled in this object and, on this basis, implement further logic. But this may not be very convenient if we have any medium or large project.

Events come to the rescue (Klev\TelegramBotApi\Events\*):

List of events
CallbackQueryEvent
ChannelPostEvent
ChatJoinRequestEvent
ChatMemberEvent
ChosenInlineResultEvent
EditedChannelPostEvent
EditedMessageEvent
InlineQueryEvent
MessageEvent
MyChatMemberEvent
PollAnswerEvent
PollEvent
PreCheckoutQueryEvent
ShippingQueryEvent

You can register your own handler for any of these events and be sure which update you are responding to. By default, events are disabled. To enable them, you need to use the method $bot->setEnableEvents(true); Consider an example:

Each Event object will have 2 required fields: update_id and payload. What type of payload will be in the event can be viewed in the class with the desired event

Also, as an event handler, you can use anything that corresponds to the callable type. Consider an example:

🎁Dontations

Support the project if you like it. Funds will go towards food.

Network Currency Wallet
Bitcoin BTC 1M1qhSE6sN34a4d7ZtCh6y17Vf3LtdoW62
or
14cvXywCMucKMhFYDCbmQ1ZHhayDgbD65R
The Open Network TON EQAYZK8rWrS9Fhojdc486BpplDmTSLHum440f-L2--SA2Oid
or
ton://transfer/UQBVsumSIvsq4PfeFMhxSV9m_zPB31cHJX4X2lAVh9BUJXm3
Binance Smart Chain – BEP20 BNB, BUSD, USDT 0x674B09Ab418bb41C075847bde004bb7F492c2121

🧨Troubleshooting

Please, if you find any errors or not exactly - report this problem page

And finally...

Happy botting 🤖


All versions of telegram-bot-api with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4.0 || ^8.0
ext-json Version *
ext-curl Version *
guzzlehttp/guzzle Version ^7.2
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 klev-o/telegram-bot-api contains the following files

Loading the files please wait ....