up
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappConversation extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_conversations';
|
||||
public $updated_at = null;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'message_id', 'reply_to_message_id', 'reaction_to_message_id',
|
||||
'reaction_emoji', 'direction', 'message_type', 'content', 'media_url',
|
||||
'whatsapp_media_id', 'local_file', 'local_thumb', 'media_storage',
|
||||
'status', 'is_read', 'filename', 'mime_type',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_read' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(WhatsappUser::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappMenu extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_menus';
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'title', 'message', 'parent_id', 'is_main', 'is_active', 'sort_order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_main' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function options()
|
||||
{
|
||||
return $this->hasMany(WhatsappMenuOption::class, 'menu_id')->orderBy('sort_order');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(WhatsappMenu::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(WhatsappMenu::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappMenuOption extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_menu_options';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'menu_id', 'option_number', 'title', 'action_type', 'action_value',
|
||||
'is_active', 'sort_order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function menu()
|
||||
{
|
||||
return $this->belongsTo(WhatsappMenu::class, 'menu_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappMessageTemplate extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_message_templates';
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'template_name', 'language_code', 'status', 'body_text',
|
||||
'header_type', 'header_text', 'footer_text', 'components', 'example_parameters',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'components' => 'array',
|
||||
'example_parameters' => 'array',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappScheduledMessage extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_scheduled_messages';
|
||||
public $updated_at = null;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'phone_number', 'template_id', 'template_name', 'template_language',
|
||||
'template_parameters', 'message_type', 'message_content', 'scheduled_date',
|
||||
'scheduled_time', 'status', 'sent_at', 'error_message', 'created_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'template_parameters' => 'array',
|
||||
'scheduled_date' => 'date',
|
||||
'sent_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappSystemConfig extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_system_config';
|
||||
|
||||
protected $fillable = ['config_key', 'config_value', 'description'];
|
||||
|
||||
public static function get(string $key, string $default = ''): string
|
||||
{
|
||||
$record = static::where('config_key', $key)->first();
|
||||
return $record ? ($record->config_value ?? $default) : $default;
|
||||
}
|
||||
|
||||
public static function set(string $key, string $value): void
|
||||
{
|
||||
static::updateOrCreate(
|
||||
['config_key' => $key],
|
||||
['config_value' => $value]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappUser extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_users';
|
||||
|
||||
protected $fillable = [
|
||||
'phone_number', 'name', 'status', 'current_menu_id', 'current_step',
|
||||
'session_data', 'welcome_sent_at', 'in_service', 'in_service_by',
|
||||
'on_hold', 'bot_paused_until', 'advisor_requested', 'bot_enabled',
|
||||
'terms_pending', 'terms_accepted_at', 'terms_version_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'session_data' => 'array',
|
||||
'welcome_sent_at' => 'datetime',
|
||||
'bot_paused_until' => 'datetime',
|
||||
'terms_accepted_at' => 'datetime',
|
||||
'in_service' => 'boolean',
|
||||
'on_hold' => 'boolean',
|
||||
'advisor_requested' => 'boolean',
|
||||
'bot_enabled' => 'boolean',
|
||||
'terms_pending' => 'boolean',
|
||||
];
|
||||
|
||||
public function conversations()
|
||||
{
|
||||
return $this->hasMany(WhatsappConversation::class, 'user_id');
|
||||
}
|
||||
|
||||
public function lastMessage()
|
||||
{
|
||||
return $this->hasOne(WhatsappConversation::class, 'user_id')->latestOfMany();
|
||||
}
|
||||
|
||||
public function currentMenu()
|
||||
{
|
||||
return $this->belongsTo(WhatsappMenu::class, 'current_menu_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WhatsappWebhookLog extends Model
|
||||
{
|
||||
protected $table = 'whatsapp_webhook_logs';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['payload', 'response', 'status_code'];
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user