Telegram - . ? :)

! 24. . , Telegram :) .


24

24 . , :

  24

, . :

  • - . REST API;
  • - c ;
  • - CRM (crm);

. . .

   24

Telegram -

, Telegram . , :


, Telegram, , 24. , :

#!/usr/bin/php -q
<?php
# AGI - ;
require('phpagi.php'); 
$agi = new AGI(); 
$cid = $agi->request['agi_callerid'];
# ,        79.  CRM    89. ,       8;
$phone = substr($cid, 1);
$phone = "8$phone";
$phoneFieldset = ",  . : ";
#  :  ,  ,   CRM (,   https://   .bitrix24.ru)  ,    ;
$token = "333333333:MMMMMEEEEE_RRRIIIIOOOO_NNNNEEEETTTT";
$chat_id = "-1001001001001";
$crm_id = "__24";
$webhook = "wblhahgytuwrnwer";
#    ;
$bitrix_lead_url = "https://$crm_id.bitrix24.ru/rest/2/$webhook/crm.lead.list.json?filter[PHONE]=$phone&select[]=TITLE&select[]=NAME&select[]=LAST_NAME";
$btl = curl_init();
curl_setopt ($btl, CURLOPT_URL,$bitrix_lead_url);
curl_setopt ($btl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($btl, CURLOPT_TIMEOUT, 60);
curl_setopt ($btl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($btl, CURLOPT_RETURNTRANSFER, 1);
$bitrix_lead = curl_exec ($btl);
curl_close($btl);
$bitrix_lead_o = json_decode($bitrix_lead, true);
$l_total = $bitrix_lead_o['total'];
#    ;
$bitrix_contact_url = "https://$crm_id.bitrix24.ru/rest/2/$webhook/crm.contact.list.json?filter[PHONE]=$phone&select[]=TITLE&select[]=NAME&select[]=LAST_NAME";
$btc = curl_init();
curl_setopt ($btc, CURLOPT_URL,$bitrix_contact_url);
curl_setopt ($btc, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($btc, CURLOPT_TIMEOUT, 60);
curl_setopt ($btc, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($btc, CURLOPT_RETURNTRANSFER, 1);
$bitrix_contact = curl_exec ($btc);
curl_close($btc);
$bitrix_contact_o = json_decode($bitrix_contact, true);
$c_total = $bitrix_contact_o ['total'];
#  , :       Telegram: ,    ;
if ($l_total >= 1) {
$l_name = $bitrix_lead_o['result'][0]['NAME'];
$l_title = $bitrix_lead_o['result'][0]['TITLE'];
$l_l_name = $bitrix_lead_o['result'][0]['LAST_NAME'];
$l_id = $bitrix_lead_o['result'][0]['ID'];
$l_titleFieldset = "    - ";
$l_FnameFieldset = "  - ";
$l_linkFieldset = "   - "; 
$l_fullname = "$l_name $l_l_name";
$l_link = "https://$crm_id.bitrix24.ru/crm/lead/show/$l_id/";
$arr = array(
$l_titleFieldset => $l_title,
$l_FnameFieldset => $l_fullname,
$l_linkFieldset => $l_link,
);
foreach($arr as $key => $value) {
$txt .= "".$key." ".$value."%0A";
};
fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r");
}
#  , :       Telegram: ,    ;
elseif ($c_total >= 1) {
$c_name = $bitrix_contact_o ['result'][0]['NAME'];
$c_c_name = $bitrix_contact_o ['result'][0]['LAST_NAME'];
$c_id = $bitrix_contact_o ['result'][0]['ID'];
$c_FnameFieldset = "    - ";
$c_linkFieldset = "   - "; 
$c_fullname = "$c_name $c_c_name";
$c_link = "https://$crm_id.bitrix24.ru/crm/contact/show/$c_id/";
$arr = array(
$c_FnameFieldset => $c_fullname,
$c_linkFieldset => $c_link,
);
foreach($arr as $key => $value) {
$txt .= "".$key." ".$value."%0A";
};
fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r");
}
else {};
?>

, :

  • $token - . ;
  • $chat_id - , . ;
  • $crm_id - 24. URL CRM company.bitrix24.ru, company;
  • $webhook - . , 24 ( wblhahgytuwrnwer);

b24.php /var/lib/asterisk/agi-bin.

unix :

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

( , ):

exten => _.,n,AGI(b24.php) 
$agi->set_variable("lookupcid", "$c_fullname"); $agi->set_variable("lookupcid", "$l_fullname"); , : Set(CALLERID(name)=${lookupcid}) CallerID Name , .

( ) . :)

 24  Asterisk

?

 .

P.S. , :)

"",