abc-messenger/mail.py
Andrew Gundersen 5b54f3f636 working v1
2020-11-21 14:43:17 -06:00

42 lines
No EOL
853 B
Python

# mail.py
import typs
import mailroom
class Mail:
"""Session interface for mailroom.
Two main IO methods. Will translate intents to mail and vice versa.
"""
def __init__(self):
pass
# 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)
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")
mail = typs.Mail(owner, target, text)
return mail
@staticmethod
def __decode(mail: typs.Mail) -> typs.Intent:
name = "notify"
params = {
"text": mail.text #dev only
}
intent = typs.Intent(name, params)
return intent