Add ntfy.sh push notifications for booking events

Sends instant push notification on new booking, modification, and
cancellation. Set ntfy_topic in application/config/google_calendar.php
to activate. No-ops silently if topic is empty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 15:21:13 +01:00
co-authored by Claude Sonnet 4.6
parent ae890c81ee
commit a71dc8d801
2 changed files with 40 additions and 0 deletions
+1
View File
@@ -3,3 +3,4 @@ defined('BASEPATH') OR exit('No direct script access allowed');
$config['gcal_service_account_path'] = APPPATH . 'config/service-account-key.json';
$config['gcal_evelin_calendar_id'] = 'katozoltan0804@gmail.com'; // Evelin's Calendar ID (e.g. her Gmail address)
$config['ntfy_topic'] = ''; // ntfy.sh topic for push notifications (e.g. 'studiobeve-bookings-x7k2')
+39
View File
@@ -460,6 +460,15 @@ class Pages extends CI_Controller {
$this->Service_model->updateBookingCalEvents($newBooking->booking_id, $workerEventId, $ownerEventId);
}
// ntfy push notification
$gcalServiceNamesNtfy = implode(', ', array_map(function($s){ return $s->service_name_no; }, $serviceArray));
$this->_ntfy(
'New booking: ' . $bookingArray['guest_name'],
'Worker: ' . $worker->worker_name . "\n" .
'Date: ' . $bookingArray['booking_date'] . ' ' . $bookingArray['booking_start_time'] . ' - ' . $bookingArray['booking_finish_time'] . "\n" .
'Services: ' . $gcalServiceNamesNtfy
);
$content = '';
switch($_POST['lang']){
@@ -880,6 +889,14 @@ class Pages extends CI_Controller {
}
$this->Service_model->updateBookingCalEvents($booking->booking_id, $newWorkerEventId, $newOwnerEventId);
// ntfy push notification
$this->_ntfy(
'Modified booking: ' . $booking->guest_name,
'Worker: ' . $worker->worker_name . "\n" .
'Date: ' . $newBookingDate . ' ' . $newStartTime . ' - ' . $finishTime . "\n" .
'Services: ' . $gcalServiceNames
);
$manageLink = SITEURL.$lang.'/manage-booking/'.$token;
$totalServicePrice = 0;
foreach($serviceArray as $s){ $totalServicePrice += $s->service_price; }
@@ -1000,6 +1017,13 @@ class Pages extends CI_Controller {
$this->googlecalendar->deleteEvent($evelinCalId, $booking->gcal_event_id_owner);
}
// ntfy push notification
$this->_ntfy(
'Cancelled booking: ' . $booking->guest_name,
'Worker: ' . $worker->worker_name . "\n" .
'Date: ' . $booking->booking_date . ' ' . $booking->booking_start_time
);
$this->Service_model->deleteBooking($booking->booking_id);
$data['selectedLang'] = $lang;
@@ -1009,5 +1033,20 @@ class Pages extends CI_Controller {
$this->load->view('pages/manage-booking-cancelled', $data);
}
private function _ntfy($title, $message){
$this->config->load('google_calendar');
$topic = $this->config->item('ntfy_topic');
if(empty($topic)) return;
$ch = curl_init('https://ntfy.sh/' . $topic);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $message,
CURLOPT_HTTPHEADER => ['Title: ' . $title, 'Priority: high', 'Tags: calendar'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
]);
curl_exec($ch);
curl_close($ch);
}
}