# session.py import time import asyncio import mail import agent import schemes class Session(schemes.Schemes, agent.Agent, mail.Mail): """Launch instance for every client connection. Will recv messages from client and push them to mailbox. Also, will pull messages from mailbox and send to client. """ def __init__(self, connection): agent.Agent.__init__(self, connection) self.crimata_id = False print("Launched new session") # Recv intents run desired endpoint. async def do_agent_intents(self): while True: # Recv intent from agent. intent = await self.recv_agent_intent() print(f"Intent: {intent.name}") # Call corresponding endpoint. await self.handle_intent(intent) await asyncio.sleep(0.1) # Send mail back to agent. async def deliver_mail(self): while True: # Sleep until Crimata ID. if not self.crimata_id: await asyncio.sleep(1) continue intent = await self.mailbox_recv() await self.send_agent_intent(intent) await asyncio.sleep(0.1) # async def hello(self): # intent = await self.recv_agent_intent() # response = await self.fetch("crimata_id", service="message") # self.profile = response.get("profile") # target = intent.params.get("target") # await self.notify(f"Messenger APP: Received Message Intent", # service="message", complete=True) # print("Shutting down in 10s") # await asyncio.sleep(10)