flexisip-account-manager/flexiapi/app/Console/Commands/Accounts/SendVoicemailsEmails.php
Timothée Jaussoin eeeb6baf74 Fix FLEXIAPI-366 Send the voicemails by email
Add a Voicemail UI to listen and delete voicemails in the Admin Account view
2025-12-11 17:20:56 +01:00

40 lines
1.2 KiB
PHP

<?php
namespace App\Console\Commands\Accounts;
use App\AccountFile;
use App\Mail\Voicemail;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
class SendVoicemailsEmails extends Command
{
protected $signature = 'accounts:send-voicemails-emails {--tryout}';
protected $description = 'Send the voicemail emails';
public function handle()
{
$voicemails = AccountFile::whereNotNull('uploaded_at')
->whereNull('sent_by_mail_at')
->where('sending_by_mail_tryouts', '<', is_int($this->option('tryout'))
? $this->option('tryout')
: 3)
->get();
foreach ($voicemails as $voicemail) {
$voicemail->sending_by_mail_at = Carbon::now();
$voicemail->save();
if (Mail::to(users: $voicemail->account)->send(new Voicemail($voicemail))) {
$voicemail->sent_by_mail_at = Carbon::now();
$this->info('Voicemail sent to ' . $voicemail->account->identifier);
} else {
$voicemail->sending_by_mail_tryouts++;
$this->info('Error sending voicemail to ' . $voicemail->account->identifier);
}
$voicemail->save();
}
}
}