Filter
uncanny-automator
automator_whatsapp_timestamp_validation_enabled
Disable timestamp validation. Otherwise, you may completely disable the timestamp validation. Filters timestamp validation for WhatsApp messages, allowing users to disable it.
add_filter( 'automator_whatsapp_timestamp_validation_enabled', $callback, 10, 1 );
Description
This filter hook, `automator_whatsapp_timestamp_validation_enabled`, controls timestamp validation for WhatsApp messages. Developers can use it to disable validation by returning `false`, preventing potential issues with message timing. The hook fires before the timestamp is checked against an acceptable interval.
Usage
add_filter( 'automator_whatsapp_timestamp_validation_enabled', 'your_function_name', 10, 1 );
Parameters
-
$response(mixed) - - **$this** `mixed`
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to disable WhatsApp timestamp validation.
*
* By default, the `automator_whatsapp_timestamp_validation_enabled` filter
* is set to `true`, meaning timestamps are validated. This example
* demonstrates how to return `false` to disable this validation entirely.
* This might be useful for debugging or in specific scenarios where
* you are certain about the timestamp integrity.
*/
add_filter( 'automator_whatsapp_timestamp_validation_enabled', function ( $enable_validation, $response, $whatsapp_helper_instance ) {
// In this specific example, we'll always disable validation.
// In a real-world scenario, you might check conditions based on
// the $response or properties of $whatsapp_helper_instance.
return false;
}, 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/integrations/whatsapp/helpers/whatsapp-helpers.php:253
public function extract_receiving_message_response( $response = array() ) {
$timestamp = $response['entry'][0]['changes'][0]['value']['messages'][0]['timestamp'];
/**
* Prevent spammy WhatsApp webhook. This is an old issue where WhatsApp repeatedly sends the webhook payload to the URL.
* We have to do this to safe guard the users and not let WhatsApp spam their logs with incoming webhooks.
* By default, its enabled.
*
* When the Trigger is erratically firing,
* try increasing the acceptable interval first via 'automator_whatsapp_acceptable_interval'
*
* @default int 5 - Five seconds.
* @filter automator_whatsapp_acceptable_interval
**/
$acceptable_interval = apply_filters( 'automator_whatsapp_acceptable_interval', 5, $response, $this );
/**
* Disable timestamp validation.
*
* Otherwise, you may completely disable the timestamp validation.
*
* @default true
* @filter automator_whatsapp_timestamp_validation_enabled
*/
$timestamp_validation = apply_filters( 'automator_whatsapp_timestamp_validation_enabled', true, $response, $this );
if ( true === $timestamp_validation && ! $this->is_timestamp_acceptable( $timestamp, $acceptable_interval ) ) {
throw new Exception( 'Stale data: WhatsApp Bug. Do not process.' );
}
$default = array(
'from' => '',
'wamid' => 0,
'body' => '',
'timestamp' => '',
);
$message = $response['entry'][0]['changes'][0]['value']['messages'][0];
$text_body = $this->extract_message( $message );
$args = array(
'from' => $message['from'],
'wamid' => $message['id'],
'body' => $text_body,
'timestamp' => $timestamp,
'_response' => $response, // Send the whole response to the Trigger.
);
do_action( 'automator_whatsapp_webhook_message_received', $args );
return wp_parse_args( $args, $default );
}