PHP code example of dollieai / wp-sdk

1. Go to this page and download the library: Download dollieai/wp-sdk 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/ */

    

dollieai / wp-sdk example snippets




namespace MyPlugin\Integrations\CustomService;

use Dollie\SDK\Attributes\Integration;
use Dollie\SDK\Base\BaseIntegration;
use Dollie\SDK\Traits\SingletonLoader;

#[Integration(
    id: 'custom_service',
    name: 'Custom Service',
    slug: 'custom-service',
    since: '1.0.0',
    homepage: 'https://example.com',
    tags: ['custom']
)]
class CustomService extends BaseIntegration
{
    use SingletonLoader;

    protected $id = 'custom_service';
    protected $name = 'Custom Service';

    public function is_plugin_installed(): bool
    {
        return class_exists('CustomServicePlugin');
    }
}



namespace MyPlugin\Integrations\CustomService\Triggers;

use Dollie\SDK\Attributes\Trigger;

#[Trigger(
    id: 'custom_service.event_occurred',
    label: 'Event Occurred',
    description: 'Fires when a custom event occurs',
    payloadSchema: [
        'type' => 'object',
        'Trigger implementation
}



namespace MyPlugin\Integrations\CustomService\Actions;

use Dollie\SDK\Attributes\Action;
use Dollie\SDK\Base\AutomateAction;
use Dollie\SDK\Traits\SingletonLoader;

#[Action(
    id: 'custom_service.create_item',
    label: 'Create Item',
    description: 'Creates a new item in the service',
    inputSchema: [
        'type' => 'object',
        '> 'Test Item', 'description' => 'A test item']
    ],
    tags: ['items'],
    since: '1.0.0'
)]
class CreateItem extends AutomateAction
{
    use SingletonLoader;

    public $integration = 'custom_service';
    public $action = 'create_item';

    public function register($actions)
    {
        $actions[$this->integration][$this->action] = [
            'label' => 'Create Item',
            'action' => $this->action,
            'function' => [$this, '_action_listener'],
        ];
        return $actions;
    }

    public function _action_listener($user_id, $automation_id, $fields, $selected_options)
    {
        // Action implementation
        return ['success' => true, 'item_id' => 123];
    }
}

src/
├── Attributes/
│   ├── Integration.php    # #[Integration] attribute for marking integration classes
│   ├── Trigger.php        # #[Trigger] attribute for defining trigger metadata
│   └── Action.php         # #[Action] attribute for defining action metadata
├── Base/
│   ├── BaseIntegration.php    # Abstract base class for integrations
│   └── AutomateAction.php     # Abstract base class for actions
├── Controllers/
│   ├── IntegrationsController.php  # Manages integration registration
│   └── AutomationController.php    # Handles trigger execution
└── Traits/
    └── SingletonLoader.php    # Singleton pattern trait