项目作者: SilverOS

项目描述 :
PHP framework for Telegram Bots
高级语言: PHP
项目地址: git://github.com/SilverOS/Silbot-Webhook.git
创建时间: 2018-03-27T15:21:12Z
项目社区:https://github.com/SilverOS/Silbot-Webhook

开源协议:

下载


SilBot 1.5

A new version based on OOP programming in PHP 7 with MySQL integration.


Documentation

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.


Webhook

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


How it works

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


Config

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.


MySQL

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


Plugins

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

TO-DO List

  • Finish adding all the botapi methods
  • Add more functions to objects