""" An inbound application that prompts the user to enter a 4-digit pin that represents a conference room, to which they are then transferred. 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 anbound call - wait for four DTMF digits - create a tone player - transfer the call to the conference room - wait for the caller to hang up """ from prosody.uas import Hangup, Error, ToneManager __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))) # because this is a transfer, we need to create the tone player tone_manager = ToneManager(my_log) channel.create_tone_player(tone_manager) if channel.transfer_to_conference_room(out_channel, digits) is False: my_log.error("Transfer 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 ("Transfer 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