Filter uncanny-automator

automator_outgoing_webhook_value_of_type_int

Filters the integer value sent in an outgoing webhook before it is processed.

add_filter( 'automator_outgoing_webhook_value_of_type_int', $callback, 10, 3 );

Description

Fires after determining a webhook value is of type 'int'. Developers can modify the 'int' type string, the webhook key, or the integer value itself before it's sent. Use this to customize how numerical data is represented in outgoing webhooks.


Usage

add_filter( 'automator_outgoing_webhook_value_of_type_int', 'your_function_name', 10, 3 );

Parameters

$type (mixed)
This parameter specifies the default type of the webhook value, which is 'text' if not otherwise determined.
$key (mixed)
The expected data type of the webhook value.
$value (mixed)
This parameter represents the key associated with the value being processed for the outgoing webhook.

Return Value

The filtered value.


Examples

/**
 * Example of how to modify an outgoing webhook value when it's detected as an integer.
 *
 * This filter allows you to intercept and potentially alter the value of a webhook
 * payload before it's sent, specifically when the system identifies the value as an integer.
 * For instance, you might want to ensure all integers are sent as strings or perform
 * some kind of formatting.
 *
 * @param mixed $type The detected type of the webhook value (will be 'int' here).
 * @param mixed $key  The key associated with the value in the webhook payload.
 * @param mixed $value The actual value being sent.
 *
 * @return mixed The potentially modified value.
 */
add_filter( 'automator_outgoing_webhook_value_of_type_int', function( $type, $key, $value ) {

    // Example: If the key is 'user_id', ensure it's always sent as a string
    // to avoid potential issues with systems expecting string identifiers.
    if ( 'user_id' === $key ) {
        $value = (string) $value;
    }

    // Example: If the key is 'order_count', double the value before sending.
    if ( 'order_count' === $key ) {
        $value = $value * 2;
    }

    // Return the (potentially modified) value.
    return $value;

}, 10, 3 );

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/lib/webhooks/class-automator-send-webhook.php:1101

public static function value_maybe_of_type( $key, $value ) {
		$type = 'text';

		if ( is_array( $value ) || is_object( $value ) ) {
			return apply_filters( 'automator_outgoing_webhook_value_of_type_array', $type, $key, $value );
		}

		if ( is_email( $value ) ) {
			$type = 'email';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_email', $type, $key, $value );
		}

		if ( is_float( $value ) ) {
			$type = 'float';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_float', $type, $key, $value );
		}

		if ( is_numeric( $value ) ) {
			$type = 'int';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_int', $type, $key, $value );
		}

		if ( wp_http_validate_url( $value ) ) {
			$type = 'url';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_url', $type, $key, $value );
		}

		return apply_filters( 'automator_outgoing_webhook_value_of_type_text', $type, $key, $value );
	}


Scroll to Top