Filter
Dynamic
uncanny-automator-pro
automator_pro_webhook_response_{$recipe['ID']}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the webhook response data for a specific Automator Pro recipe before it's sent.
add_filter( 'automator_pro_webhook_response_{$recipe['ID']}', $callback, 10, 4 );
Description
Fires after Uncanny Automator processes a webhook for a specific recipe. Developers can modify the webhook response data, affecting what's sent back to the webhook sender. This hook is dynamic, with the recipe ID included in its name. Access recipe details and the original data for context.
Usage
add_filter( 'automator_pro_webhook_response_{$recipe['ID']}', 'your_function_name', 10, 4 );
Parameters
-
$response_data(mixed) - This parameter contains the data that will be sent back as the webhook response.
-
$_hooks(mixed) - This parameter contains the response data that will be sent back to the webhook caller.
-
$recipe(mixed) - This parameter contains an array of all hooks that were executed for the current recipe.
-
$data(mixed) - This parameter contains the recipe object that triggered the webhook, providing access to its specific settings and configurations.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the webhook response data for a specific Uncanny Automator Pro recipe.
* This function might be used to modify the JSON response sent back to the webhook caller,
* for instance, to include or exclude specific data points based on the recipe's ID.
*
* @param mixed $response_data The original response data to be sent.
* @param mixed $_hooks An array or object containing information about the hooks triggered.
* @param array $recipe An array containing details about the Uncanny Automator recipe.
* @param array $data An array containing the data passed to the webhook.
*
* @return mixed The modified response data.
*/
add_filter(
'automator_pro_webhook_response_123', // Replace 123 with the actual Recipe ID you want to target.
function( $response_data, $_hooks, $recipe, $data ) {
// Ensure $response_data is an array or can be treated as one for modification.
if ( ! is_array( $response_data ) ) {
// If it's not an array, try to decode it if it's JSON, or initialize it.
if ( is_string( $response_data ) ) {
$decoded_data = json_decode( $response_data, true );
if ( json_last_error() === JSON_ERROR_NONE ) {
$response_data = $decoded_data;
} else {
// If it's not valid JSON, maybe it's a simple string or a single value.
// For this example, let's assume we want to wrap it in an array.
$response_data = array( 'original_response' => $response_data );
}
} else {
$response_data = array( 'original_response' => $response_data );
}
}
// Example: If the recipe ID is 123, and the original data contained a 'user_id',
// let's add a custom message to the response.
if ( isset( $data['user_id'] ) ) {
$response_data['custom_message'] = 'Thank you for the data for user ID: ' . $data['user_id'];
}
// Example: Remove a specific field from the response if it exists.
if ( isset( $response_data['internal_debug_info'] ) ) {
unset( $response_data['internal_debug_info'] );
}
// You could also conditionally add data based on the recipe itself or $_hooks if needed.
// For example, if a specific hook was triggered:
// if ( isset( $_hooks['specific_hook_name'] ) ) {
// $response_data['hook_specific_data'] = 'This was added because of a specific hook.';
// }
// Return the modified response data.
return $response_data;
},
10, // Priority: standard priority for filters.
4 // Accepted arguments: $response_data, $_hooks, $recipe, $data.
);
?>
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:487
}
} catch ( Exception $e ) {
automator_log( $e->getMessage(), '', AUTOMATOR_DEBUG_MODE, 'automator_pro_webhook_response' );
}
}
}
$response_data = apply_filters(
"automator_pro_webhook_response_{$recipe['ID']}",
$response_data,
$_hooks,
$recipe,
$data
);
$response_headers = apply_filters(