""" An inbound application that prompts the user to enter a 4-digit pin that represents a conference room, to which they are then connected. Please read the documentation about conference rooms. The application uses TTS to communicate with the caller. This application requires 1 extra channel. Actions: - wait for inbound call - wait for four DTMF digits - create a tone player - connect the call to the conference room - wait for the caller to hang up """ from prosody.uas import Hangup, Error from prosody.uas.highlevel import HighLevelCallChannel __uas_identify__ = "application" __uas_version__ = "1.0b1" 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') # get the extra channel try: out_channel = channel.ExtraChannel[0] except: raise Error("You need to register an extra channel for this application") channel.FilePlayer.say("Please enter a four digit conference i d.", barge_in = True) digits = channel.DTMFDetector.get_digits(count=4, seconds_predigits_timeout = 10) if channel.DTMFDetector.cause() == channel.DTMFDetector.Cause.COUNT: channel.FilePlayer.say("Adding you to conference {0}".format(", ".join(digits))) high_level_channel = HighLevelCallChannel(channel, my_log) if high_level_channel.call_and_connect_to_conference(other_call=out_channel, conference_room_name=digits) is False: my_log.error("Connect to conference. Hanging up") channel.FilePlayer.say ("Sorry, I could not connect you to your conference. Good bye") return_code = -104 else: my_log.info ("Connect to conference {0} succeeded. Waiting for idle.".format (digits)) channel.wait_for_idle(seconds_timeout=None) else: channel.FilePlayer.say ("I did not receive four digits. Hanging up.") return_code = -103 except Hangup as exc: my_log.info("Got Hangup") return_code = -100 except Error as exc: my_log.error("Got Error {0}".format(exc)) return_code = -102 except Exception as exc: my_log.exception("Got unexpected exception {0}".format(exc)) return_code = -101 finally: if channel.state() != channel.State.IDLE: channel.hang_up() return return_code