Rubikit
A modern, secure, and fluent PHP framework for building Rubika bots. Focus on your logic โ we handle the complexity.
Get Started DownloadFeatures
Smart Webhook
One-click webhook registration โ no manual API calls. Just call setup.php with your token, and your bot file is generated and webhook is set automatically.
Fluent API
Chain methods naturally: $bot->chat($chatId)->withChatKeypad($keypad)->sendMessage("Hello"). Simple, readable, powerful.
Keyboard Toolkit
Build both Chat (persistent) and Inline (floating) keypads with all button types (Simple, Link, SharePhone, AskMyPhoneNumber, etc.).
File Manager
Upload and send files directly from local paths or existing file_id. The framework handles the two-step upload automatically.
Database Layer
Built-in QueryBuilder with validation, auto-reconnect on failure, and support for MySQL/SQLite. All queries use prepared statements.
Security
Input sanitization, rate limiter, database validation โ all active by default. Just write your bot logic; security is already handled.
Installation
Install Rubikit via Composer (coming soon):
COMING SOON
Or clone manually and run composer install.
Quick Start
Create a setup.php file:
<?php
require 'vendor/autoload.php';
use Rubikit\Setup\Setter;
header('Content-Type: application/json; charset=utf-8');
$setter = new Setter($_GET);
echo json_encode($setter->deploy(), JSON_UNESCAPED_UNICODE);
Then visit (replace with your actual token):
https://yourdomain.com/setup.php?token=YOUR_BOT_TOKEN&webhook_type=webhook&file_name=my_bot.php
Your bot file (e.g., app/my_bot_xxxxxx.php) is created and webhook registered instantly.
Example Bot
The generated bot file already contains a minimal working bot. You can customize it:
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Rubikit\Bot;
use Rubikit\Config;
use Rubikit\Webhook\Server;
$config = new Config(require __DIR__.'/../config/rubikit.php');
$bot = new Bot($config);
$bot->onMessage(function ($update) use ($bot) {
$name = $update->getSenderFirstName() ?? 'User';
$bot->chat($update->chatId())->sendMessage("Hello, {$name}!");
});
$server = new Server($bot);
$server->run();
Keyboards
Chat Keypad (persistent)
use Rubikit\Keyboard\Chat;
use Rubikit\Keyboard\Button;
$keypad = (new Chat())
->addRow()
->addButton(Button::simple('profile', '๐ค Profile'))
->addButton(Button::simple('about', '๐ About'))
->addRow()
->addButton(Button::simple('help', 'โ Help'));
$bot->chat($chatId)
->withChatKeypad($keypad)
->sendMessage("Choose an option:");
Inline Keypad (floating)
use Rubikit\Keyboard\Inline;
$inline = (new Inline())
->addRow()
->addButton(Button::link('Website', 'https://rubika.ir'))
->addRow()
->addButton(Button::simple('done', 'โ
Done'))
->addButton(Button::simple('cancel', 'โ Cancel'));
$bot->chat($chatId)
->withInlineKeypad($inline)
->sendMessage("Quick actions:");
Handling Clicks
Both Chat and Inline button clicks are handled by onChatKeypad:
$bot->onChatKeypad(function ($update) use ($bot) {
$buttonId = $update->buttonId();
if ($buttonId === 'profile') {
$bot->chat($update->chatId())->sendMessage("Your profile.");
}
});
File Upload & Send
Send a Local File
Automatic two-step upload and send:
$bot->chat($chatId)
->sendFileFromLocal('/path/to/report.pdf', '๐ Monthly Report');
Send Using an Existing file_id
$bot->chat($chatId)
->sendFileById('6oPxsDV...', 'Image from gallery');
Get a File's Download URL
$info = $bot->fileManager()->getFile($fileId);
// $info['data']['download_url'] contains the URL
Database
Configure database in config/rubikit.php (auto-generated):
'database' => [
'driver' => 'mysql',
'config' => [
'host' => 'localhost',
'port' => 3306,
'database' => 'my_bot_db',
'username' => 'root',
'password' => '',
'charset' => 'utf8mb4',
],
],
Basic CRUD
$db = $bot->db();
// Insert
$db->table('users')->insert([
'chat_id' => $chatId,
'name' => 'Ali',
'wallet' => 100,
]);
// Select
$user = $db->table('users')->where('chat_id', $chatId)->first();
// Update
$db->table('users')->where('chat_id', $chatId)->update(['wallet' => 200]);
// Delete
$db->table('users')->where('chat_id', $chatId)->delete();
Validation
$db->table('users')->insert([
'name' => 'Ali',
'age' => 'twenty',
], [
'name' => 'required|string|max:255',
'age' => 'int',
]);
// Throws RuntimeException: Field 'age' must be an integer.
Text Formatting
Use Parser for simple formatting:
use Rubikit\Message\Parser;
$bot->chat($chatId)->sendMessage(Parser::bold('Important!'));
$bot->chat($chatId)->sendMessage(Parser::link('Click here', 'https://rubika.ir'));
Or TextBuilder for complex messages:
use Rubikit\Message\TextBuilder;
$msg = (new TextBuilder())
->bold('Welcome')
->addText(' back, ')
->italic('friend')
->build();
$bot->chat($chatId)->sendMessage($msg);
Editing & Deleting Messages
$editor = $bot->editor();
$editor->editMessageText($chatId, $messageId, 'Updated text');
$editor->deleteMessage($chatId, $messageId);
Group Management
$cm = $bot->chatManager();
$cm->banChatMember($groupId, $userId);
$cm->unbanChatMember($groupId, $userId);
$cm->forwardMessage($fromChatId, $messageId, $toChatId);
Location, Contact & Poll
$sender = $bot->chat($chatId);
$sender->sendLocation('35.6892', '51.3890');
$sender->sendContact('Ali', 'Rezaei', '09123456789');
$sender->sendPoll('Favorite color?', ['Red', 'Blue', 'Green']);
Security (Enabled by Default)
- Input sanitization โ all incoming data cleaned automatically.
- Rate limiter โ max 20 requests/min per user.
- Database validation โ enforce data types and length.
- PDO prepared statements โ 100% SQL injection proof.
- Auto-reconnect on database failure.
Download
The latest release can be downloaded directly.
Download v1.0Contact & Community
Developer
Rubika: @gheyme_ba_mast
Rubikit Channel
Report Issues
GitHub (coming soon).