Files
fewo-stommer/app/Process/Tester/Scenarios/MessageOtherMedium.php
T

64 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Process\Tester\Scenarios;
use App\Communication\IncomingMessage;
use App\Communication\MessageIntake;
use App\Enums\IntakeKind;
use App\Enums\Medium;
use App\Process\Tester\SandboxContext;
use Carbon\CarbonImmutable;
/**
* V2.1: a message of a guest arrives through another medium (WhatsApp or chat; no provider, only the entry). Shows how
* medium, reference and rules decide – assigned reply, unassignable message, contradictory reference – and that nothing
* is taken over or created by itself.
*/
final class MessageOtherMedium extends Scenario
{
public static function key(): string
{
return 'message_other_medium';
}
public static function label(): string
{
return 'Nachricht über WhatsApp oder Chat';
}
public static function description(): string
{
return 'Der Gast antwortet in einem anderen Medium – mit überprüftem Bezug, ohne Bezug oder mit widersprüchlicher Vorgangsnummer. Zeigt Zuordnung, Absicht und erlaubte Wirkung.';
}
public static function intakes(): array
{
return [IntakeKind::Inquiry, IntakeKind::Booking];
}
public static function inputs(): array
{
return [
...parent::inputs(),
'medium' => ['label' => 'Medium', 'default' => 'whatsapp', 'type' => 'select', 'options' => ['whatsapp' => 'WhatsApp', 'chat' => 'Chat']],
'reference' => ['label' => 'Bezug', 'default' => 'verified', 'type' => 'select', 'options' => ['verified' => 'überprüfter Bezug zum Vorgang', 'none' => 'kein Bezug (nur Absender)', 'contradicting' => 'überprüfter Bezug, Text nennt andere Nummer']],
'consent' => ['label' => 'Einwilligung des Gastes liegt vor', 'default' => true, 'type' => 'bool'],
];
}
public function events(array $inputs): array
{
return [
new ScenarioEvent('Anfrage des Gastes liegt vor', fn (SandboxContext $context) => $context->request([])),
new ScenarioEvent('Nachricht des Gastes im anderen Medium', function (SandboxContext $context) use ($inputs): void {
$reference = (string) ($inputs['reference'] ?? 'verified');
$text = 'Wir kommen am Anreisetag gegen 16 Uhr an.'.($reference === 'contradicting' ? ' Vorgang 2099-0001' : '');
app(MessageIntake::class)->handle(new IncomingMessage(
Medium::tryFrom((string) ($inputs['medium'] ?? 'whatsapp')) ?? Medium::WhatsApp, '+49170000000', $text, CarbonImmutable::now(), 'tester-'.md5($text),
$reference === 'none' ? null : $context->booking?->id, (bool) ($inputs['consent'] ?? true),
));
}),
];
}
}