PHP code example of mamadali / yii2-webhook

1. Go to this page and download the library: Download mamadali/yii2-webhook 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/ */

    

mamadali / yii2-webhook example snippets


    'modules' => [
        ...
        'webhook' => [
            'class' => 'mamadali\webhook\Module',
            'url' => 'https://example.com/webhook',
        ],
        ...
    ];

public function behaviors()
{
    return [
		[
		    'class' => 'mamadali\webhook\WebhookBehavior',
			'modelName' => 'ExampleModel', // your model name, 

    'modules' => [
        ...
        'webhook' => [
            'class' => 'mamadali\webhook\Module',
            'url' => 'https://example.com/webhook',
            'authToken' => base64_encode("$username:$password"), // change username and password
        ],
        ...
    ];

    'modules' => [
        ...
        'webhook' => [
            'class' => 'mamadali\webhook\Module',
            'url' => 'https://example.com/webhook',
            'authMethod' => 'Bearer',
            'authToken' => $token, // your token here
        ],
        ...
    ];

public function behaviors()
{
	return [
		[
			'class' => 'mamadali\webhook\WebhookBehavior',
			'modelName' => 'ExampleModel', // your model name, 

public function behaviors()
{
	return [
		[
			'class' => 'mamadali\webhook\WebhookBehavior',
			'modelName' => 'ExampleModel', // your model name, 
	];
}

public function behaviors()
{
	return [
		[
		    'class' => 'mamadali\webhook\WebhookBehavior',
			'modelName' => 'ExampleModel', // your model name, f $model) {
                    return date('Y-m-d H:i:s', $model->created_at);
                },
			],
		],
	];
}

public function behaviors()
{
	return [
		[
		    'class' => 'mamadali\webhook\WebhookBehavior',
			'modelName' => 'ExampleModel', // your model name, 

public function behaviors()
{
	return [
		[
		    'class' => 'mamadali\webhook\WebhookBehavior',
			'modelName' => 'ExampleModel', // your model name, 

public function behaviors()
{
	return [
		[
		    'class' => 'mamadali\webhook\WebhookBehavior',
			'modelName' => 'ExampleModel', // your model name, 

    'modules' => [
        ...
        'webhook' => [
            'class' => 'mamadali\webhook\Module',
            'url' => 'https://example.com/webhook',
            'jobNamespace' => 'console\job',
        ],
        ...
    ];



namespace console\job;

use mamadali\webhook\Module;
use Yii;
use yii\base\BaseObject;
use yii\queue\RetryableJobInterface;

class WebhookJob extends BaseObject implements RetryableJobInterface
{
	/**
	 * @var integer the webhook id
	 */
	public $webhook_id;

	public function execute($queue)
	{
		/**
		 * @var Module
		 */
		$module = Yii::$app->getModule('webhook');
		$module->send($this->webhook_id);
	}


	public function getTtr()
	{
		return 60;
	}

	public function canRetry($attempt, $error)
	{
		return $attempt < 5;
	}
}

php yii migrate/up --migrationPath=@vendor/mamadali/yii2-webhook/migrations