AiAssistant Model
The AiAssistant model represents a configured AI-powered conversational agent that can handle voice calls. Supports both SIP-based and WebSocket-based AI providers.
Overview
| Property | Value |
|---|---|
| Namespace | App\Models |
| Table | ai_assistants |
| Primary Key | id |
| Global Scope | OrganizationScope |
| Soft Deletes | Yes |
Database Schema
| Column | Type | Nullable | Description |
|---|---|---|---|
id | bigint unsigned | No | Primary key |
organization_id | bigint unsigned | No | Organization ID |
name | varchar(255) | No | Assistant name |
description | text | Yes | Optional description |
status | varchar(50) | No | UserStatus enum |
provider | varchar(100) | No | Provider key |
protocol | varchar(50) | No | sip or websocket |
configuration | json | Yes | Provider-specific config |
created_by | bigint unsigned | Yes | Creator user ID |
updated_by | bigint unsigned | Yes | Updater user ID |
deleted_at | timestamp | Yes | Soft delete timestamp |
created_at | timestamp | No | Creation timestamp |
updated_at | timestamp | No | Update timestamp |
Protocols
| Protocol | Description |
|---|---|
sip | SIP-based connection to AI service |
websocket | WebSocket streaming connection |
Attributes
Fillable
protected $fillable = [
'organization_id',
'name',
'description',
'status',
'provider',
'protocol',
'configuration',
'created_by',
'updated_by',
];
Casts
| Attribute | Cast | Description |
|---|---|---|
status | UserStatus::class | Status enum |
configuration | array | JSON configuration |
Relationships
Belongs To
organization()→ Organizationcreator()→ Userupdater()→ User
Has Many
extensions()→ Extension[]
Methods
Protocol Checking
isWebSocket(): bool
Check if using WebSocket protocol.
if ($assistant->isWebSocket()) {
// Use WebSocket streaming
}
isSip(): bool
Check if using SIP protocol.
if ($assistant->isSip()) {
// Use SIP connection
}
Provider
getProviderDefinition(): ?ProviderDefinition
Get provider definition from registry.
$provider = $assistant->getProviderDefinition();
Usage
getUsageCountAttribute(): int
Get number of extensions using this assistant.
$count = $assistant->usage_count;
isInUse(): bool
Check if assistant is in use.
if ($assistant->isInUse()) {
// Cannot delete - in use by extensions
}
Query Scopes
scopeForOrganization($query, $orgId)scopeActive($query)scopeInactive($query)scopeByProtocol($query, $protocol)scopeByProvider($query, $provider)scopeSearch($query, $search)scopeWithStatus($query, $status)
Configuration
Configuration varies by provider. Common fields:
{
"api_key": "sk-...",
"model": "gpt-4",
"voice": "alloy",
"phone_number": "+18001234567"
}