code: async def on_message(self, event):
          
          # We want to show only messages sent to this chat
          if event.chat_id != self.chat_id:
              return
  
          # Save the message ID so we know which to reply to
          self.message_ids.append(event.id)
  
          # Decide a prefix (">> " for our messages, "<user>" otherwise)
          if event.out:
              text = '>> '
          else:
              sender = await event.get_sender()
              text = '<{}> '.format(sanitize_str(
                  utils.get_display_name(sender)))
  
          # If the message has media show "(MediaType) "
          if event.media:
              text += '({}) '.format(event.media.__class__.__name__)
  
          text += sanitize_str(event.text)
          text += '\n'
  
          # Append the text to the end with a newline, and scroll to the end
          self.log.insert(tkinter.END, text)
          self.log.yview(tkinter.END)
docs: Event handler that will add new messages to the message log.