PHP framework for Telegram Bots
A new version based on OOP programming in PHP 7 with MySQL integration.
You can read the full documentation for this framework on https://github.com/SilverOS/Silbot-Webhook/wiki.
To easly install this framework you can use the installer.
To set the bot’s webhook you have to do a setWebhook request to the botAPI using this format:https://api.telegram.org/botTOKEN/setWebhook?url=https://your.server.com/path/index.php?token=TOKEN
You can also use @DevToolsForBot using Set Webhook and writing first the token and next the url to your server in format https://your.server.com/path/index.php?token=TOKEN
In the file functions/botapi.php
there is the botApi class, where there are the functions to make requests to the botapi. In index.php is defined in $bot
, so to send a message you can use $bot->sendMessage(‘Chat_ID’,’Text’);
.
Then, there is the file functions/update.php
whose purpose is to set variables, sort the update and, if set, save users in the database. The variables are set dinamically, the objects which do this are in functions/objects.php
.
In conclusion, index.php make same important variables easier tu write and execute commands.php, where the bot’s code should be written.
You can include config.php in an external file to use the framework’s functions and objects without elaborating an update
In the config.php
file you will find an array, $config, where you can set pre-defined values for some botapi variables if not included in the function, such as disable_notification
. You can also set if you want a MySQL database.
To use this you have to set database->active on true and insert your credentials in the config. After that are asked the names of two tables:
chat_id,username,lang,type
chat_id, state
. This is made to do stuff with the code.To install the database you need to do a GET request to the webhook url with the parameter install
There are two plugins folders:
plugins/start
will be loaded before commands.phpplugins/end
will be loaded after commands.php