. IP Asterisk (/) Telegram . .


Telegram Asterisk

C . , .

, Telegram - .


PHP -

, Telegram php. . #:

<?php
#    ;
function rus_date() {
    $translate = array(
    "am" => "",
    "pm" => "",
    "AM" => "",
    "PM" => "",
    "Monday" => "",
    "Mon" => "",
    "Tuesday" => "",
    "Tue" => "",
    "Wednesday" => "",
    "Wed" => "",
    "Thursday" => "",
    "Thu" => "",
    "Friday" => "",
    "Fri" => "",
    "Saturday" => "",
    "Sat" => "",
    "Sunday" => "",
    "Sun" => "",
    "January" => "",
    "Jan" => "",
    "February" => "",
    "Feb" => "",
    "March" => "",
    "Mar" => "",
    "April" => "",
    "Apr" => "",
    "May" => "",
    "May" => "",
    "June" => "",
    "Jun" => "",
    "July" => "",
    "Jul" => "",
    "August" => "",
    "Aug" => "",
    "September" => "",
    "Sep" => "",
    "October" => "",
    "Oct" => "",
    "November" => "",
    "Nov" => "",
    "December" => "",
    "Dec" => "",
    "st" => "",
    "nd" => "",
    "rd" => "",
    "th" => ""
    );
    
    if (func_num_args() > 1) {
        $timestamp = func_get_arg(1);
        return strtr(date(func_get_arg(0), $timestamp), $translate);
    } else {
        return strtr(date(func_get_arg(0)), $translate);
    }
}
# : 
$hostname = "localhost"; #    Asterisk; 
$username = "_"; #  ,     ;
$password = "_"; #,  ;
$dbName = "asteriskcdrdb"; #  ;
$token = "Telegram_API"; # API -     Telegram - ;
$chat_id = "_ID"; # ;
$today = date('y-m-d'); #     (y-m-d);
$did = "_DID"; #      (DID). , 74996491913;
$noanswer = 0; #,        ;
#   SQL  
mysql_connect($hostname,$username,$password) OR DIE("    ");
mysql_select_db($dbName) or die(mysql_error());
$query = "SELECT DISTINCT `clid` ,`dst` ,`duration` , `dstchannel` , `calldate` , `disposition` FROM `cdr` WHERE `calldate` >='$today 00:00:00' AND `calldate` <='$today 23:59:59' AND `did` = '$did' GROUP BY `clid`;" ; 
$res=mysql_query($query) or die(mysql_error());
$number = mysql_num_rows($res);
while ($row=mysql_fetch_array($res)) {
if ($row['disposition'] == 'NO ANSWER') $noanswer = $noanswer + 1; }
#  
if ($noanswer != 0) {$percentage = round(100 * ($noanswer / $number));} else #     :) ,  ;
{
$percentage = 0;
};
$percentage = ''.$percentage.'%';
$date_rus = rus_date("j F");
$hello = "<b> </b>,  !  , <b>$date_rus</b>,    -  ";
$missed = "   - ";
$missed_percent = "       - ";
$arr = array(
$hello => $number,
$missed => $noanswer,
$missed_percent => $percentage,
);
foreach($arr as $key => $value) {
$txt .= "".$key." <b>".$value."</b>%0A";
};
fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r");
?>

asterisktelegram.php. , /home.

, :

chmod 755 /home/asterisktelegram.php 
dos2unix /home/asterisktelegram.php

cron. , 19:00. cron :

crontab e

:

00 19 * * 1-5 /usr/bin/php /home/asterisktelegram.php

, :)

   Asterisk  Telegram

?

 .

P.S. , :)

"",