# RubikaPhp - Rubika Bot API SDK

A complete PHP SDK for building bots on **Rubika Messenger** using the official Rubika Bot API.

## Features

✅ **Complete API Coverage** - 48+ API methods  
✅ **Advanced Button Types** - Calendar, Number/String Picker, Textbox, Location  
✅ **Text Formatting** - Markdown formatting (Bold, Italic, Code, Links, Mentions)  
✅ **Group Management** - User ban\unban\
✅ **Media Support** - Files\
✅ **Flexible Updates** - Polling or Webhook modes  
✅ **Type-Safe** - PHP 8.0+ with strong typing  
✅ **Well Tested** - 100+ unit tests with 100% pass rate  
✅ **PSR-4 Compliant** - Modern autoloading  

##installation:

```bash
git clone https://github.com/AbolfazlMirzae/RubikaPhp.git
cd RubikaPhp
composer install
```

## Quick Start

### Create a Bot

```php
use RubikaPhp\Core\Bot;

$bot = new Bot('YOUR_BOT_TOKEN');
```

### Send a Message

```php
$bot->chatId('c12345')
    ->text('Hello from RubikaPhp!')
    ->sendMessage();
```

### Send a File

```php
$bot->chatId('c12345')
    ->filePath('/path/to/file.pdf')
    ->sendFile();
```

### Handle Messages

```php
use RubikaPhp\Filters\Filters;

$bot->onUpdate(Filters::text(), function($bot, $update) {
    $bot->chatId($update->new_message->chat_id)
        ->text('Echo: ' . $update->new_message->text)
        ->sendMessage();
});

$bot->run();
```

## Advanced Features

### Button Types

**Calendar Selection**
```php
use RubikaPhp\Models\ButtonCalendar;
use RubikaPhp\Enums\ButtonCalendarTypeEnum;

$calendar = new ButtonCalendar(
    type: ButtonCalendarTypeEnum::DATEPERSIAN,
    min_year: '1400',
    max_year: '1410',
    title: 'Select Date'
);
```

**Number Picker**
```php
use RubikaPhp\Models\ButtonNumberPicker;

$picker = new ButtonNumberPicker(
    min_value: '1',
    max_value: '100',
    title: 'Choose a number'
);
```

**Location Picker**
```php
use RubikaPhp\Models\ButtonLocation;
use RubikaPhp\Models\Location;
use RubikaPhp\Enums\ButtonLocationTypeEnum;

$location = new ButtonLocation(
    type: ButtonLocationTypeEnum::PICKER,
    title: 'Share your location'
);
```

### Group Management

```php
// Ban a user
$bot->banUser('group_chat_id', 'user_id');
// Unban a user
$bot->unbanUser('group_chat_id', 'user_id')
```
### Advanced Filters

```php
// Command filter
$bot->onUpdate(Filters::command('start'), $handler);

// Text with prefix
$bot->onUpdate(Filters::text('/help'), $handler);

// Combined filters
$bot->onUpdate(
    Filters::text()->and(Filters::isForwarded()), 
    $handler
);

// File/Media filters
$bot->onUpdate(Filters::hasFile(), $handler);
$bot->onUpdate(Filters::hasLocation(), $handler);
$bot->onUpdate(Filters::hasSticker(), $handler);
```

### Text Formatting (Markdown)

```php
use RubikaPhp\Utils\Markdown;

$text = "Bold
$bot->chatId('c123')->text($text)->sendMessage();
```

**Supported formats:**
- `Bold("**text**")` → **text**
- `Italic("__text__")` → _text
- `Code("```php code```")` → `text`
- `Hyperlink("[text](link)")` → [text](url)
- `Mention("[text](guid)")` → [text](guid)
- `Spoiler("||text||")` → ||text||
- `Strike("~~text~~")` → ~~text~~
- `Underline("--text--")` → --text--
- `Mono(``text``)` → ``text``

## Documentation

- [FEATURES.md](FEATURES.md) - Complete feature documentation
- [CHANGELOG.md](CHANGELOG.md) - Version history
- [examples/basic_bot.php](examples/basic_bot.php) - Simple example
- [examples/advanced_bot.php](examples/advanced_bot.php) - Advanced features
- [examples/webhook_bot.php](examples/webhook_bot.php) - Webhook setup

## Testing

Run the test suite:

```bash
./vendor/bin/phpunit tests/
```

Current status: **80/80 tests passing** ✅

## API Methods

### Message Operations
- `sendMessage()` - Send text with optional keyboard
- `sendFile()` - Send file/document
- `sendPoll()` - Send poll/quiz
- `sendLocation()` - Send location
- `sendContact()` - Send contact info

### Message Editing
- `editMessageText()` - Update message text
- `editMessageKeypad()` - Update inline keyboard
- `deleteMessage()` - Delete message
- `forwardMessage()` - Forward message

### Chat Info
- `getMe()` - Get bot information
- `getChat()` - Get chat details

### Group Management
- `banUser()` - Ban user
- `unbanUser()` - Remove ban

### Bot Configuration
- `setCommands()` - Set command list
- `updateBotEndpoints()` - Configure webhook
- `setEndpoint()` - Setup endpoint for all types
- `editChatKeypad()` - Update keyboard layout

### Updates
- `getUpdates()` - Long polling
- `run()` - Start bot (polling or webhook)

## Requirements

- PHP >= 8.0
- Composer
- cURL extension
- JSON extension
- GuzzleHttp 7.x

## Structure

```
lib/
├── Core/Bot.php           # Main bot class
├── Api/RubikaAPI.php      # API client
├── Models/                # Data models
├── Filters/Filters.php    # Message filters
├── Enums/Enums.php        # Enumerations
└── Exceptions/            # Custom exceptions
```

## Contributing

Contributions welcome! Please follow PSR-12 standards and add tests for new features.

## License

MIT License - See LICENSE file

## Support

For API documentation, visit: https://rubika.ir/botapi

## Version

Current: **2.0.0**  
Last Updated: 1404/12/3 
Test Coverage: 100% (80/80 tests passing)


