Telegram - . ? :)

Asterisk

Post call survey

, , . , ? .

( , , ). :

  • ;
  • ;
  • ;
  • 1 5, ;
  • MySQL Telegram, ;

:)

FreePBX Distro (FreePBX 13 + 13.10.0)

FreePBX, ( Queue Agents) , .

? . , /etc/asterisk/queues_post_custom.conf :

member=Local/111@customer-survey-ivr/n,0,111,hint:111@ext-local

111 - , . .


/etc/asterisk/extensions_custom.conf :

[customer-survey-ivr]
exten => _X.,1,NoOp(Post call survey beginning)
exten => _X.,n,DIAL(SIP/${EXTEN},,trg) //  g -     ,        .
exten => _X.,n,GotoIf($[${DIALSTATUS}=BUSY]?busy:answered) //,    
exten => _X.,n(busy),Hangup()
exten => _X.,n(answered),Goto(assessment,${EXTEN},1)


[assessment]
exten => _X.,1,Answer
exten => _X.,n,Wait(1)
exten => _X.,n(skip),Set(IVR_MSG=en/beep)
exten => _X.,n(start),Set(TIMEOUT(digit)=1)
exten => _X.,n,Background(/var/lib/asterisk/sounds/ru/custom/ocenite-8khz,m)  //    
exten => _X.,n,WaitExten(5,)

exten => 1,1,AGI(survey.php, ${CDR(src)}, ${DIALEDPEERNUMBER}, ${NODEST}, 1) //   1,     AGI  ,     Telegram  SQL
exten => 1,n,Playback(/var/lib/asterisk/sounds/ru/custom/bye-8khz,skip) //   

exten => 2,1,AGI(survey.php, ${CDR(src)}, ${DIALEDPEERNUMBER}, ${NODEST}, 2)
exten => 2,n,Playback(/var/lib/asterisk/sounds/ru/custom/bye-8khz,skip)

exten => 3,1,AGI(survey.php, ${CDR(src)}, ${DIALEDPEERNUMBER}, ${NODEST}, 3)
exten => 3,n,Playback(/var/lib/asterisk/sounds/ru/custom/bye-8khz,skip)

exten => 4,1,AGI(survey.php, ${CDR(src)}, ${DIALEDPEERNUMBER}, ${NODEST}, 4)
exten => 4,n,Playback(/var/lib/asterisk/sounds/ru/custom/bye-8khz,skip)

exten => 5,1,AGI(survey.php, ${CDR(src)}, ${DIALEDPEERNUMBER}, ${NODEST}, 5)
exten => 5,n,Playback(/var/lib/asterisk/sounds/ru/custom/bye-8khz,skip)

exten => t,1,Playback(/var/lib/asterisk/sounds/ru/custom/bye-8khz,skip)
exten => e,1,Playback(/var/lib/asterisk/sounds/ru/custom/bye-8khz,skip)
  • /var/lib/asterisk/sounds/ru/custom/ocenite-8khz - : , 1 5;
  • /var/lib/asterisk/sounds/ru/custom/bye-8khz - : ! ;

. , :

dialplan reload

SQL

, : BI (business intelligence) . SQL. survey, , , :

mysql
mysql> use asteriskcdrdb;
mysql> CREATE TABLE survey(num varchar(20),operator varchar(20),queue varchar(20),valuation varchar(20),date datetime);
mysql> CREATE USER '_mysql'@'localhost' IDENTIFIED BY '_mysql';
mysql> GRANT INSERT ON asteriskcdrdb.survey TO '_mysql';

, :

mysql
mysql> describe survey;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| num       | varchar(20) | YES  |     | NULL    |       |
| operator  | varchar(20) | YES  |     | NULL    |       |
| queue     | varchar(20) | YES  |     | NULL    |       |
| valuation | varchar(20) | YES  |     | NULL    |       |
| date      | datetime    | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+ 

. AGI , Telegarm API SQL.


AGI

, Telegram ? , . ID :)

, . :

#!/usr/bin/php -q
<?php
#   AGI
require('phpagi.php'); 
$agi = new AGI(); 
$num = $agi->request['agi_arg_1'];
$operator = $agi->request['agi_arg_2'];
$queue = $agi->request['agi_arg_3'];
$valuation = $agi->request['agi_arg_4'];
#   API Telegram   ID - 
$token = "_api__Telegram";
$chat_id = "ID_";
#
$date = date("Y-m-d H:i:s");
#  Telegram  
$arr = array(
'   :' => '',
':' => $num,
' :' => $operator,
' :' => $queue,
'  (1-5)' => $valuation,
' :' => $date,
);
foreach($arr as $key => $value) {
$txt .= "<b>".$key."</b> ".$value."%0A";
};
fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r");
#   
$hostname = "localhost";
$username = "_mysql";
$password = "_mysql";
$dbName = "asteriskcdrdb";
#   SQL  
mysql_connect($hostname,$username,$password) OR DIE("    ");
mysql_select_db($dbName) or die(mysql_error());
$query = "INSERT INTO survey (`num`, `operator`, `queue`, `valuation`, `date`) VALUES ('$num', '$operator', '$queue', '$valuation', '$date');"; 
$res=mysql_query($query) or die(mysql_error());
?>

, .txt .php

$token, $chat_id, $username $password . survey.php /var/lib/asterisk/agi-bin. WinSCP, . , SSH Asterisk :

dos2unix /var/lib/asterisk/agi-bin/survey.php
chown asterisk:asterisk /var/lib/asterisk/agi-bin/survey.php
chmod 775 /var/lib/asterisk/agi-bin/survey.php

. , .


, , , . ? :) , 1 5. . , Telegram :

       Asterisk

SQL?

       Asterisk  SQL

?