Action uncanny-automator-pro

automator_pro_run_webhook

Fires after a webhook has been executed within Automator Pro, providing access to hook, recipe, and data details.

add_action( 'automator_pro_run_webhook', $callback, 10, 3 );

Description

Fires after a webhook trigger successfully processes data for a recipe. Developers can use this hook to perform custom actions or data manipulations based on the received webhook payload. It provides access to the webhook trigger details, the recipe that was run, and the processed data.


Usage

add_action( 'automator_pro_run_webhook', 'your_function_name', 10, 3 );

Parameters

$_hooks (mixed)
This parameter contains an array of hooks that are executed when a webhook is triggered.
$recipe (mixed)
This parameter contains an array of hook names that the webhook is associated with.
$data (mixed)
This parameter contains information about the specific Uncanny Automator recipe that triggered the webhook, including its ID and settings.

Examples

<?php
/**
 * Example callback function for the 'automator_pro_run_webhook' action hook.
 * This function demonstrates how to access and process the webhook data.
 *
 * @param array $hooks An array of hook information. The exact structure depends on the plugin.
 * @param array $recipe An array representing the Uncanny Automator recipe being triggered.
 * @param array $data An array containing the data passed to the webhook.
 */
add_action(
	'automator_pro_run_webhook',
	function( $hooks, $recipe, $data ) {
		// Check if the recipe is for a specific automation, for example, triggering a form submission.
		if ( isset( $recipe['id'] ) && $recipe['id'] === 123 ) { // Replace 123 with a real recipe ID for testing
			// Log that this specific recipe has been triggered by a webhook.
			automator_log(
				sprintf(
					'Webhook triggered for Recipe ID: %d',
					$recipe['id']
				),
				'Webhook Processing',
				AUTOMATOR_DEBUG_MODE
			);

			// Example: If the webhook data contains a user ID, get user details.
			if ( isset( $data['user_id'] ) && ! empty( $data['user_id'] ) ) {
				$user_id = absint( $data['user_id'] );
				$user = get_user_by( 'id', $user_id );

				if ( $user ) {
					automator_log(
						sprintf(
							'User detected from webhook data: %s (ID: %d)',
							$user->user_login,
							$user->ID
						),
						'Webhook User Data',
						AUTOMATOR_DEBUG_MODE
					);

					// Further actions can be taken here, e.g., update user meta, send an email.
					// For instance, update a custom meta field for this user.
					update_user_meta( $user_id, 'last_webhook_trigger', current_time( 'mysql' ) );
				} else {
					automator_log(
						sprintf(
							'User ID %d found in webhook data, but user does not exist.',
							$user_id
						),
						'Webhook User Data Error',
						AUTOMATOR_DEBUG_MODE
					);
				}
			}

			// Example: Process other data points from the webhook.
			if ( isset( $data['custom_field'] ) ) {
				automator_log(
					sprintf(
						'Custom field value from webhook: %s',
						sanitize_text_field( $data['custom_field'] )
					),
					'Webhook Custom Data',
					AUTOMATOR_DEBUG_MODE
				);
			}
		} else {
			// Log if the webhook triggered a different recipe or if recipe data is unexpected.
			automator_log(
				sprintf(
					'Webhook received but did not match expected Recipe ID. Current Recipe ID: %s',
					isset( $recipe['id'] ) ? $recipe['id'] : 'N/A'
				),
				'Webhook Mismatch',
				AUTOMATOR_DEBUG_MODE
			);
		}
	},
	10, // Priority: higher number means later execution
	3   // Accepted args: the number of arguments this callback function accepts
);
?>

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

uncanny-automator-pro/src/core/webhook/webhook-rest-handler.php:432

'uncanny_automator_pro_wp_webhook',
			array( $_hooks, $recipe ),
			'3.6',
			'automator_pro_run_webhook'
		);

		try {
			do_action( 'automator_pro_run_webhook', $_hooks, $recipe, $data );
		} catch ( Error $e ) {
			automator_log( $e->getMessage(), '', AUTOMATOR_DEBUG_MODE, 'automator_pro_run_webhook' );
		} catch ( Exception $e ) {
			automator_log( $e->getMessage(), '', AUTOMATOR_DEBUG_MODE, 'automator_pro_run_webhook' );
		}

		// Handle custom response configuration.


Scroll to Top