SMS service

This commit is contained in:
Simon Pocrnjič
2025-10-24 21:39:10 +02:00
parent 3a2eed7dda
commit 930ac83604
52 changed files with 3830 additions and 36 deletions
@@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreSmsProfileRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->can('manage-settings') ?? false;
}
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:190'],
'active' => ['sometimes', 'boolean'],
'api_username' => ['required', 'string', 'max:190'],
'api_password' => ['required', 'string', 'max:500'],
];
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreSmsSenderRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->can('manage-settings') ?? false;
}
public function rules(): array
{
$pid = (int) $this->input('profile_id');
return [
'profile_id' => ['required', 'integer', 'exists:sms_profiles,id'],
'sname' => [
'nullable', 'string', 'max:20',
Rule::unique('sms_senders', 'sname')->where(fn ($q) => $q->where('profile_id', $pid)),
],
'phone_number' => ['nullable', 'string', 'max:30'],
'description' => ['nullable', 'string', 'max:190'],
'active' => ['sometimes', 'boolean'],
];
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreSmsTemplateRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->can('manage-settings') ?? false;
}
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:190'],
'slug' => ['required', 'string', 'max:190', 'alpha_dash', 'unique:sms_templates,slug'],
// Content is required unless template allows custom body
'content' => [Rule::requiredIf(fn () => ! (bool) $this->input('allow_custom_body')), 'nullable', 'string', 'max:1000'],
'variables_json' => ['nullable', 'array'],
'is_active' => ['sometimes', 'boolean'],
'default_profile_id' => ['nullable', 'integer', 'exists:sms_profiles,id'],
'default_sender_id' => ['nullable', 'integer', 'exists:sms_senders,id'],
'allow_custom_body' => ['sometimes', 'boolean'],
'action_id' => ['nullable', 'integer', 'exists:actions,id'],
'decision_id' => ['nullable', 'integer', 'exists:decisions,id'],
];
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class TestSendSmsRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->can('manage-settings') ?? false;
}
public function rules(): array
{
return [
'to' => ['required', 'string', 'max:30'], // E.164-ish; we can refine later
'message' => ['required', 'string', 'max:1000'],
'sender_id' => ['nullable', 'integer', 'exists:sms_senders,id'],
'delivery_report' => ['sometimes', 'boolean'],
'country_code' => ['nullable', 'string', 'max:5'],
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class TestSendSmsTemplateRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->can('manage-settings') ?? false;
}
public function rules(): array
{
return [
'to' => ['required', 'string', 'max:30'],
'variables' => ['nullable', 'array'],
'profile_id' => ['nullable', 'integer', 'exists:sms_profiles,id'],
'sender_id' => ['nullable', 'integer', 'exists:sms_senders,id'],
'delivery_report' => ['sometimes', 'boolean'],
'country_code' => ['nullable', 'string', 'max:5'],
'custom_content' => ['nullable', 'string', 'max:1000'],
];
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateSmsSenderRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->can('manage-settings') ?? false;
}
public function rules(): array
{
$pid = (int) $this->input('profile_id');
$id = (int) ($this->route('smsSender')?->id ?? 0);
return [
'profile_id' => ['required', 'integer', 'exists:sms_profiles,id'],
'sname' => [
'nullable', 'string', 'max:20',
Rule::unique('sms_senders', 'sname')
->ignore($id)
->where(fn ($q) => $q->where('profile_id', $pid)),
],
'phone_number' => ['nullable', 'string', 'max:30'],
'description' => ['nullable', 'string', 'max:190'],
'active' => ['sometimes', 'boolean'],
];
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateSmsTemplateRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->can('manage-settings') ?? false;
}
public function rules(): array
{
$id = (int) ($this->route('smsTemplate')?->id ?? 0);
return [
'name' => ['required', 'string', 'max:190'],
'slug' => ['required', 'string', 'max:190', 'alpha_dash', Rule::unique('sms_templates', 'slug')->ignore($id)],
// Content is required unless template allows custom body
'content' => [Rule::requiredIf(fn () => ! (bool) $this->input('allow_custom_body')), 'nullable', 'string', 'max:1000'],
'variables_json' => ['nullable', 'array'],
'is_active' => ['sometimes', 'boolean'],
'default_profile_id' => ['nullable', 'integer', 'exists:sms_profiles,id'],
'default_sender_id' => ['nullable', 'integer', 'exists:sms_senders,id'],
'allow_custom_body' => ['sometimes', 'boolean'],
'action_id' => ['nullable', 'integer', 'exists:actions,id'],
'decision_id' => ['nullable', 'integer', 'exists:decisions,id'],
];
}
}