Skip to main content

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

PropertyValue
NamespaceApp\Models
Tableai_assistants
Primary Keyid
Global ScopeOrganizationScope
Soft DeletesYes

Database Schema

ColumnTypeNullableDescription
idbigint unsignedNoPrimary key
organization_idbigint unsignedNoOrganization ID
namevarchar(255)NoAssistant name
descriptiontextYesOptional description
statusvarchar(50)NoUserStatus enum
providervarchar(100)NoProvider key
protocolvarchar(50)Nosip or websocket
configurationjsonYesProvider-specific config
created_bybigint unsignedYesCreator user ID
updated_bybigint unsignedYesUpdater user ID
deleted_attimestampYesSoft delete timestamp
created_attimestampNoCreation timestamp
updated_attimestampNoUpdate timestamp

Protocols

ProtocolDescription
sipSIP-based connection to AI service
websocketWebSocket streaming connection

Attributes

Fillable

protected $fillable = [
'organization_id',
'name',
'description',
'status',
'provider',
'protocol',
'configuration',
'created_by',
'updated_by',
];

Casts

AttributeCastDescription
statusUserStatus::classStatus enum
configurationarrayJSON configuration

Relationships

Belongs To

  • organization() → Organization
  • creator() → User
  • updater() → 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"
}