Уведомления о пропущенных
Добавлено: 21 май 2021, 23:14
- Код: Выделить всё
[local_context]
exten => _17XX,1,Set(fname=${STRFTIME(${EPOCH},,%Y%m%d%H%M%S)}-${CALLERID(number)}-${EXTEN})
exten => _17XX,n,MixMonitor(/var/spool/asterisk/monitor/${fname}.wav)
exten => _17XX,n,Set(recfile=/var/spool/asterisk/monitor/${fname}.wav)
exten => _17XX,n,Set(CDR(recfile)=/var/spool/asterisk/monitor/${fname}.wav)
exten => _17XX,n,Dial(SIP/${EXTEN},12)
;exten => _17XX,n,GotoIf($["${DIALSTATUS}" =="BUSY"]?vm)
exten => _17XX,n,GotoIf($["${DIALSTATUS}" !="ANSWER"]?vm)
exten => _17XX,n(vm),Macro(svm,${EXTEN},v_mail)
;exten => _17XX,n,HangUp()
exten => h,1,Noop(*****SEND to Telegram*************)
exten => h,2,Noop(***DIALSTATUS=${DIALSTATUS}*************)
exten => h,3,GotoIf($["${DIALSTATUS}" =="ANSWER"]?end)
exten => h,n,System(/usr/local/share/asterisk/agi-bin/scriptFINAL.sh ${recfile})
exten => h,n,Hangup()
exten => h,n(end),Hangup()
[macro-svm]
exten => s,1,Wait(1)
exten => s,n,PlayBack(vm-nobodyavail)
exten => s,n,Wait(1)
exten => s,n,Voicemail(${ARG1}@${ARG2})
exten => s,n,Wait(2)
exten => s,n,HangUp()
sox, хорошо бы установить
sendOK_FINAL.php
- Код: Выделить всё
#!/usr/local/bin/php -q
<?php
sleep(3);
define('TOKEN', '123123123123:Axgsfgsdfsdfsdfgsfdgsdf'); // bot TOKEN
define('CHAT_ID','-123123123123'); // group Telegram
define('TEMP_DIR_OGG','/home/tmp/'); //must be chown asterisk
//define('VOICEMAIL_CONTEXT','v_mail');
$i = explode('-',$argv[1]);
$cdn = $i[count($i)-2];
$j = explode('.',end($i));
$st = basename($i[0]);
echo basename($i[0])."\n";
//echo $argv[2]."\n";
$y=$st[0].$st[1].$st[2].$st[3];
$mon=$st[4].$st[5];
$d=$st[6].$st[7];
$h=$st[8].$st[9];
$min=$st[10].$st[11];
$sec=$st[12].$st[13];
$starttime=$y.'-'.$mon.'-'.$d.' '.$h.':'.$min.':'.$sec;
$ut=strtotime($starttime);
$pdir = '/var/spool/asterisk/voicemail/v_mail/'.$j[0].'/INBOX';
//$pdir = '/var/spool/asterisk/voicemail/'.VOICEMAIL_CONTEXT.'/'.$j[0].'/INBOX';
//////////////////////////////
$last_mtimes= array();
//sleep(7);
if($dh = opendir($pdir)) {
$files = Array();
$inner_files = Array();
while($file = readdir($dh)) {
if($file == '.' || $file == '..'){continue;}
$pos = stripos($file,"wav");
if($pos===false){continue;}
$lmtime = filemtime($pdir . "/" . $file) ;
$last_mtimes[$lmtime] = $pdir . "/" . $file;
}
}
$infile=end($last_mtimes);
$temp =pathinfo($infile);
$voicefile=$temp['filename'].'.ogg';
$last_txt =$temp['dirname'].'/'.$temp['filename'].'.txt';
//echo $last_txt;
//$str_origtime=0;
$fromfileutime=0;
/////////////
$handle = fopen($last_txt, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$pos = strpos($line,'origtime');
if($pos!==false){
$arrfile =explode('=',$line);
$fromfileutime=trim($arrfile[1]);
break; }
// process the line read.
}
} else {
echo 'Error opening file '.$last_txt; // error opening the file.
$s = 'Звонили c номера: '.$cdn.' На номер: '.$j[0].' Дата: '.$starttime.' ';
$response_txt = array(
'chat_id' => CHAT_ID,
'text' => $s,
'method' => 'sendMessage'
);
// echo "Not exist VoiceMessage";
sendTelegram('sendMessage',$response_txt);
exit(0);
}
fclose($handle);
if($ut > $fromfileutime)
{
$s = 'Звонили c номера: '.$cdn.' На номер: '.$j[0].' Дата: '.$starttime.' ';
$response_txt = array(
'chat_id' => CHAT_ID,
'text' => $s,
'method' => 'sendMessage'
);
// echo "Not exist VoiceMessage";
sendTelegram('sendMessage',$response_txt);
}
else{
$cap = 'Звонили c номера: '.$cdn.' На номер: '.$j[0].' Дата: '.$starttime;
$sendf=TEMP_DIR_OGG.$voicefile;
//echo 'End file'."\n\r";
//echo $infile;
$cmd='sox -V '.end($last_mtimes).' '.$sendf;
//echo $cmd;
$output=shell_exec($cmd);
//$output=shell_exec('chown asterisk:asterisk '.TEMP_DIR_OGG);
//$f = $infile;
$f = $sendf;
//fwrite($fp,$f);
//fwrite($fp,'\n\r');
$cfile = new CURLFILE(realpath($f));
$resp_audio = array(
'chat_id' => CHAT_ID,
'audio' => $cfile,
'caption' => $cap
);
//sleep(3);
sendTelegram('sendAudio',$resp_audio );
//sendTelegram('sendMessage',$response_txt);
}
////////////
/*
$method_img = 'sendPhoto';
$response_file = array(
'chat_id' => $data['message']['chat']['id'],
'document' => curl_file_create(__DIR__ . '/file.xls'),
'method' => 'sendDocument'
);
sendTelegram($method_img,$response_img2);
sendTelegram($method_img,$response_img);
*/
//echo 'TEST';
// Функция вызова методов API.
function sendTelegram($method, $response)
{
// echo 'TEST';
$ch = curl_init('https://api.telegram.org/bot' . TOKEN . '/' . $method);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $response);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$res = curl_exec($ch);
curl_close($ch);
print_r($res);
return $res;
}
/*
// Прислали фото.
if (!empty($data['message']['photo'])) {
$photo = array_pop($data['message']['photo']);
$res = sendTelegram(
'getFile',
array(
'file_id' => $photo['file_id']
)
);
$res = json_decode($res, true);
if ($res['ok']) {
$src = 'https://api.telegram.org/file/bot' . TOKEN . '/' . $res['result']['file_path'];
$dest = __DIR__ . '/' . time() . '-' . basename($src);
if (copy($src, $dest)) {
sendTelegram(
'sendMessage',
array(
'chat_id' => $data['message']['chat']['id'],
'text' => 'Фото сохранено'
)
);
}
}
exit();
}
// Прислали файл.
if (!empty($data['message']['document'])) {
$res = sendTelegram(
'getFile',
array(
'file_id' => $data['message']['document']['file_id']
)
);
$res = json_decode($res, true);
if ($res['ok']) {
$src = 'https://api.telegram.org/file/bot' . TOKEN . '/' . $res['result']['file_path'];
$dest = __DIR__ . '/' . time() . '-' . $data['message']['document']['file_name'];
if (copy($src, $dest)) {
sendTelegram(
'sendMessage',
array(
'chat_id' => $data['message']['chat']['id'],
'text' => 'Файл сохранён'
)
);
}
}
exit();
}
// Ответ на текстовые сообщения.
if (!empty($data['message']['text'])) {
$text = $data['message']['text'];
if (mb_stripos($text, 'привет') !== false) {
sendTelegram(
'sendMessage',
array(
'chat_id' => $data['message']['chat']['id'],
'text' => 'Хай!'
)
);
exit();
}
// Отправка фото.
if (mb_stripos($text, 'фото') !== false) {
sendTelegram(
'sendPhoto',
array(
'chat_id' => $data['message']['chat']['id'],
'photo' => curl_file_create(__DIR__ . '/45.jpg')
)
);
exit();
}
// Отправка файла.
if (mb_stripos($text, 'файл') !== false) {
sendTelegram(
'sendDocument',
array(
'chat_id' => $data['message']['chat']['id'],
'document' => curl_file_create(__DIR__ . '/example.xls')
)
);
exit();
}
}
*/
?>
scriptFINAL.sh
- Код: Выделить всё
#!/bin/sh
(
sleep 1
/usr/local/bin/php /usr/local/share/asterisk/agi-bin/sendOK_FINAL.php $1
) &
#disown -h
exit 0