fix(care): use clinic name as email From display, not Ladill Care
Deploy Ladill Care / deploy (push) Successful in 28s

Patient-facing suite (and Bird fallback) emails should appear from the
organization name. Stop defaulting from_name to CARE_SMTP_FROM_NAME.
Appointment notifications also prefer suite messaging with the same rule.
This commit is contained in:
isaacclad
2026-07-16 11:58:24 +00:00
parent 2a00d4321b
commit f7baa6ebf0
4 changed files with 79 additions and 33 deletions
@@ -5,6 +5,8 @@ namespace App\Services\Care;
use App\Models\Appointment;
use App\Models\Organization;
use App\Models\Patient;
use App\Services\Billing\PlatformEmailClient;
use App\Services\Billing\PlatformSmsClient;
use App\Services\Messaging\CustomerEmailClient;
use App\Services\Messaging\CustomerSmsClient;
use App\Services\Messaging\MessagingCredentialsService;
@@ -25,6 +27,8 @@ class AppointmentPatientNotifier
private MessagingCredentialsService $credentials,
private CustomerSmsClient $sms,
private CustomerEmailClient $email,
private PlatformEmailClient $platformEmail,
private PlatformSmsClient $platformSms,
) {}
public function organizationWants(Organization $organization, string $setting): bool
@@ -129,7 +133,7 @@ class AppointmentPatientNotifier
/**
* When true, Meet should also email the patient join invite.
* Prefer Care-branded email when Bird is connected; otherwise fall back to Meet invites.
* Prefer Care suite/product email when available; otherwise fall back to Meet invites.
*/
public function shouldInvitePatientEmailViaMeet(Organization $organization): bool
{
@@ -137,9 +141,13 @@ class AppointmentPatientNotifier
return false;
}
if ($this->platformEmail->isConfigured()) {
return false;
}
$credential = $this->credentials->forOrganization($organization);
// Avoid double emails when Care Bird can send the branded notice.
// Avoid double emails when Care can send the branded notice.
return ! $credential->hasValidBird();
}
@@ -152,16 +160,29 @@ class AppointmentPatientNotifier
try {
$credential = $this->credentials->forOrganization($organization);
if (! $credential->hasValidSms()) {
$owner = (string) $organization->owner_ref;
$sent = false;
$error = null;
if ($this->platformSms->isConfigured()) {
$sender = $credential->sms_sender_id ?: null;
$sent = $this->platformSms->send($owner, $phone, $message, $sender ? (string) $sender : null);
if (! $sent) {
$error = $this->platformSms->lastError();
}
}
if (! $sent && $credential->hasValidSms() && ($apiKey = $credential->smsApiKey())) {
$sent = $this->sms->send($apiKey, $phone, $message, (string) $credential->sms_sender_id);
if (! $sent) {
$error = $this->sms->lastError() ?: $error;
}
}
if (! $sent && ! $this->platformSms->isConfigured() && ! $credential->hasValidSms()) {
return;
}
$apiKey = $credential->smsApiKey();
if (! $apiKey) {
return;
}
$sent = $this->sms->send($apiKey, $phone, $message, (string) $credential->sms_sender_id);
AuditLogger::record(
$organization->owner_ref,
$sent ? $auditAction.'_sent' : $auditAction.'_failed',
@@ -171,7 +192,7 @@ class AppointmentPatientNotifier
$patient->id,
[
'to' => $phone,
'error' => $sent ? null : $this->sms->lastError(),
'error' => $sent ? null : $error,
],
);
} catch (\Throwable $e) {
@@ -197,25 +218,37 @@ class AppointmentPatientNotifier
try {
$credential = $this->credentials->forOrganization($organization);
if (! $credential->hasValidBird()) {
return;
}
$apiKey = $credential->birdApiKey();
if (! $apiKey) {
return;
}
$owner = (string) $organization->owner_ref;
$fromName = trim((string) $organization->name) ?: null;
$html = OrganizationBranding::wrapEmailHtml(nl2br(e($body)), $organization);
$sent = $this->email->send(
$apiKey,
(string) $credential->bird_from_email,
$credential->bird_from_name,
$to,
$subject,
$html,
$body,
);
$sent = false;
$error = null;
if ($this->platformEmail->isConfigured()) {
$sent = $this->platformEmail->send($owner, $to, $subject, $html, $body, $fromName);
if (! $sent) {
$error = $this->platformEmail->lastError();
}
}
if (! $sent && $credential->hasValidBird() && ($apiKey = $credential->birdApiKey())) {
$sent = $this->email->send(
$apiKey,
(string) $credential->bird_from_email,
$credential->bird_from_name ?: $fromName,
$to,
$subject,
$html,
$body,
);
if (! $sent) {
$error = $this->email->lastError() ?: $error;
}
}
if (! $sent && ! $this->platformEmail->isConfigured() && ! $credential->hasValidBird()) {
return;
}
AuditLogger::record(
$organization->owner_ref,
@@ -227,7 +260,7 @@ class AppointmentPatientNotifier
[
'to' => $to,
'subject' => $subject,
'error' => $sent ? null : $this->email->lastError(),
'error' => $sent ? null : $error,
],
);
} catch (\Throwable $e) {