rubika/app

This package is abandoned and no longer maintained. The author suggests using the rubialib/rubikalib package instead.

rubika library for making apps with PHP

v1.3 2023-04-06 17:58 UTC

This package is auto-updated.

Last update: 2024-10-10 08:20:48 UTC


README

rubika client for running bots with PHP. use this client to make bots, games and ...

usage

run this command on terminal

composer require rubika/app
  1. create a new php file in current directory

  2. require vendor and Bot class in file

require_once __DIR__ . '/vendor/autoload.php';

use Rubika\Bot;
  1. now you can send messages
$bot = new Bot(9123456789);
$bot->sendMessage('u0FFeu...', 'سلام');

get message updates

for getting updates, you must create new class with a name and call it

require_once __DIR__ . '/vendor/autoload.php';

use Rubika\Client;

class myBot extends Client
{
    function onStart(): void # required !
    {
        echo 'bot running ... ';
    }

    function runBot(array $update) # required !
    {
        foreach ((isset($update['message']) ? $update['message'] : $update) as $message) {
            $message = isset($message['message']) ? $message['message'] : $message;
            $msg_id = $message['message_id'];
            $text = $message['text'];
            $type = $message['type'];
            $user_id = $message['author_object_guid'];

            $this->sendMessage($user_id, 'پیامتان دریافت شد ;)');
        }
    }
}

new myBot(9123456789);

error exceptions

we created exception system for all possible errors you can catch them with try/catch :

use Rubika\Exception\Error;

try {
    $bot = new Bot(9123456789);
    $bot->sendMessage('u0FFeu...', 'سلام');
} catch (Error $e) {
    echo $e->getMessage();
}


// or for updates :


try {
    new myBot(9206634543);
} catch (Error $e) {
    echo $e->getMessage();
}

web mode

if you runs your bot on web page or want to make web page, we have a way too ;)

Note : with runnig on web page, Bot will active web mode automatic

require_once __DIR__ . '/vendor/autoload.php';

$page = Web(9123456789);
// $page = Web(9123456789, 'index.php'); you can add a custom index file
// index file:
//     <?php
//     echo 'its OK ;)';
//     ?>

$page->sendMessage("uFF...", 'سلام');

* web login feature will improve on the text versions ...

fast mode

you can get message updates without writing class or ...

require_once __DIR__ . '/vendor/autoload.php';

Fast(function ($update, $obj) {
    foreach ((isset($update['message']) ? $update['message'] : $update) as $message) {
        $message = isset($message['message']) ? $message['message'] : $message;
        $msg_id = $message['message_id'];
        $text = $message['text'];
        $type = $message['type'];
        $user_id = $message['author_object_guid'];

        $obj->sendMessage($user_id, 'پیامتان دریافت شد ;)');
    }
}, 9123456789);

auto send message action

now you can set auto send action mode to your media like send messgae, photo, ... .

Fast(function ($update, $obj) {
    // ...
        $obj->autoSendAction = true;
    // ...
}, 9123456789);