Slack - , . , , .
API. IP Asterisk Slack, .
Slack API
, Webhook URL. : , Apps, :

, webhook. , Incoming WebHooks Install:

Add Configuration:

, , , Webhook ( Asterisk). #general:

, Webhook URL:

URL. .
Slack
, : , , Announcement ( ), 15 . , , Asterisk . PHP ( ):
#!/usr/bin/php -q <?php # error_reporting(0); require('phpagi.php'); $agi = new AGI(); $cid = $agi->request['agi_callerid']; # ( ) $webhook_url = 'https://hooks.slack.com/services/_webhook_url'; $channel = "#general"; $username = "Merion Networks"; $icon_url = "//merionet.ru/logo.png"; # JSON $fields = "payload=" . json_encode(array( "channel" => $channel, "text" => ", ! \n - $cid", "username" => $username, "icon_url" => $icon_url )); # CURL API Slack $ch = curl_init($webhook_url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); ?>
.txt .php!
, , :
- slack.php;
- ;
- $webhook_url - Webhook URL , ;
- $channel - , ;
- $username - , ;
- $icon_url - URL , ;
- ;
- PHP /var/lib/asterisk/agi-bin slack.php;
- ( SSH ) :
- Asterisk:
chmod 755 /var/lib/asterisk/agi-bin/slack.php chown asterisk:asterisk /var/lib/asterisk/agi-bin/slack.php dos2unix /var/lib/asterisk/agi-bin/slack.php
exten => _.,n,AGI(slack.php)
, :

! .
Slack
Asterisk Slack. :
<?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 = ""; # SQL; $password = ""; #, ; $dbName = "asteriskcdrdb"; # ; $today = date('y-m-d'); # SQL - ; $did = "74996491913"; # (DID), ; $date_rus = rus_date("j F"); # ; # 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;}; # ; # Slack $webhook_url = 'https://hooks.slack.com/services/_webhook_url'; $channel = "#general"; $username = "Merion Networks"; $icon_url = "//merionet.ru/logo.png"; $fields = "payload=" . json_encode(array( "channel" => $channel, "text" => "! , $date_rus, - $number\n - $noanswer\n - $percentage%", "username" => $username, "icon_url" => $icon_url )); $ch = curl_init($webhook_url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); ?>
.txt .php!
. SQL , webhook URL , . :
- /home/admin/slack_calls.php
- :
- cron ( 19:00):
chmod 755 /home/slack_calls.php dos2unix /home/slack_calls.php
crontab e
00 19 * * 1-5 /usr/bin/php /home/slack_calls.php

:)