Posteingang: Antwortbezug ohne Klammern, Testadresse im Testbetrieb, sofortige Auswertung
Deploy FeWo mit PipelineManager / deploy (push) Successful in 5m6s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 5m6s
- Antwortbezug (In-Reply-To/References) wird mit und ohne spitze Klammern verglichen – Strato liefert ihn ohne, gespeichert war er mit; Antworten blieben deshalb im Posteingang hängen. - Testbetrieb: Die Testadresse steht zusammen mit der genannten Vorgangsnummer für den Gast dieses Vorgangs (alle Antworten kommen vom Testpostfach). Im Live-Betrieb gilt das nicht. - Eine zugeordnete Nachricht wird sofort ausgewertet (automatisch und nach Zuordnung von Hand), nicht erst im Fünf-Minuten-Lauf; die Meldung nennt, was übernommen wurde. Neu: „Erneut auswerten“. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f4a435c71a
commit
ad63db78f3
6 files changed
+78
-11
No files matched your search
@@ -11,6 +11,7 @@
|
||||
use App\Process\CaseLog;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Database\UniqueConstraintViolationException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* The inbox of v0.11 (S2/S3, CH-01, CH-06, CH-08): every message of the landlord's dedicated mailbox is stored first,
|
||||
@@ -79,8 +80,22 @@ public function handle(PortalMail $mail, ?Mailbox $mailbox = null): InboundMessa
|
||||
CaseLog::record($booking, 'mail_in', 'E-Mail des Gastes eingegangen'.($message->test_mode ? ' (im Testbetrieb)' : '').': '.$message->subject, actor: CaseLog::GUEST, at: $message->received_at);
|
||||
$this->requests->replyReceived($booking);
|
||||
BookingTask::openOnce($booking, BookingTaskKind::InboundReview, 'm'.$message->id, ['due_on' => today(), 'note' => '„'.mb_substr((string) $message->subject, 0, 120).'“ – im Posteingang ansehen; erkannte Angaben werden dort zur Übernahme vorgeschlagen.']);
|
||||
// Evaluate at once instead of waiting for the next five-minute run (the run remains the safety net).
|
||||
$this->evaluate($message);
|
||||
|
||||
return $message;
|
||||
return $message->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the extraction for a freshly assigned message; a problem never undoes the assignment.
|
||||
*/
|
||||
public function evaluate(InboundMessage $message): void
|
||||
{
|
||||
try {
|
||||
app(ExtractMessageFacts::class)->handle($message->refresh());
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
use App\Models\BookingMessage;
|
||||
use App\Models\InboundMessage;
|
||||
use App\Models\Property;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
@@ -30,7 +31,9 @@ public function match(InboundMessage $message): array
|
||||
$sender = mb_strtolower(trim((string) $message->from_address));
|
||||
$text = $message->subject."\n".$message->body;
|
||||
|
||||
$references = array_values(array_filter([$message->in_reply_to, ...((array) $message->references)]));
|
||||
// Message-IDs are compared with and without angle brackets (mail servers deliver both forms).
|
||||
$references = collect([$message->in_reply_to, ...((array) $message->references)])->filter()
|
||||
->flatMap(fn (string $id): array => ['<'.trim($id, '<> ').'>', trim($id, '<> ')])->unique()->values()->all();
|
||||
if ($references !== []) {
|
||||
$replied = BookingMessage::query()->whereIn('message_id', $references)->whereNotNull('booking_id')->latest('id')->first()?->booking;
|
||||
if ($replied !== null) {
|
||||
@@ -39,8 +42,13 @@ public function match(InboundMessage $message): array
|
||||
}
|
||||
|
||||
$hints = [];
|
||||
// In test operation every answer comes from the test mailbox: there it stands for the guest of the named case.
|
||||
$testSender = $message->test_mode && $sender !== '' && $sender === mb_strtolower(trim((string) Settings::tenant()?->test_recipient));
|
||||
if (preg_match_all('/\b(20\d{2}-\d{4})\b/', $text, $numbers)) {
|
||||
foreach (Booking::query()->whereIn('reference', array_unique($numbers[1]))->with('guest')->get() as $booking) {
|
||||
if ($testSender) {
|
||||
return ['booking' => $booking, 'reason' => 'reference_test_sender', 'hints' => []];
|
||||
}
|
||||
if ($sender !== '' && mb_strtolower((string) $booking->guest?->email) === $sender) {
|
||||
return ['booking' => $booking, 'reason' => 'reference_and_sender', 'hints' => []];
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Actions\ContributeCaseFacts;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\ReceiveInboundMessage;
|
||||
use App\Actions\RequestCaseData;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
@@ -137,7 +138,15 @@ public static function table(Table $table): Table
|
||||
CaseLog::record($booking, 'mail_in', 'E-Mail von Ihnen zugeordnet: '.$record->subject);
|
||||
$requests->replyReceived($booking);
|
||||
BookingTask::openOnce($booking, BookingTaskKind::InboundReview, 'm'.$record->id, ['due_on' => today(), 'note' => '„'.mb_substr((string) $record->subject, 0, 120).'“ – im Posteingang ansehen.']);
|
||||
Notification::make()->title('Zugeordnet')->success()->send();
|
||||
app(ReceiveInboundMessage::class)->evaluate($record);
|
||||
Notification::make()->title('Zugeordnet')->body(self::evaluationSummary($record->fresh()))->success()->send();
|
||||
}),
|
||||
Action::make('evaluateAgain')->label('Erneut auswerten')->icon(Heroicon::OutlinedArrowPath)->color('gray')
|
||||
->visible(fn (InboundMessage $record): bool => $record->booking_id !== null && in_array($record->extraction_status, ['failed', 'disabled'], true))
|
||||
->action(function (InboundMessage $record): void {
|
||||
$record->update(['extraction_status' => null]);
|
||||
app(ReceiveInboundMessage::class)->evaluate($record);
|
||||
Notification::make()->title('Ausgewertet')->body(self::evaluationSummary($record->fresh()))->send();
|
||||
}),
|
||||
Action::make('createInquiry')->label('Als neue Anfrage anlegen')->icon(Heroicon::OutlinedPlus)
|
||||
->visible(fn (InboundMessage $record): bool => $record->status === InboundMessage::NEEDS_REVIEW)
|
||||
@@ -204,6 +213,22 @@ public static function table(Table $table): Table
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* What the evaluation of a message did, in one sentence.
|
||||
*/
|
||||
public static function evaluationSummary(InboundMessage $message): string
|
||||
{
|
||||
$applied = collect((array) ($message->extraction['applied'] ?? []))->map(fn (array $fact): string => CaseRequirements::label($fact['field']))->implode(', ');
|
||||
$proposed = count((array) ($message->extraction['proposed'] ?? []));
|
||||
|
||||
return match ($message->extraction_status) {
|
||||
'done' => ($applied !== '' ? 'Übernommen: '.$applied.'.' : 'Keine Angaben automatisch übernommen.').($proposed > 0 ? ' '.$proposed.' Vorschlag/Vorschläge zu prüfen.' : ''),
|
||||
'disabled' => 'Keine automatische Auswertung (System › KI-Anbindung nicht eingerichtet oder abgelehnt).',
|
||||
'failed' => 'Die automatische Auswertung war nicht möglich: '.($message->extraction['error'] ?? 'unbekannter Fehler'),
|
||||
default => 'Wird ausgewertet.',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cases to assign a message to: the hints first, then the open cases.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user