""" A simple example that will answer an inbound call and play a wav file. The wav to play is passed in through application_parameters, which is configured on the inbound services page of the CWP. Actions: - check the channel state - ring and answer - play a file - file name in application_parameters - hang up """ from prosody.uas import Hangup, Error import time __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") # log at info level # play a wav file, file name is provided in application_parameters cause = channel.FilePlayer.play(application_parameters) if cause != channel.FilePlayer.Cause.NORMAL: raise Error("Say hello failed: cause is {0}".format(cause)) # Bye bye cause = channel.FilePlayer.say("Bye bye.") if cause != channel.FilePlayer.Cause.NORMAL: raise Error("Say bye bye failed: cause is {0}".format(cause)) except Hangup as exc: my_log.info("Hangup exception reports: {0}".format(exc)) # in this app a hangup is not an error, return a positive value return_code = 100 except Error as exc: # for error conditions return a negative value my_log.error("Error exception reports: {0}".format(exc)) return_code = -101 except Exception as exc: # an unexpected exception, return a negative value my_log.exception("Unexpected exception reports: {0}".format(exc)) return_code = -102 finally: if channel.state() != channel.State.IDLE: channel.hang_up() return return_code