""" An inbound application that prompts the caller to enter a 4 digit pin. It waits at most 30 seconds for the caller to begin entering digits, then replays the digits to the caller before hanging up. """ from prosody.uas import Hangup, Error __uas_identify__ = "application" __uas_version__ = "1.0b2" def main(channel, application_instance_id, file_man, my_log, application_parameters): return_code = 0 try: if channel.state() == channel.State.CALL_INCOMING: channel.ring() # this can raise a Hangup exception channel.answer() # this can raise a Hangup exception else: raise Hangup('No inbound call') channel.FilePlayer.say("Please enter a four digit pin.", barge_in = True) # wait at most 30 seconds for the caller to begin entering digits digits = channel.DTMFDetector.get_digits(count=4, seconds_predigits_timeout = 30) if channel.DTMFDetector.cause() == channel.DTMFDetector.Cause.COUNT: channel.FilePlayer.say("The digits you entered are, {0}".format(", ".join(digits))) else: channel.FilePlayer.say ("No digits received. Hanging up.") return_code = -103 except Hangup as exc: my_log.info("Got Hangup: {0}".format(exc)) return_code = -100 except Error as exc: my_log.error("Got Error: {0}".format(exc)) return_code = -101 except Exception as exc: my_log.exception("Got unexpected exception: {0}".format(exc)) return_code = -102 finally: if channel.state() != channel.State.IDLE: channel.hang_up() return return_code