""" An inbound application that answers the call, prompts the caller to record a message (and to press any key to stop recording), plays a beep to indicate that it is recording and then records for a maximum of 60 seconds. The recorded filename is samples/voicemail1/recordedMessageFrom.wav The application will check that the recorded message file exists before exiting. Actions: - check the channel state - ring and answer - use TTS to play a prompt - record a file - check that the file exists - hang up This application is part of the Voice Mail tutorial at https://cloud.aculab.com/documents/voicemail. """ from prosody.uas import Hangup, Error __uas_version__ = "0.0.1" __uas_identify__ = "application" def main (channel, application_instance_id, file_man, my_log, application_parameters): return_code = 0 try: # check the incoming channel state state = channel.state() if state == channel.State.CALL_INCOMING: state = channel.ring() # this can raise a Hangup exception if state == channel.State.RING_INCOMING: state = channel.answer() # this can raise a Hangup exception else: raise Hangup('No inbound call, state is {0}'.format(state)) if state != channel.State.ANSWERED: raise Hangup('Failed to answer inbound call, state is {0}'.format(state)) my_log.info("Answered an inbound call") cause = channel.FilePlayer.say ("Please record a message after the tone. Press any digit to stop the recording.") if cause != channel.FilePlayer.Cause.NORMAL: raise Error("Say please record failed: cause is {0}".format(cause)) msg_file_name = "samples/voicemail1/recordedMessageFrom{0}.wav".format(channel.Details.call_from) cause = channel.DTMFPlayer.play ('#') if cause != channel.DTMFPlayer.Cause.NORMAL: raise Error ("Play # failed: cause is {0}".format (digits, cause)) cause = channel.FileRecorder.record(msg_file_name, milliseconds_max_silence=3000, seconds_timeout=60, barge_in=True) if cause != channel.FileRecorder.Cause.SILENCE and cause != channel.FileRecorder.Cause.BARGEIN: raise Error("Record message failed: cause is {0}".format(cause)) if file_man.exists("samples/voicemail1/recordedMessageFrom{0}.wav".format(channel.Details.call_from)): cause = channel.FilePlayer.say ("Your message has been saved. Good bye.") if cause != channel.FilePlayer.Cause.NORMAL: raise Error("Say saved failed: cause is {0}".format(cause)) else: cause = channel.FilePlayer.say ("Your message could not be saved. Good bye.") if cause != channel.FilePlayer.Cause.NORMAL: raise Error("Say saved failed: cause is {0}".format(cause)) except Hangup as exc: my_log.info ("Hangup exception: {0}.".format(exc)) return_code = 100 except Error as exc: my_log.error("Error execption caught: {0}".format(exc)) return_code = -101 except Exception as exc: my_log.exception("Unexpected exception caught: {0}".format(exc)) return_code = -102 finally: if channel.state() != channel.State.IDLE: channel.hang_up() my_log.info("Example completed") return return_code