def on_message(self, message: MessageProtocolEntity): receipt = OutgoingReceiptProtocolEntity( messageIds=message.getId(), to=message.getFrom(), read=True, participant=message.getParticipant()) today = datetime.datetime.now().isocalendar() target_dir = self.getProp(self.__class__.PROP_TARGET) target_file = f'{today[0]}-{today[1]}-{today[2]}.json' try: nice_message = self._jsonify(message) if nice_message: with open(os.path.join(target_dir, target_file), 'a', encoding='utf-8') as file: file.write(nice_message) file.write(os.linesep) else: log.info( f'Did not write non-text message with ID {message.getId()}' ) except Exception as e: log.warning(f'Unable to write message: {str(e)}') self.toLower(receipt)