Exemplo n.º 1
0
class UnblockCall(BaseAsteriskAppCall):
    """ unblockes a caller using asterisk. A new instance is created for each call.   """

    def __init__(self, ari_client, channel, asterisk_app_name, dialed_extension):
        """
        :param ari_client: the ari client instance
        :param channel: the active channel with the handset
        """
        super(UnblockCall, self).__init__(ari_client, channel, asterisk_app_name)
        self.dialed_extension = dialed_extension
        self.state_machine = None
        self.setup_state_machine()

    def setup_state_machine(self):
        """ setup the states and start the initial state """
        unblock = UnblockState(self, self.dialed_extension)
        done = GenericPlaybackState(self, 'sound:/telewall/sounds/de/unblock-done')
        invalid = GenericPlaybackState(self, 'sound:/telewall/sounds/de/phonenumber-invalid')
        hungup_state = HungUpState(self)
        ending_state = EndingState(self)

        self.state_machine = StateMachine()

        self.state_machine.add_transition(unblock, Event.ACTION_COMPLETE, done)
        self.state_machine.add_transition(unblock, Event.INVALID_INPUT, invalid)

        self.state_machine.add_transition(done, Event.PLAYBACK_COMPLETE, ending_state)
        self.state_machine.add_transition(invalid, Event.PLAYBACK_COMPLETE, ending_state)

        # hangup event is in every state
        for state in [unblock, done, invalid]:
            self.state_machine.add_transition(state, Event.HANGUP, hungup_state)

        self.state_machine.start(unblock)
Exemplo n.º 2
0
class VoiceMailCall(object):
    def __init__(self, ari_client, channel, mailbox):
        self.client = ari_client
        self.channel = channel
        self.vm_path = time.time()
        self.setup_state_machine()

    def setup_state_machine(self):
        # This is where we will initialize states, create a state machine, add
        # state transitions to the state machine, and start the state machine.
        hungup_state = HungUpState(self)
        recording_state = RecordingState(self)
        ending_state = EndingState(self)
        reviewing_state = ReviewingState(self)
        greeting_state = GreetingState(self)

        self.state_machine = StateMachine()
        self.state_machine.add_transition(recording_state,
                                          Event.DTMF_OCTOTHORPE,
                                          reviewing_state)
        self.state_machine.add_transition(recording_state, Event.HANGUP,
                                          hungup_state)
        self.state_machine.add_transition(recording_state, Event.DTMF_STAR,
                                          recording_state)
        self.state_machine.add_transition(reviewing_state, Event.HANGUP,
                                          hungup_state)
        self.state_machine.add_transition(reviewing_state,
                                          Event.DTMF_OCTOTHORPE, ending_state)
        self.state_machine.add_transition(reviewing_state, Event.DTMF_STAR,
                                          recording_state)
        self.state_machine.add_transition(greeting_state, Event.HANGUP,
                                          hungup_state)
        self.state_machine.add_transition(greeting_state,
                                          Event.PLAYBACK_COMPLETE,
                                          recording_state)
        self.state_machine.start(greeting_state)
Exemplo n.º 3
0
class IncomingCall(BaseAsteriskAppCall):
    """ manages an incoming call using asterisk. A new instance is created for each call.   """

    def __init__(self, ari_client, channel, handset_endpoint, asterisk_app_name):
        """
        :param ari_client: the ari client instance
        :param channel: the active channel with the handset_endpoint
        """
        super(IncomingCall, self).__init__(ari_client, channel, asterisk_app_name)
        self.handset_endpoint = handset_endpoint
        self.call_state = CallState.instance()

        self.state_machine = None
        self.setup_state_machine()

    def setup_state_machine(self):
        """ setup the states and start the initial state """
        check_caller = CheckCallerState(self)
        call_handset = CallHandsetState(self)
        playback_refused = PlaybackRefusedState(self, hangup_caller_when_hangup_handset=False)
        call_connected = CallConnectedState(self)

        hungup_state = HungUpState(self)
        ending_state = EndingState(self)

        self.state_machine = StateMachine()

        # identification
        self.state_machine.add_transition(check_caller, Event.CALLER_ALLOWED, call_handset)
        self.state_machine.add_transition(check_caller, Event.CALLER_REFUSED, playback_refused)

        # allowed
        self.state_machine.add_transition(call_handset, Event.ANSWER, call_connected)
        self.state_machine.add_transition(call_handset, Event.BUSY, ending_state)
        self.state_machine.add_transition(call_connected, Event.CALLER_REFUSED, playback_refused)

        # refused
        self.state_machine.add_transition(playback_refused, Event.PLAYBACK_COMPLETE, ending_state)

        # hangup event is in every state (except the final states hangup and ending)
        for state in [check_caller, call_handset, playback_refused, playback_refused, call_connected]:
            self.state_machine.add_transition(state, Event.HANGUP, hungup_state)

        self.state_machine.start(check_caller)
Exemplo n.º 4
0
class ManageRecordingCall(BaseAsteriskAppCall):
    """ manages the announcement using asterisk. A new instance is created for each call.   """

    def __init__(self, ari_client, channel, asterisk_app_name):
        """
        :param ari_client: the ari client instance
        :param channel: the active channel with the handset
        """
        super(ManageRecordingCall, self).__init__(ari_client, channel, asterisk_app_name)
        self.state_machine = None
        self.setup_state_machine()

    def setup_state_machine(self):
        """ setup the states and start the initial state """
        main_menu = DtmfMenuState(self, 'sound:/telewall/sounds/de/mainmenu', allowed_keys=['1', '2', '3'])
        playback = PlaybackRefusedState(self)
        recording_instruction = GenericPlaybackState(self, 'sound:/telewall/sounds/de/record-announcement-instruction')
        recording = RecordingState(self)
        recording_reset = ResetRecordingState(self)
        recording_reset_done = GenericPlaybackState(self, 'sound:/telewall/sounds/de/reset-announcement-done')
        hungup_state = HungUpState(self)
        ending_state = EndingState(self)

        self.state_machine = StateMachine()
        self.state_machine.add_transition(main_menu, Event.DTMF_1, playback)
        self.state_machine.add_transition(main_menu, Event.DTMF_2, recording_instruction)
        self.state_machine.add_transition(main_menu, Event.DTMF_3, recording_reset)

        # 1: playback
        self.state_machine.add_transition(playback, Event.PLAYBACK_COMPLETE, ending_state)

        # 2: recording
        self.state_machine.add_transition(recording_instruction, Event.PLAYBACK_COMPLETE, recording)

        # 3: reset recording
        self.state_machine.add_transition(recording_reset, Event.ACTION_COMPLETE, recording_reset_done)
        self.state_machine.add_transition(recording_reset_done, Event.PLAYBACK_COMPLETE, main_menu)

        # hangup event is in every state
        for state in [main_menu, playback, recording_instruction, recording, recording_reset,
                      recording_reset_done]:
            self.state_machine.add_transition(state, Event.HANGUP, hungup_state)

        self.state_machine.start(main_menu)