Skip to main content
Version: 2024.1

Register Regular Actions to Pimcore Copilot

To register regular actions in Pimcore Copilot, two components need to be implemented. For actual examples see shipped implementations.

Server-Side Component

The server-side component is responsible for providing available actions based on search tokens.

To implement:

  • Create a PHP class that implements [Pimcore\Bundle\CopilotBundle\Copilot\ActionProviderInterface]
  • Register it as Symfony service with tag name pimcore.copilot.actions_provider and optional priority
    • priority should influence order of search results provided by multiple adapters (not implemented yet).
  • Result of ActionProvider needs to be a list of [Pimcore\Bundle\CopilotBundle\Copilot\Model\ActionInterface] objects
    • Either use [Pimcore\Bundle\CopilotBundle\Copilot\Model\RegularAction] or provide custom implementation
    • See method comments of interface for expected data

Client-Side Component

The client-side component is responsible for

  • executing some action when action is selected in Pimcore Copilot.
  • tracing progress of long-running actions and populating action history if necessary and wanted.

To implement:

  • Create a JS class that extends [pimcore.plugin.PimcoreCopilotBundle.copilot.adapters.abstractAdapter] and implement startProcessing method (will be called when action is selected in Pimcore Copilot)
    • this.actionItem: Action item containing all data provided by controller (title, jsAdapterName, jsConfig, icon, iconCls)
    • this.context: Context in what Pimcore Copilot dialog window was opened (subject, selected_elements, tags)
    • this.dialogWindow: Reference to Pimcore Copilot dialog window - e.g. do close it if necessary
  • JS class needs to be in namespace pimcore.plugin.PimcoreCopilotBundle.copilot.adapters.

Example

Server-Side Component

namespace App\RegularActions;

use Pimcore\Bundle\CopilotBundle\Copilot\ActionProviderInterface;
use Pimcore\Bundle\CopilotBundle\Copilot\Model\RegularAction;

final class AlertAction implements ActionProviderInterface
{
public function getActions(string $searchLanguage): array
{
return
[
new RegularAction('Alert', 'alertAdapter', ['message' => 'My Alert Message']),
];
}
}

Client-Side Component

pimcore.plugin.PimcoreCopilotBundle.copilot.adapters.alertAdapter = Class.create(pimcore.plugin.PimcoreCopilotBundle.copilot.adapters.abstractAdapter, {

startProcessing: function() {
this.dialogWindow.hideWindow();

const jsConfig = this.actionItem.jsConfig;

alert(jsConfig.message);
}
});

Register Service

    App\RegularActions\AlertAction:
tags:
- { name: "pimcore.copilot.actions_provider", priority: 40 }