Download the PHP package kyle2142/phpbot without Composer
On this page you can find all versions of the php package kyle2142/phpbot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kyle2142/phpbot
More information about kyle2142/phpbot
Files in kyle2142/phpbot
Package phpbot
Short Description A simple lib to use Telegram's BotAPI in PHP
License MIT
Informations about the package phpbot
PHPBot
At some point I decided I wanted to make a Telegram bot. I saw the API and thought
hey, I might as well make my own lib for this
This lib doesn't have any groundbreaking features, but it allowed me to develop my own bots and be able to edit the underlying code as I needed.
Please read the wiki!
Getting Started
Prerequisites
- PHP >= 7.0
- cURL extension correctly installed and enabled
Installing
You may use any of the following:
-
Download PHPBot.php and
-
composer.json:
- CLI:
composer require kyle2142/phpbot=dev-master
with both of the composer methods, add this to your main file:
Usage
Receiving updates
I highly suggest you set up a webhook (requires SSL), so you can use this amazingly simple code to process updates:
Calling methods
This library contains some convenience functions, as well as access to the normal botAPI functions.
For the most part, you can refer to Telegram's BotAPI for method names and parameters.
If you really want to, you can use PHP's ...
operator with convenience functions to unpack arrays:
Check the examples and documentation of the PHPBot class for details
Return values
Success
While calling any raw API method or convenience function, you will get a result in the form of an object or a boolean:
View dump
This means you can access return values as such:
Error
In the case of an error, kyle2142\TelegramException
(or one of its subclasses) will be thrown.
As an example, let us try delete a message that does not exist:
(Note that we already deleted message 172 here, so trying to delete it again will throw an error)
When you catch the error, you can get the error code and description (returned by Telegram) as such:
If your bot makes a lot of requests, you might run into 429
"FloodWait" errors, which will tell you how long until you can make that request again:
Have Questions?
Please do not open an issue for small questions etc, it's there for issues
- Telegram: @Kyle_S (preferred)
- Email (not preferred)
Contributing
If you want to contribute, please make sure you follow the current style and the changes do not break anything!
Tests
To run tests, you need to rename/copy tests/example-config.php
to tests/config.php
and update the values.
Make sure to have the correct testing environment!
E.g.GROUP_WITH_ADMIN
needs to be the ID of a group where the bot is an admin, or skip the tests that require them.
License
This project is licensed under the MIT License - see the LICENSE file for details
Acknowledgments
All versions of phpbot with dependencies
ext-curl Version *
ext-json Version *