PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.8.1
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.8.1
8.8.1 8.8.0 8.7.9 8.7.8 8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 All 537 releases
chatbot / addons / automator / includes / triggers / webhook.php

webhook.php in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 8.8.1, at addons/automator/includes/triggers/webhook.php

70 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Webhook Trigger
4 *
5 * @package WPbot_Automator
6 */
7
8 namespace WPbot_Automator\Triggers;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Class Webhook
16 */
17 class Webhook extends Trigger {
18
19 /**
20 * Constructor
21 */
22 public function __construct() {
23 $this->id = 'webhook';
24 $this->group = __( 'Universal', 'wpbot-automator' );
25 $this->title = __( 'Webhook Trigger', 'wpbot-automator' );
26 }
27
28 /**
29 * Register the triggers
30 */
31 public function register() {
32 add_action( 'rest_api_init', array( $this, 'register_webhook_route' ) );
33 }
34
35 /**
36 * Register REST API route for incoming webhooks
37 */
38 public function register_webhook_route() {
39 register_rest_route(
40 'wpbot-automator/v1',
41 '/webhook/(?P<token>[a-zA-Z0-9]+)',
42 array(
43 'methods' => array( 'GET', 'POST' ),
44 'callback' => array( $this, 'handle_webhook' ),
45 'permission_callback' => '__return_true', // Webhooks are usually public or handled by token
46 )
47 );
48 }
49
50 /**
51 * Handle incoming webhook
52 */
53 public function handle_webhook( $request ) {
54 $token = $request->get_param( 'token' );
55 $data = $request->get_params();
56
57 $this->run( array(
58 'sub_id' => 'incoming_webhook',
59 'data' => array_merge( $data, array(
60 'target_node_id' => 'node-' . $token,
61 ) ),
62 ) );
63
64 return rest_ensure_response( array(
65 'success' => true,
66 'message' => 'Webhook received and workflow triggered.',
67 ) );
68 }
69 }
70