From 63f95b63d0165de31b72be3fa2a0e57a6dc8d30f Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Fri, 17 Feb 2023 11:28:22 +1300 Subject: [PATCH] Changed webhook to allow for a custom object or string to be returned from the called script defaulting to msg:success --- src/webhooks/assets/testscript.php | 3 +++ src/webhooks/webhook.php | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/webhooks/assets/testscript.php b/src/webhooks/assets/testscript.php index 4e9f6dae..98413b74 100644 --- a/src/webhooks/assets/testscript.php +++ b/src/webhooks/assets/testscript.php @@ -18,3 +18,6 @@ $db->insert("logs",["logtype"=>"script test","lognote"=>"Did it work?"]); dnd($data); + +//If you set $return_object as an object or string then this will be returned +//instead of {msg:"success"} diff --git a/src/webhooks/webhook.php b/src/webhooks/webhook.php index b035db4b..f947becb 100644 --- a/src/webhooks/webhook.php +++ b/src/webhooks/webhook.php @@ -142,7 +142,12 @@ } $action = performWebhookAction($webhook->id,$webhook->action_type,$webhook->action,$data); -$msg['msg'] = $action; +if (is_string($action)) { + $msg['msg'] = $action; +} else { + $msg=$action; + $action=json_encode($msg); +} $fields = [ 'hook'=>$webhook->id, 'ip'=>$ip, @@ -175,7 +180,8 @@ function performWebhookAction($id,$action_type,$action,$data){ }elseif($action_type == "php"){ if(file_exists($abs_us_root.$us_url_root."usersc/plugins/webhooks/assets/".$action)){ require_once($abs_us_root.$us_url_root."usersc/plugins/webhooks/assets/".$action); - return "success"; + if(empty($return_object)) return "success"; + else return $return_object; }else{ return "File not found"; }