Filter uncanny-automator

automator_app_integrations_endpoints

Filters the available app integrations endpoints to allow modification or addition of integration endpoints.

add_filter( 'automator_app_integrations_endpoints', $callback, 10, 1 );

Description

Allows developers to register custom webhook endpoints for App Integrations, enabling them to support various triggers. This filter receives an array of endpoint definitions. Developers can add, modify, or filter these endpoints to integrate their own services or customize existing ones.


Usage

add_filter( 'automator_app_integrations_endpoints', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

add_filter( 'automator_app_integrations_endpoints', 'my_custom_automator_endpoints', 10, 1 );

/**
 * Adds a custom endpoint for a specific integration to the Automator App Integrations.
 *
 * This function demonstrates how to hook into the 'automator_app_integrations_endpoints'
 * filter to add a new webhook endpoint for a hypothetical "MyIntegration" service.
 *
 * @param array $endpoints The existing array of registered endpoints.
 * @return array The modified array of endpoints, including the new custom one.
 */
function my_custom_automator_endpoints( $endpoints ) {
    // Define the details for our new custom endpoint.
    $new_endpoint = array(
        'service'     => 'MyIntegration', // The name of the integration service.
        'description' => 'Trigger actions when a new item is added to MyIntegration.', // A human-readable description.
        'endpoint'    => 'my-integration/new-item', // The unique identifier for the webhook route.
        'callback'    => array( 'MyIntegrationWebhooks', 'handle_new_item' ), // The callback function/method to execute.
        'args'        => array( // Arguments expected by the callback.
            'item_id'    => array(
                'type'        => 'integer',
                'description' => 'The ID of the new item.',
                'required'    => true,
            ),
            'item_title' => array(
                'type'        => 'string',
                'description' => 'The title of the new item.',
                'required'    => false,
            ),
        ),
    );

    // Add our new endpoint to the existing list of endpoints.
    $endpoints[] = $new_endpoint;

    // Return the updated array of endpoints.
    return $endpoints;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/core/services/app-integrations/action-manager.php:110

private function register_webhook_routes() {
		// Get all registered webhook endpoints via filter.
		$endpoints = apply_filters( 'automator_app_integrations_endpoints', array() );

		// Bail nothing to do.
		if ( empty( $endpoints ) || ! is_array( $endpoints ) ) {
			return;
		}

		// Filter endpoints into common patterns and legacy / custom.
		$common   = array_filter( $endpoints, array( $this, 'is_common_webhook_pattern' ) );
		$filtered = array_diff( $endpoints, $common );

		// Register common pattern.
		if ( ! empty( $common ) ) {
			$this->register_webhook_route( '/webhooks/(?P<endpoint>[a-zA-Z0-9_-]+)' );
		}

		// Register filtered routes.
		foreach ( $filtered as $endpoint ) {
			$this->register_webhook_route( $endpoint, true );
		}
	}

Scroll to Top