# mail.py import typs import mailroom class Mail: """Session interface for mailroom. Two main IO methods. Will translate intents to mail and vice versa. Should be a parent class of Session. """ def __init__(self): self.crimata_id = False # Receive intent. async def mailbox_recv(self): mail = await mailroom.get_mail(self.crimata_id) intent = self.__decode(mail) return intent # Send intent. def mailbox_send(self, intent): mail = self.__encode(intent) print(f"Putting message into outbox {self.crimata_id}") mailroom.put_mail(self.crimata_id, mail) def __encode(self, intent: typs.Intent) -> typs.Mail: p = intent.params owner = self.crimata_id target = p.get("target") text = p.get("text") audio = p.get("audio") mail = typs.Mail(owner, target, text, audio) return mail @staticmethod def __decode(mail: typs.Mail) -> typs.Intent: name = "message" params = { "owner": mail.owner, "text": mail.text, #dev only "audio": mail.audio } intent = typs.Intent(name, params) return intent