Skip to main content

MissingInfo-Mailflow

App\Services\Grenke\MissingInfoMailFlowService

Wenn ein Grenke-Request während des Pollings den State MissingInfo erreicht, schickt der Service automatisch eine Mail an den Lessee. Der Mail-Body kommt aus einem Weclapp-Mail-Template.

Wie es im Flow ausgelöst wird

Konfiguration

config/grenke.php:

'missing_info_mailflow' => [
'enabled' => env('GRENKE_MISSING_INFO_MAILFLOW_ENABLED', true),
'template_id' => env('GRENKE_MISSING_INFO_WECLAPP_TEMPLATE_ID', null),
'cc' => array_filter(array_map('trim', explode(',', env('GRENKE_MISSING_INFO_CC', '')))),
'bcc' => array_filter(array_map('trim', explode(',', env('GRENKE_MISSING_INFO_BCC', '')))),
'deduplicate_hours' => (int) env('GRENKE_MISSING_INFO_DEDUPLICATE_HOURS', 24),
'store_rendered_view' => env('GRENKE_MISSING_INFO_STORE_RENDERED_VIEW', false),
],

.env:

GRENKE_MISSING_INFO_MAILFLOW_ENABLED=true
GRENKE_MISSING_INFO_WECLAPP_TEMPLATE_ID=12345
GRENKE_MISSING_INFO_CC=cc1@bluesafety.com,cc2@bluesafety.com
GRENKE_MISSING_INFO_BCC=
GRENKE_MISSING_INFO_DEDUPLICATE_HOURS=24
GRENKE_MISSING_INFO_STORE_RENDERED_VIEW=false

Deduplikation

Der Service speichert pro financingId einen Cache-Key (grenke_missing_info_mail_sent_<id>) für deduplicate_hours Stunden. So wird bei mehrfachen Polling-Runs nicht mehrfach Mail verschickt.

Mail-Variablen

MissingInfoMailFlowService::buildTemplateVariables() extrahiert aus dem Request und dem mailContext folgende Variablen, die im Weclapp-Template als ..variableName.. referenziert werden können:

VariableQuelle
formalSalutationabgeleitet (companyName → "Sehr geehrte …")
companyNamelessee.companyName
email, lesseeEmaillessee.email
lesseeNamelessee.companyName
financingIdaus DTO
requestIdaus DTO
stateRequestState::value
productType
paymentMethod
paymentFrequency
financingAmount
period
quoteNote
currentDatenow()->format('d.m.Y')
technicianAppointmentbool aus Context
technicianAppointmentDate$mailContext['technician_appointment_date']
technicianAppointmentTime$mailContext['technician_appointment_time']

Mail-Context aus dem Controller

$result = $this->waitForGrenkeReadyToSignAction->execute(
financingId: $financingId,
mailContext: [
'technician_appointment_date' => $request->input('technician_appointment_date'),
'technician_appointment_time' => $request->input('technician_appointment_time'),
],
);

Template-Syntax (Weclapp → Blade)

Der WeclappTemplateRendererService übersetzt Weclapp-Template-Syntax in Blade:

WeclappBlade
..companyName..{{ $companyName ?? "" }}
[[if technicianAppointment]] … [[endif]]@if(!empty($technicianAppointment)) … @endif
[[ifnot technicianAppointment]] … [[endif]]@if(empty($technicianAppointment)) … @endif

Snake-case Variablen aus Weclapp werden zu camelCase umgewandelt (technician_appointmenttechnicianAppointment).

Mehr dazu unter Weclapp Template-Renderer.

Disable im Test

config(['grenke.missing_info_mailflow.enabled' => false]);

oder per .env.testing:

GRENKE_MISSING_INFO_MAILFLOW_ENABLED=false

Im Service wird das geprüft:

if (!config('grenke.missing_info_mailflow.enabled', true)) {
Log::info('Grenke MissingInfo Mailflow deaktiviert.');
return;
}

Optional: Rendered HTML speichern

Mit GRENKE_MISSING_INFO_STORE_RENDERED_VIEW=true wird der gerenderte HTML-Body unter storage/app/grenke/mails/missing-info-<financingId>.html abgelegt — gut für Debugging.