abc-messenger/agent.py
Andrew Gundersen db2e6c4f15 minor improvments
2020-12-15 15:30:42 -06:00

38 lines
825 B
Python

import json
import asyncio
import websockets
import typs
class Agent:
"""Session interface for Crimata Agent
Receive core functionalities for communicating with Crimata
Agent in an OOP way.
"""
def __init__(self, connection):
self.service = None
self.client_connection = connection
async def recv_agent_intent(self):
package = await self.client_connection.recv()
jpackage = self.__decode(package)
return jpackage
async def send_agent_intent(self, jpackage):
package = self.__encode(jpackage)
await self.client_connection.send(package)
def __encode(self, jpackage):
package = json.dumps(jpackage)
return package
def __decode(self, package):
jpackage = json.loads(package)
return jpackage