Create a new notification when there is a missed call

master
Miles Alan 4 years ago
parent 5f8aad0386
commit 17fb103ee3
  1. 71
      scripts/modem/sxmo_modemmonitor.sh

@ -20,46 +20,62 @@ modem_n() {
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
} }
checkforincomingcalls() { lookupnumberfromcallid() {
VOICECALLID="$( VOICECALLID=$1
mmcli -m "$(modem_n)" --voice-list-calls -a | mmcli -m "$(modem_n)" --voice-list-calls -o "$VOICECALLID" -K |
grep -Eo '[0-9]+ incoming \(ringing-in\)' | grep call.properties.number |
grep -Eo '[0-9]+' cut -d ':' -f 2 |
)" tr -d ' +'
echo "$VOICECALLID" | grep -v . && rm -f "$NOTIFDIR/incomingcall" && return }
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/ring"
else
sxmo_vibratepine 2000 &
fi
# Delete all previous calls which have been terminated calls checkformissedcalls() {
for CALLID in $( if pgrep -vf sxmo_modemcall.sh; then
# Add a notification for every missed call
# Note sxmo_modemcall.sh cleanups/delete the callid from the modem; so
# effectivly any incoming call thats terminated here is a missed call!
for MISSEDCALLID in $(
mmcli -m "$(modem_n)" --voice-list-calls | mmcli -m "$(modem_n)" --voice-list-calls |
grep incoming |
grep terminated | grep terminated |
grep -oE "Call\/[0-9]+" | grep -oE "Call\/[0-9]+" |
cut -d'/' -f2 cut -d'/' -f2
); do ); do
mmcli -m "$(modem_n)" --voice-delete-call "$CALLID" MISSEDNUMBER="$(lookupnumberfromcallid $MISSEDCALLID)"
mmcli -m "$(modem_n)" --voice-delete-call "$MISSEDCALLID"
TIME="$(date --iso-8601=seconds)"
mkdir -p "$LOGDIR"
printf %b "$TIME\tcall_missed\t$MISSEDNUMBER\n" >> "$LOGDIR/modemlog.tsv"
CONTACT="$(sxmo_contacts.sh | grep -E "^$MISSEDNUMBER")"
RUNCOMMAND=""
sxmo_notificationwrite.sh \
random \
"st -f Terminus-20 -e sh -c \"echo 'Missed call from $CONTACT at $(date)' && read\"" \
none \
"Missed call - $CONTACT"
done done
fi
}
checkforincomingcalls() {
VOICECALLID="$(
mmcli -m "$(modem_n)" --voice-list-calls -a |
grep -Eo '[0-9]+ incoming \(ringing-in\)' |
grep -Eo '[0-9]+'
)"
echo "$VOICECALLID" | grep -v . && rm -f "$NOTIFDIR/incomingcall" && return
# Determine the incoming phone number # Determine the incoming phone number
echo "Incoming Call:" echo "Incoming Call:"
INCOMINGNUMBER=$( INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID")
mmcli -m "$(modem_n)" --voice-list-calls -o "$VOICECALLID" -K |
grep call.properties.number |
cut -d ':' -f 2 |
tr -d ' +'
)
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/ring" "$(sxmo_contacts.sh | grep -E "^$INCOMINGNUMBER")" "$XDG_CONFIG_HOME/sxmo/hooks/ring" "$(sxmo_contacts.sh | grep -E "^$INCOMINGNUMBER")"
else else
sxmo_vibratepine 2000 & sxmo_vibratepine 2500 &
fi fi
# Log to /tmp/incomingcall to allow pickup and log into modemlog
TIME="$(date --iso-8601=seconds)" TIME="$(date --iso-8601=seconds)"
mkdir -p "$LOGDIR" mkdir -p "$LOGDIR"
printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv" printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv"
@ -67,8 +83,8 @@ checkforincomingcalls() {
sxmo_notificationwrite.sh \ sxmo_notificationwrite.sh \
"$NOTIFDIR/incomingcall" \ "$NOTIFDIR/incomingcall" \
"sxmo_modemcall.sh pickup $VOICECALLID" \ "sxmo_modemcall.sh pickup $VOICECALLID" \
"none" \ none \
"Pickup $(sxmo_contacts.sh | grep -E "^$INCOMINGNUMBER")" & "Pickup - $(sxmo_contacts.sh | grep -E "^$INCOMINGNUMBER")" &
echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)" echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)"
} }
@ -101,7 +117,7 @@ checkfornewtexts() {
random \ random \
"st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" \ "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" \
"$LOGDIR/$NUM/sms.txt" \ "$LOGDIR/$NUM/sms.txt" \
"Message from $(sxmo_contacts.sh | grep -E "^$NUM:"): $TEXT" & "Message - $(sxmo_contacts.sh | grep -E "^$NUM:"): $TEXT"
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/sms" ]; then if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/sms" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/sms" "$(sxmo_contacts.sh | grep -E "^$INCOMINGNUMBER")" "$TEXT" "$XDG_CONFIG_HOME/sxmo/hooks/sms" "$(sxmo_contacts.sh | grep -E "^$INCOMINGNUMBER")" "$TEXT"
@ -111,6 +127,7 @@ checkfornewtexts() {
mainloop() { mainloop() {
while true; do while true; do
checkformissedcalls
checkforincomingcalls checkforincomingcalls
checkfornewtexts checkfornewtexts
sleep $TIMEOUT & wait sleep $TIMEOUT & wait

Loading…
Cancel
Save