Files
crm.clientright.ru/modules/SPVoipIntegration/zebra/notifications/AbstractZebraNotification.php
Fedor ac7467f0b4 Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system
- Added comprehensive AI Assistant system (aiassist/ directory):
  * Vector search and embedding capabilities
  * Typebot proxy integration
  * Elastic search functionality
  * Message classification and chat history
  * MCP proxy for external integrations

- Implemented Court Status API (GetCourtStatus.php):
  * Real-time court document status checking
  * Integration with external court systems
  * Comprehensive error handling and logging

- Enhanced S3 integration:
  * Improved file backup system with metadata
  * Batch processing capabilities
  * Enhanced error logging and recovery
  * Copy operations with URL fixing

- Added Telegram contact creation API
- Improved error logging across all modules
- Enhanced callback system for AI responses
- Extensive backup file storage with timestamps
- Updated documentation and README files

- File storage improvements:
  * Thousands of backup files with proper metadata
  * Fix operations for broken file references
  * Project-specific backup and recovery systems
  * Comprehensive file integrity checking

Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
2025-10-16 11:17:21 +03:00

109 lines
3.4 KiB
PHP

<?php
namespace SPVoipIntegration\zebra\notifications;
use SPVoipIntegration\integration\AbstractNotification;
use SPVoipIntegration\ProvidersEnum;
abstract class AbstractZebraNotification extends AbstractNotification{
protected abstract function canCreatePBXRecord();
protected $fieldsMapping = array();
protected $args = array();
const SOURCE_ID_PREFIX = "zebra_";
public function __construct($values = array()) {
$values = json_decode(file_get_contents("php://input"), true);
parent::__construct($values);
$this->args = $this->get('args');
}
protected function getNotificationDataMapping() {
return $this->fieldsMapping;
}
protected function prepareNotificationModel() {
$this->set('user', '');
$this->set('sp_voip_provider', ProvidersEnum::ZEBRA);
$userModel = self::getUserByNumber($this->getUserPhoneNumber());
if ($userModel != null) {
$this->set('user', $userModel->getId());
}
}
public function process() {
if (!$this->pbxManagerModel->getId() && !$this->canCreatePBXRecord()) {
return;
}
$voipModel = $this->getVoipRecordModelFromNotificationModel();
$voipModel->save();
}
public function validateNotification() {
$handleNotification = true;
$direction = $this->args['Call-Direction'];
if ($direction == 'inbound') {
$handleNotification = false;
}
if ($handleNotification) {
$userModel = $this->getUserFromRequest();
if ($userModel == null) {
$handleNotification = false;
}
}
if (!$handleNotification) {
throw new \Exception("Unused notification");
}
}
public static function getInstance($requestData) {
$eventName = json_decode(file_get_contents("php://input"))->name;
switch ($eventName) {
case ZebraEventType::CREATE :
return new ZebraCreateChannelNotification($requestData);
case ZebraEventType::ANSWER :
return new ZebraChannelAnswerNotification($requestData);
case ZebraEventType::DESTROY :
return new ZebraChannelDestroyNotification($requestData);
default :
throw new \Exception("Unknown zebra notification");
}
}
protected function getUserFromRequest() {
$request = $this->args['Request'];
$requestParts = explode('@', $request);
$sipLogin = $requestParts[0];
$userModel = $this->getUserBySipLogin($sipLogin);
return $userModel;
}
protected function getUserBySipLogin($sipLogin) {
$db = \PearDatabase::getInstance();
$userModel = null;
$result = $db->pquery("SELECT id FROM vtiger_users WHERE sp_zebra_login=?", array($sipLogin));
if ($result && $resRow = $db->fetchByAssoc($result)) {
$userModel = \Users_Record_Model::getInstanceById($resRow['id'], 'Users');
}
return $userModel;
}
protected function getSourceUUId() {
return AbstractZebraNotification::SOURCE_ID_PREFIX . $this->get('args')['Call-ID'];
}
protected function getCustomerPhoneNumber() {
return '';
}
protected function getUserPhoneNumber() {
return '';
}
}