diff --git a/config.example.php b/config.example.php index 50fb977..e4b58b6 100644 --- a/config.example.php +++ b/config.example.php @@ -25,4 +25,6 @@ "DOMAIN_OA" => "@oa", "DOMAIN_CA" => "@ca" ]); -define("MAIL_SUPPORT","");//If not empty, use this value to send to the Support team: card url, the description and who submitted the request. \ No newline at end of file +define("MAIL_SUPPORT","");//If not empty, use this value to send to the Support team: card url, the description and who submitted the request. + +define("ROCKETCHAT_WEBHOOK", ""); //add rocketchat notification webhook diff --git a/lib/CreateCardClass.php b/lib/CreateCardClass.php index 8826e0a..540976e 100644 --- a/lib/CreateCardClass.php +++ b/lib/CreateCardClass.php @@ -86,6 +86,10 @@ function createCard($newcard, $data, $mailSender, $cleanedSubject, $inbox, $boar $response = $newcard->addCard($data, $mailSender->origin, $mailSender->host, $board); error_log("New card created with response: " . json_encode($response)); + if ($response && defined('ROCKETCHAT_WEBHOOK')){ + $this->notifyRocketChat($response); + } + if($data->attachments){ $imageUrls = $newcard->addAttachments($response, $data->attachments); if (!empty($imageUrls)) { @@ -106,4 +110,29 @@ function createCard($newcard, $data, $mailSender, $cleanedSubject, $inbox, $boar error_log("Comment added with response: " . json_encode($response)); } } -} \ No newline at end of file + + function notifyRocketChat($card){ + $cardUrl = NC_SERVER . "/index.php/apps/deck/board/{$card->board}/card/{$card->id}"; + $boardTitle = $card->boardTitle ?? "Deck"; + $payload = json_encode([ + 'text' => "New ticket on **{$boardTitle}**\n[{$card->title}]({$cardUrl})" + ]); + + $curl = curl_init(); + curl_setopt_array($curl, [ + CURLOPT_URL => ROCKETCHAT_WEBHOOK, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $payload, + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_TIMEOUT => 5, + ]); + + $resp = curl_exec($curl); + if (curl_errno($curl)) { + error_log("RocketChat notify error: " . curl_error($curl)); + } + + curl_close($curl); + } +}