webhook2xmpp/classes/webhook.php
2021-05-15 11:38:03 +02:00

72 lines
1.5 KiB
PHP

<?php
namespace classes;
use classes\webhook_comp\discord;
use classes\webhook_comp\grafana;
class webhook extends core
{
private $json;
private $comp;
public function __construct(string $json,string $comp)
{
parent::__construct();
if($json)
{
$this->comp = $comp;
$this->json = json_decode($json, false);
}
else
{
throw new \Exception("JSON is required to use this class");
}
}
public function getMessage()
{
if($this->comp === "gitea")
{
$comp = new discord($this->json);
return($comp->readableMessage());
}
if($this->comp === "grafana")
{
$comp = new grafana($this->json);
return($comp->readableMessage());
}
if(isset($this->json->text))
{
return $this->json->text;
}
if(isset($this->json->message) && isset($this->json->imageUrl))
{
return $this->json->message . PHP_EOL . $this->json->imageUrl;
}
if(isset($this->json->message))
{
return $this->json->message;
}
throw new \Exception("Error not compatible query!");
}
public function getEventFilter()
{
if(isset($this->json->event) && $this->json->event)
{
return $this->json->event;
}
elseif(isset($_GET['event']) && $_GET['event'])
{
return $_GET['event'];
}
return false;
}
}
?>