Created
August 24, 2021 07:46
-
-
Save krotesk/c4d2428772fc625c215ec3a0e2c12fed to your computer and use it in GitHub Desktop.
Sending notifications about the unavailability of the trunk (rather the subscriber)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
require('phpagi.php'); | |
$agi = new AGI(); | |
$stdin = fopen('php://stdin', 'r'); | |
$stdout = fopen('php://stdout', 'w'); | |
/* | |
Вынесем отправку в телеграм в отдельную функцию send, последний параметр укажем как необязательный т.к. для тестовых сообщений используются бесплатные прокси – без пароля | |
*/ | |
function send($token, $chatid, $text){ | |
$ch=curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot'.$token.'/sendMessage'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, 'chat_id='.$chatid.'&text='.urlencode($text)); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); | |
//curl_setopt($ch, CURLOPT_PROXY, $proxy); | |
if($auth){ | |
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $auth); | |
} | |
// Отправляем сообщение | |
$result=curl_exec($ch); | |
/* | |
Для отладки в скрипте можно добавить dump какой-либо переменной, например $result. Результат вывода var_dump($result) отобразится в консоли Астериска при включенном режиме отладки agi - agi set debug on | |
*/ | |
var_dump($result); | |
curl_close($ch); | |
return $result; | |
} | |
// Токен бота и идентификатор чата | |
$token='196***4032:AAEvVTI_uo................'; | |
//id чата оператора в telegram | |
$chat_id = array(58XYZA112, 693ABCD57); | |
/* Текст сообщения. Переданные в скрипт аргументы (номер звонящего и дата звонка) - $argv[1] и $argv[2] */ | |
$text="Shar-Orsk: GSM-gate KTS 1 nicht arbeiten - reboot!\nКто не понял - с GSM 1 какая-то фигня - перезагрузи который 15.100!"; | |
// Настройки прокси | |
//$proxy='23.23.179.254:3128'; | |
//$auth='login:password'; //пароль, если прокси – с паролем, в формате 'login:password' | |
// Отправка сообщения в личный Telergam чат | |
foreach($chat_id as $chatid){ | |
//echo($chat_id); | |
send($token, $chatid, $text); | |
} | |
fclose ($stdin); | |
fclose ($stdout); | |
exit(0); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment