PHP code example of zafarjonovich / yii-telegram-action

1. Go to this page and download the library: Download zafarjonovich/yii-telegram-action library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zafarjonovich / yii-telegram-action example snippets


use zafarjonovich\YiiTelegramAction\models\TelegramMessageAction;
use \zafarjonovich\YiiTelegramAction\models\TelegramMessageActionChild;
use zafarjonovich\YiiTelegramAction\base\ChildAction;
use \zafarjonovich\YiiTelegramAction\base\Action;

class SendNotification extends ChildAction
{
    public function run(){
    
        $children = $this->parent->action->getTelegramMessageActionChildren()->all();
        
        $options = $this->parent->action->options;
        
        foreach ($children as $child) {
            \Yii::$app->telegram->sendMessage($child->chat_id,$options['text']);
        }
    }
}

$options = [
    'text' => 'Hello world'
];

$action = TelegramMessageAction::create('UniqueKey',SendNotification::class,$options);

// id = 7
TelegramMessageActionChild::create($action->id,666000111);


// For run action

class SomeControllerAction extends \yii\base\Action
{
    
}

$controllerAction = new SomeControllerAction();

$asyncAction = new Action($action,$controllerAction);
$asyncAction->run();