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:
- universal_table => Created to work with more than one bot, there will be saved all the users and chats the bot see with Telegram information, even with forwarded messages or reply. The table contains 4 coloumns:
chat_id,username,lang,type
- bot_table => Where the bot's users are saved, by default it only contains two coloumns:
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 in
plugins/start
will be loaded before commands.php - Plugins in
plugins/end
will be loaded after commands.php To add a plugin just drop it in the needed folder
- Finish adding all the botapi methods
- Add more functions to objects