Portal-Synchronisation: unser System führt
- Connector-System (app/Channels, config/channels.php) mit iCal-Connector, robustem Parser und Export-Feed je Portal (ohne eigene Belegungen, ohne Gästedaten) - Abgleich alle 5 Min. mit Protokoll, Echo-Erkennung, Konflikt-Mail bei möglicher Doppelbuchung - Überwachung: Störungs-Mail, Status-Endpunkt /health/sync für n8n - Portal-Aufgaben für Sofortbuchungsportale (FeWo-direkt): automatisch aus Buchungen/Sperren/anderen Portalen, Mail + Erinnerung, Abhaken im Admin - Optionaler signierter Automatisierungs-Webhook mit Rückmeldung - Herkunftsmessung: Abfrage im Formular + UTM-Parameter - Portal-Analyse: AGB-Prüfung Automatisierung, Umsetzungsbeschreibung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a8e72715ab
commit
0b7205e050
55 files changed
+2290
-3
No files matched your search
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Channels\ICal\ICalFeed;
|
||||
use App\Enums\ChannelTaskStatus;
|
||||
use App\Models\Channel;
|
||||
use App\Models\ChannelTask;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
/**
|
||||
* Public endpoints of the channel synchronisation: export feeds for portals, the health check for
|
||||
* external monitoring and the callback of the optional blocking automation.
|
||||
*/
|
||||
class ChannelController extends Controller
|
||||
{
|
||||
public function feed(string $token, ICalFeed $feed): Response
|
||||
{
|
||||
$channel = Channel::query()->where('export_token', $token)->where('is_active', true)->firstOrFail();
|
||||
|
||||
return response($feed->build($channel), 200, [
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
'Content-Disposition' => 'inline; filename="belegung.ics"',
|
||||
'Cache-Control' => 'no-cache, max-age=0',
|
||||
]);
|
||||
}
|
||||
|
||||
public function health(Request $request): JsonResponse
|
||||
{
|
||||
$token = config('fewo.channels.health_token');
|
||||
abort_if(blank($token) || ! hash_equals($token, (string) $request->query('token')), 404);
|
||||
|
||||
$channels = Channel::query()->active()->get()->map(fn (Channel $channel): array => [
|
||||
'name' => $channel->name,
|
||||
'imports' => $channel->importsOccupations(),
|
||||
'ok' => ! $channel->isStale(),
|
||||
'last_success_at' => $channel->last_success_at?->toIso8601String(),
|
||||
'last_error' => $channel->last_error,
|
||||
]);
|
||||
$openTasks = ChannelTask::query()->open()->count();
|
||||
|
||||
$ok = $channels->every(fn (array $channel): bool => $channel['ok']);
|
||||
|
||||
return response()->json([
|
||||
'status' => $ok ? 'ok' : 'degraded',
|
||||
'open_tasks' => $openTasks,
|
||||
'channels' => $channels->values(),
|
||||
], $ok ? 200 : 503);
|
||||
}
|
||||
|
||||
/**
|
||||
* The automation reports a task as done. The raw body must be signed like the outgoing webhook.
|
||||
*/
|
||||
public function completeTask(Request $request, ChannelTask $task): JsonResponse
|
||||
{
|
||||
$secret = config('fewo.automation.secret');
|
||||
$signature = (string) $request->header('X-Signature');
|
||||
abort_if(blank($secret) || ! hash_equals(hash_hmac('sha256', $request->getContent(), $secret), $signature), 403);
|
||||
|
||||
if ($task->status === ChannelTaskStatus::Open) {
|
||||
$task->complete('Automatisierung');
|
||||
}
|
||||
|
||||
return response()->json(['status' => $task->status->value]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user