Add Slack customer registration notification functionality

This commit is contained in:
Jeppe Bundgaard
2026-06-08 12:42:03 +02:00
parent bedbf21c29
commit 91d3332d4e
11 changed files with 414 additions and 2 deletions
+47 -1
View File
@@ -6,13 +6,25 @@ use GuzzleHttp\Client;
use interfaces\notification_i;
use objects\departments_o;
use objects\users_o;
use slack\slack_c;
use traits\notification_t;
require_once WD . '/modules/slack/slack_c.php';
class slack implements notification_i
{
use notification_t;
private ?slack_c $config = null;
public function getConfig(): slack_c
{
if ($this->config === null) {
$this->config = new slack_c();
}
return $this->config;
}
/**
* @inheritdoc
@@ -132,4 +144,38 @@ class slack implements notification_i
// Send the message to the slack webhook
self::add_log(self::send_webhook_message($string, $SLACK_DEFAULT_WEBHOOK));
}
}
public function send_customer_registration_notification(int $customer_number): self
{
$webhook = trim((string)$this->getConfig()->customer_registration_webhook_url->getVariableValue());
if ($webhook === '') {
return $this;
}
self::add_log(self::send_webhook_message(
$this->format_customer_registration($customer_number),
$webhook
));
return $this;
}
public function format_customer_registration(int $customer_number): string
{
$customer = (new users_o())->getUserByCustomerNumber($customer_number);
$customerName = $customer->exists()
? $customer->getCustomerName((int)$customer->customer_number->value())
: '';
$customerName = trim((string)$customerName);
if ($customerName === '') {
$customerName = 'Unknown customer';
}
$safeCustomerNumber = (int)$customer_number;
$customerUrl = 'https://truckwash.io/superuser/users?search=' . $safeCustomerNumber;
return "*New customer registered on Truck Wash*\n"
. "Customer: $customerName ($safeCustomerNumber)\n"
. "Open in Superuser: $customerUrl";
}
}