Missed Call Telegram Notifications
This article describes two ways to implement Telegram notifications for missed calls.
Dialplan-Based Example



PHP-AGI Example





Last updated
Was this helpful?
This article describes two ways to implement Telegram notifications for missed calls.








Last updated
Was this helpful?
Was this helpful?
[add-trim-prefix-clid-custom]
exten => _[0-9*#+a-zA-Z][0-9*#+a-zA-Z]!,1,NoOp(start check blacklist)
same => n,Set(CHANNEL(hangup_handler_push)=hangup-ext-queues,h,1);
same => n,Return()
[hangup-ext-queues]
exten => h,1,ExecIf($["${M_DIALSTATUS}" = "ANSWER"]?return)
same => n,Set(TOKEN=5118292900:AAEWCOAXkay5fXb8AJptZmDyqkNk8QbP200)
same => n,Set(CHAT_ID=939950800)
same => n,Set(URL=https://api.telegram.org/bot${TOKEN}/sendMessage)
same => n,Set(TEXT=MISSED CALL from: ${CALLERID(name)}, did: ${FROM_DID}, callid: ${CHANNEL(callid)})
same => n,SHELL(curl -s -X POST '${URL}' -d chat_id='${CHAT_ID}' -d text='${TEXT}')
same => n,Set(MISSED=${SHELL(curl -s -X POST '${URL}' -d chat_id='${CHAT_ID}' -d text='${TEXT}')})
same => n,returnload => func_shell.sosame => n,Set(MISSED=${SHELL(curl -X POST --data-urlencode "payload={\"channel\": \"#cannel_name\", \"username\": \"bot_name\", \"text\": \"Missed call from ${CALLERID(name)} using external line: ${FROM_DID} в ${STRFTIME(${EPOCH},,%H:%M:%S %d-%m-%Y)}\", \"icon_emoji\": \":sos:\"}" https://hooks.slack.com/services/T76G7L0/B01R/VMPQUeAN)})<?php
require_once 'Globals.php';
use \GuzzleHttp\Client;
const API_KEY = '';
const CHAT_ID = '';
$agi = new MikoPBX\Core\Asterisk\AGI();
$name = $agi->get_variable('CALLERID(name)', true);
$num = $agi->get_variable('CALLERID(num)', true);
$did = $agi->get_variable('$FROM_DID', true);
$id = $agi->get_variable('CHANNEL(linkedid)', true);
$date = date('Y.d.m H:i:s', str_replace('mikopbx-', '', $id));
$TEXT = "Missed call: $name, did: $did, callid: $num, id: $id, date: $date";
$apiURL = 'https://api.telegram.org/bot' . API_KEY . '/';
$client = new Client([
'base_uri' => $apiURL,
'timeout' => 1,
'http_errors' => false,
]);
try {
$client->post( 'sendMessage', ['query' => ['chat_id' => CHAT_ID, 'text' => $TEXT]] );
}catch (Throwable $e){
}[add-trim-prefix-clid-custom]
exten => _.X!,1,Set(CHANNEL(hangup_handler_push)=hangup-ext-queues,h,1);
same => n,return
[hangup-ext-queues]
exten => h,1,ExecIf($["${M_DIALSTATUS}" = "ANSWER"]?return)
same => n,AGI(DIALPLAN-APP-1B2B846E.php)
same => n,return