Filter uncanny-automator

automator_meta_webhook_endpoint

Filters the WhatsApp webhook endpoint URL before it's registered to allow customization of the endpoint.

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

Description

Filters the WhatsApp webhook endpoint URL. Developers can use this hook to customize the default '/whatsapp' endpoint for receiving webhook notifications from WhatsApp. This allows for flexible integration and routing of incoming messages.


Usage

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

Parameters

$this (mixed)
This parameter contains the default path for the WhatsApp webhook endpoint.

Return Value

The filtered value.


Examples

<?php
/**
 * Filters the WhatsApp webhook endpoint to include a specific identifier for authenticated requests.
 *
 * This example adds a query parameter to the webhook endpoint if a specific nonce
 * is present and valid, indicating an authenticated request from the Automator plugin.
 * This can help in differentiating internal requests from external ones or for
 * security purposes.
 *
 * @param string $endpoint The default webhook endpoint.
 * @param object $this     The current object instance, likely a WhatsApp integration class.
 * @return string The modified webhook endpoint.
 */
add_filter( 'automator_meta_webhook_endpoint', function ( $endpoint, $this ) {

	// Check if a specific nonce is set and is valid.
	// This is a hypothetical check, replace with actual nonce verification logic if needed.
	if ( isset( $_REQUEST['automator_nonce'] ) && wp_verify_nonce( $_REQUEST['automator_nonce'], 'automator_whatsapp_webhook' ) ) {
		// Append a query parameter to signify an authenticated request.
		$endpoint .= '?authenticated=true';
	}

	return $endpoint;

}, 10, 2 );
?>

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:88

public function __construct() {

		// Disconnect.
		add_action( 'wp_ajax_automator_whatsapp_disconnect', array( $this, 'disconnect' ) );

		// Regenerate webhoook.
		add_action( 'wp_ajax_whatsapp-regenerate-webhook-key', array( $this, 'regenerate_webhook_key_ajax' ) );

		// The webhook's rest api endpoint.
		add_action( 'rest_api_init', array( $this, 'init_webhook' ) );

		// Flush expired transients.
		add_action( 'automator_whatsapp_flush_transient', array( $this, 'flush_transient' ) );

		// Message templates dropdown.
		add_action( 'wp_ajax_automator_whatsapp_list_message_templates', array( $this, 'list_message_templates' ) );

		// Message templates fields retrieval.
		add_Action( 'wp_ajax_automator_whatsapp_retrieve_template', array( $this, 'retrieve_template' ) );

		// Load the settings page.
		require_once __DIR__ . '/../settings/settings-whatsapp.php';

		// Webhook endpoint.
		$this->webhook_endpoint = apply_filters( 'automator_meta_webhook_endpoint', '/whatsapp', $this );

		$this->whatsapp_settings = new WhatsApp_Settings( $this );
	}

Scroll to Top