userdoc:tt_asterisk_call_notify

Asterisk Call Notification

AstLinux now supports the gntp-send CLI tool for sending Growl (GNTP) notifications
via the GNTP 1.0 TCP protocol and also via the legacy Growl UDP protocol.

A simple shell script can be called via an Asterisk System() command, formulate the desired notification message, and send to a listening Growl endpoint using gntp-send.

The notification can include CallerID name, number and extension, additionally an optional clickable link based on the CallerID number.

Snarl Notification

Snarl URL


Note: AstLinux 1.2.10 or later is required

Using the classic Macro() call:

[macro-growl-notify]
exten => s,1,Set(OK=0-9a-zA-Z!#%&*+./<>?@[]_{}~\x20\x28\x29\x2c\x2d\x7c)
exten => s,n,System(/mnt/kd/bin/asterisk-growl-notify-tcp '${FILTER(${OK},${CALLERID(name)}|${CALLERID(num)}|${ARG1})}' ${ARG2})
;
;...
exten => 1234,n,Macro(growl-notify,${EXTEN},192.168.101.13)

Using the modern Gosub() call:

[growl-notify]
exten = s,1,Set(OK=0-9a-zA-Z!#%&*+./<>?@[]_{}~\x20\x28\x29\x2c\x2d\x7c)
 same = n,System(/mnt/kd/bin/asterisk-growl-notify-tcp '${FILTER(${OK},${CALLERID(name)}|${CALLERID(num)}|${ARG1})}' ${ARG2})
 same = n,Return()
;
;...
exten => 1234,n,Gosub(growl-notify,s,1(${EXTEN},192.168.101.13))

Either executable shell script asterisk-growl-notify-tcp or asterisk-growl-notify-udp (below) can be called via the System() command, depending on the listening endpoint.

Tip -> The FILTER() function call is used to prevent remote command injection.

Tip -> Growl (GNTP) uses TCP port 23053, legacy Growl uses UDP port 9887.


Below is an example shell script asterisk-growl-notify-tcp that can be customized to formulate the desired message notification.

Tip -> The growl_notify function call is run in the background since the return value is not needed and TCP takes longer to handle the connection.

#!/bin/sh
##
## asterisk-growl-notify-tcp
##
## Usage: asterisk-growl-notify-tcp 'tel_name|tel_num|ext_num' client_ip
##

## Define ACTION_URL to add a clickable link, tel_num will be appended
#ACTION_URL="http://local.example.com/lookup.php?num="

## Set to "yes" for North America Numbering, USA/Canada/etc.
NANPA="yes"

PASS="secret"

ICON=""

tel_name="$(echo "$1" | cut -s -d'|' -f1)"

tel_num="$(echo "$1" | cut -s -d'|' -f2)"

ext_num="$(echo "$1" | cut -s -d'|' -f3)"

client_ip="$2"

if [ -z "$client_ip" -o -z "$tel_num" ]; then
  echo "Usage: asterisk-growl-notify-tcp 'tel_name|tel_num|ext_num' client_ip" >&2
  exit 1
fi

## Silently fail if client_ip is not reachable
#if ! fping -t 200 "$client_ip" >/dev/null 2>&1; then
#  exit 2
#fi

format_NANPA_number()
{
  echo "$1" | \
  sed -r -e 's/^([2-9])([0-9]{2})([2-9])([0-9]{2})([0-9]{4})$/\1\2-\3\4-\5/' \
         -e 's/^(1)([2-9])([0-9]{2})([2-9])([0-9]{2})([0-9]{4})$/\1-\2\3-\4\5-\6/'
}

growl_notify()
{
  local num date title msg url

  if [ "$NANPA" = "yes" ]; then
    num="$(format_NANPA_number "$tel_num")"
    date="$(ldate '+%l:%M %p on %A, %B %e')"
  else
    num="$tel_num"
    date="$(ldate '+%X %A, %B %e')"
  fi

  title="Incoming Call"

  msg="$tel_name"
  msg="$msg${msg:+\n}$num"
  msg="$msg${ext_num:+\nfor $ext_num}"
  msg="$msg\n${date## }"

  url="${ACTION_URL:+$ACTION_URL$tel_num}"

  gntp-send -s "$client_ip" -p "$PASS" -a "Incoming Call" -n "Incoming Call Notify" \
            "$title" "$(echo -e "$msg")" "$ICON" "$url"
}

growl_notify >/dev/null 2>&1 &


Below is an example shell script asterisk-growl-notify-udp that can be customized to formulate the desired message notification.

Note -> The UDP version of Growl is compatible with older Growl implementations, such as Growl 1.2.2 for Mac OS X.

Note -> A clickable URL or custom icon is not supported with the older UDP version.

#!/bin/sh
##
## asterisk-growl-notify-udp
##
## Usage: asterisk-growl-notify-udp 'tel_name|tel_num|ext_num' client_ip
##

## Set to "yes" for North America Numbering, USA/Canada/etc.
NANPA="yes"

PASS="secret"

tel_name="$(echo "$1" | cut -s -d'|' -f1)"

tel_num="$(echo "$1" | cut -s -d'|' -f2)"

ext_num="$(echo "$1" | cut -s -d'|' -f3)"

client_ip="$2"

if [ -z "$client_ip" -o -z "$tel_num" ]; then
  echo "Usage: asterisk-growl-notify-udp 'tel_name|tel_num|ext_num' client_ip" >&2
  exit 1
fi

format_NANPA_number()
{
  echo "$1" | \
  sed -r -e 's/^([2-9])([0-9]{2})([2-9])([0-9]{2})([0-9]{4})$/\1\2-\3\4-\5/' \
         -e 's/^(1)([2-9])([0-9]{2})([2-9])([0-9]{2})([0-9]{4})$/\1-\2\3-\4\5-\6/'
}

growl_notify()
{
  local num date title msg

  if [ "$NANPA" = "yes" ]; then
    num="$(format_NANPA_number "$tel_num")"
    date="$(ldate '+%l:%M %p on %A, %B %e')"
  else
    num="$tel_num"
    date="$(ldate '+%X %A, %B %e')"
  fi

  title="Incoming Call"

  msg="$tel_name"
  msg="$msg${msg:+\n}$num"
  msg="$msg${ext_num:+\nfor $ext_num}"
  msg="$msg\n${date## }"

  gntp-send -u -s "$client_ip" -p "$PASS" -a "Incoming Call" -n "Incoming Call Notify" \
            "$title" "$(echo -e "$msg")"
}

growl_notify >/dev/null 2>&1


Mac OS X

Growl 1.2.2f1 (forked) version for Mac OS X works in the legacy UDP mode on newer OS versions (tested up to 10.13.6).
But it does neither support an icon nor a clickable URL in the notification.

Growl 2.x (4 USD from the Mac AppStore) was not tested. The Growl homepage notes: supported up to 10.9.5 (development has stalled!).

Windows

Snarl 3.1 and 5.0-beta-1 (from 01/2017) have been tested to work in TCP mode with the GNTP 1.0 protocol (tested on Win 10 64-bit, Win 7 32-bit).

Growl for Windows Last version 2.0.9 is from 2012, not tested (development has stalled!).

Linux Desktop

Growl for Linux Typically compile from source, not tested. Same author as gntp-send.

  • userdoc/tt_asterisk_call_notify.txt
  • Last modified: 2019/01/25 10:30
  • by mkeuter