def outgoing(self, message): ''' This will be called when messages go out. ''' msg = LoggedMessage.create_from_message(message) msg.direction = LoggedMessage.DIRECTION_OUTGOING # If an _outgoing_ message has a logger_id it is actually the logger_id # of the incoming message (because Message.respond does a copy.copy # on the message object). This is actually very convenient because # it allows us to match an outgoing message to the incoming message # that solicited it (assuming Message.respond) was used. if hasattr(message, 'logger_id'): try: orig_msg = LoggedMessage.incoming.get(pk=message.logger_id) except LoggedMessage.DoesNotExist: # Really no reason for this to ever happen, but if it does # we'll just silently continue, but we won't be able # to set the response_to field of this LoggedMessage pass else: # Set the response_to foreign key of this logged outgoing # message to the incoming message that it was copied from. msg.response_to = orig_msg msg.save() # Watermark the message object with the LoggedMessage pk. message.logger_id = msg.pk # Print message if debug self.debug(msg)
def handle(self, message): ''' This will be called when messages come in. We don't return return anything, so as far as rapidsms is concerned, we haven't handled it so it just keeps passing it along to the latter apps. ''' msg = LoggedMessage.create_from_message(message) msg.direction = LoggedMessage.DIRECTION_INCOMING msg.save() # Watermark the message object with the LoggedMessage pk. message.logger_id = msg.pk # Print message if debug self.debug(msg)