#!/bin/sh
# $Header: /boot/home/code/cvsroot/scripts/BasicAnsweringMachine,v 1.2 1998/05/17 02:21:24 jrand Exp $
#
#  BasicAnsweringMachine
#
#  By: Jeremy Rand
#    Copyright 1997
#
# This script answers the phone and attempts to play a voice message.
# Once the message is played, it starts recording a message from the
# caller.  After the recording is complete, it hangs up the phone.
#

cleanup () {
  ./tellModem -d onhook "$MODEM" stop > /dev/null
  exit
  }

cd "$1"
MODEM="$2"
MESSAGE="$3"

RESULT=`./tellModem -d offhook "$MODEM" play`

if echo $RESULT | grep 'Error' > /dev/null
then
  cleanup
fi

if echo $RESULT | grep 'Event' > /dev/null
then
  ./tellModem "$MODEM" stop > /dev/null
fi

RESULT=`./tellModem -D 6 "$MODEM" record "$MESSAGE"`

if echo $RESULT | grep 'Error' > /dev/null
then
  cleanup
fi

cleanup
