Download the PHP package php-telegram-bot/telegram-bot-manager without Composer
On this page you can find all versions of the php package php-telegram-bot/telegram-bot-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-telegram-bot/telegram-bot-manager
More information about php-telegram-bot/telegram-bot-manager
Files in php-telegram-bot/telegram-bot-manager
Package telegram-bot-manager
Short Description PHP Telegram Bot Manager
License MIT
Homepage https://github.com/php-telegram-bot/telegram-bot-manager
Informations about the package telegram-bot-manager
PHP Telegram Bot Manager
This project builds on top of PHP Telegram Bot and as such, depends on it!
The main purpose of this mini-library is to make the interaction between your webserver and Telegram easier. I strongly suggest your read the PHP Telegram Bot instructions first, to understand what this library does exactly.
Installation and usage is pretty straight forward:
Require this package with Composer
NOTE: This will automatically also install PHP Telegram Bot into your project (if it isn't already).
Advanced: Due to the fact that the core library is not a stable version yet, this project is partly locked to the core version, to ensure reliable functioning.
It is possible however, to override the core version that this library requires:
This example will pull the master version of the core library, making it appear to be version 0.81, which then satisfies the requirement.
Performing actions
What use would this library be if you couldn't perform any actions?!
There are a few parameters available to get things rolling:
Parameter | Description |
---|---|
s | secret: This is a special secret value defined in the main manager.php file. |
This parameter is required to call the script via browser! | |
a | action: The actual action to perform. (handle (default), webhookinfo, cron, set, unset, reset) |
handle executes the getUpdates method; webhookinfo to get result from getWebhookInfo , cron executes cron commands; set / unset / reset the webhook. |
|
l | loop: Number of seconds to loop the script for (used for getUpdates method). |
This would be used mainly via CLI, to continually get updates for a certain period. | |
i | interval: Number of seconds to wait between getUpdates requests (used for getUpdates method, default is 2). |
This would be used mainly via CLI, to continually get updates for a certain period, every i seconds. | |
g | group: Commands group for cron (only used together with cron action, default group is default ). |
Define which group of commands to execute via cron. Can be a comma separated list of groups. |
via browser
Simply point your browser to the manager.php
file with the necessary GET parameters:
http://example.com/manager.php?s=<secret>&a=<action>&l=<loop>&i=<interval>
Webhook
Set, unset and reset the webhook:
http://example.com/manager.php?s=super_secret&a=set
http://example.com/manager.php?s=super_secret&a=unset
http://example.com/manager.php?s=super_secret&a=reset
(unset & set combined)
getUpdates
Handle updates once:
http://example.com/manager.php?s=super_secret&a=handle
or simplyhttp://example.com/manager.php?s=super_secret
(handle
action is the default)
Handle updates for 30 seconds, fetching every 5 seconds:
http://example.com/manager.php?s=super_secret&l=30&i=5
cron
Execute commands via cron:
http://example.com/manager.php?s=super_secret&a=cron&g=maintenance
or multiple groupshttp://example.com/manager.php?s=super_secret&a=cron&g=maintenance,cleanup
via CLI
When using CLI, the secret is not necessary (since it could just be read from the file itself).
Call the manager.php
file directly using php
and pass the parameters:
$ php manager.php a=<action> l=<loop> i=<interval>
Webhook
Set, unset and reset the webhook:
$ php manager.php a=set
$ php manager.php a=unset
$ php manager.php a=reset
(unset & set combined)
getUpdates
Handle updates once:
$ php manager.php a=handle
or simply$ php manager.php
(handle
action is the default)
Handle updates for 30 seconds, fetching every 5 seconds:
$ php manager.php l=30 i=5
cron
Execute commands via cron:
$ php manager.php a=cron g=maintenance
or multiple groups$ php manager.php a=cron g=maintenance,cleanup
Create the manager PHP file
You can name this file whatever you like, it just has to be somewhere inside your PHP project (preferably in the root folder to make things easier).
(Let's assume our file is called manager.php
)
Let's start off with a simple example that uses the webhook method:
Set vital bot parameters
The only vital parameter is the API key:
Set extra bot parameters
Apart from the necessary API key, the bot can be easily configured using extra parameters.
Set the webhook? Enable admins? Add custom command paths?
All no problem!
The secret
is a user-defined key that is required to execute any of the library's features via webhook.
Best make it long, random and very unique!
For 84 random characters:
- If you have
pwgen
installed, just executepwgen 84 1
and copy the output. - If you have
openssl
installed, useopenssl rand -hex 84
. - Or just go here and put all the output onto a single line.
(You get 2 guesses why 84 is a good number :wink:)
Below is a complete list of all available extra parameters.
Using getUpdates method
Using the getUpdates
method must not have a webhook
parameter set and requires a MySQL database connection:
Now, the updates can be done either through the via CLI.
Custom getUpdates output
A callback can be defined, to override the default output when updates are handled via getUpdates.
Example of the default output:
Using custom callback that must return a string:
output:
Development
When running live bot tests on a fork, you must enter the following environment variables to your repository settings:
It probably makes sense for you to create a new dummy bot for this.
Security
See SECURITY for more information.
Donate
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:
- Patreon.com/phptelegrambot
- OpenCollective.com/php-telegram-bot
- Ko-fi.com/phptelegrambot
- Tidelift.com/longman/telegram-bot
- Liberapay.com/PHP-Telegram-Bot
- PayPal.me/noplanman (account of @noplanman)
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
All versions of telegram-bot-manager with dependencies
longman/telegram-bot Version ^0.81
longman/ip-tools Version ^1.2
psr/log Version ^1.0|^2.0|^3.0