py-asterisk icon indicating copy to clipboard operation
py-asterisk copied to clipboard

OriginateResponse

Open ghost opened this issue 8 years ago • 1 comments

Hello! I'm unable to catch event named by 'OriginateResponse'. Its fired when pbx.Originate method used with Asynk=True. Using logger i found that my asterisk send it but event not fired. I found why: In _dispatch_packet(...) we first check 'Response' field and if it found we move it to response_buffer. And then we check 'Event' field with the same action. But here is OriginateResponse message: {'Event': 'OriginateResponse', 'Privilege': 'call,all', 'ActionID': '1513434723.7291746', 'Response': 'Success', 'Channel': <Asterisk.Manager.BaseChannel referencing channel '...' of <Asterisk.Manager.Manager connected as ...>>, 'Context': 'from-internal', 'Exten': '...', 'Reason': '4', 'Uniqueid': '1513434723.253', 'CallerIDNum': '', 'CallerIDName': '...'} As you can see it has Event field and Response field together. So it move to response buffer, but must go in event buffer. To fix it I move condition checks in _dispatch_packet(...) so Event field checks first. Here is code:

    def _dispatch_packet(self, packet):
        'Feed a single packet to an event handler.'

        if 'Event' in packet:
            self._translate_event(packet)
            self.log.debug('_dispatch_packet() passing event to on_Event.')
            self.on_Event(packet)

        elif 'Response' in packet:
            self.log.debug('_dispatch_packet() placed response in buffer.')
            self.response_buffer.append(packet)

        else:
            raise InternalError('Unknown packet type detected: %r' % (packet,))

I dont know maybe I break something else, but now I can see that event named OriginateResponse fired and catched properly.

ghost avatar Dec 16 '17 14:12 ghost

Hi, did you use listen_events=True in your test before patching ?

jeansch avatar May 08 '18 14:05 jeansch