Skip to content

Commit

Permalink
#764 Добавил параметр NOTIFICATION_NAME_TO для оповещений о пропущенн…
Browse files Browse the repository at this point in the history
…ых. Доработал оповещения о голосовой почте, заполнение параметра VM_CALLER_NAME.
  • Loading branch information
boffart committed Aug 8, 2024
1 parent 5c22cc1 commit 5ac99a2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
36 changes: 36 additions & 0 deletions src/Common/Models/Extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,42 @@ public static function getNextFreeApplicationNumber(): string
return $freeExtension;
}

/**
* Returns Caller ID by phone number.
* @param string $number
* @return string
*/
public static function getCidByPhoneNumber(string $number):string
{
if(empty($number)){
return $number;
}
$number = preg_replace('/\D+/', '', $number);
$extensionLength = PbxSettings::getValueByKey(PbxSettingsConstants::PBX_INTERNAL_EXTENSION_LENGTH);
if(strlen($number) > $extensionLength){
$query = 'number LIKE :phone:';
$phone = '%'.substr($number, -9);
}else{
$query = 'number = :phone:';
$phone = $number;
}
$filter = [
$query,
'columns' => 'callerid',
'bind' => [
'phone' => $phone
]
];
$data = self::findFirst($filter);
if($data){
$cid = $data->callerid;
}else{
$cid = $number;
}

return $cid;
}

/**
* Get the next available internal extension number.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Core/System/RootFS/sbin/voicemail-sender
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/php
<?php

use MikoPBX\Common\Models\Extensions;
use MikoPBX\Core\Asterisk\Configs\VoiceMailConf;
use MikoPBX\Core\System\BeanstalkClient;
use MikoPBX\Core\System\Notifications;
Expand Down Expand Up @@ -76,6 +77,10 @@ try {
unset($data);
}
}
$cidName = $params['VM_CALLER_NAME']??'';
if(empty($cidName)){
$params['VM_CALLER_NAME'] = Extensions::getCidByPhoneNumber($params['VM_CALLER_NUM']);
}
$message = "$body $footer";
replaceParams($subject, $params);
replaceParams($message, $params);
Expand Down
15 changes: 12 additions & 3 deletions src/Core/Workers/WorkerNotifyByEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
namespace MikoPBX\Core\Workers;
require_once 'Globals.php';

use AWS\CRT\Internal\Extension;
use MikoPBX\Core\System\{BeanstalkClient, MikoPBXConfig, Notifications, SystemMessages, Util};
use MikoPBX\Common\Models\Extensions;
use MikoPBX\Common\Models\PbxSettingsConstants;

/**
Expand Down Expand Up @@ -60,8 +62,9 @@ public function start(array $argv): void
*/
public function workerNotifyByEmail($message): void
{
$phonesCid = [];
$notifier = new Notifications();
$config = new MikoPBXConfig();
$config = new MikoPBXConfig();
$settings = $config->getGeneralSettings();

/** @var BeanstalkClient $message */
Expand All @@ -80,11 +83,16 @@ public function workerNotifyByEmail($message): void
$tmpArray = [];
foreach ($data as $call) {
$keyHash = $call['email'] . $call['start'] . $call['from_number'] . $call['to_number'];

// Skip duplicate emails
if (in_array($keyHash, $tmpArray, true)) {
continue;
}
if(isset($phonesCid[$call['to_number']])){
$call['to_name'] = $phonesCid[$call['to_number']];
}else{
$call['to_name'] = Extensions::getCidByPhoneNumber($call['to_number']);
$phonesCid[$call['to_number']] = $call['to_name'];
}
$tmpArray[] = $keyHash;
if (!isset($emails[$call['email']])) {
$emails[$call['email']] = [
Expand All @@ -98,7 +106,6 @@ public function workerNotifyByEmail($message): void
$emails[$call['email']]['body'] .= "$email <br><hr><br>";
}
}

foreach ($emails as $to => $email) {
$subject = $email['subject'];
$body = "{$email['body']}<br>{$email['footer']}";
Expand All @@ -122,6 +129,7 @@ private function replaceParams(string $src, array $params): string
"NOTIFICATION_MISSEDCAUSE",
"NOTIFICATION_CALLERID",
"NOTIFICATION_TO",
"NOTIFICATION_NAME_TO",
"NOTIFICATION_DURATION",
"NOTIFICATION_DATE"
],
Expand All @@ -130,6 +138,7 @@ private function replaceParams(string $src, array $params): string
'NOANSWER',
$params['from_number'],
$params['to_number'],
$params['to_name'],
$params['duration'],
explode('.', $params['start'])[0]
],
Expand Down

0 comments on commit 5ac99a2

Please sign in to comment.