async def basic_message(agent, msg): await a.send({ "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/basicmessage/1.0/message", "~l10n": {"locale": "en"}, "sent_time": utils.timestamp(), "content": "You said: {}".format(msg['content']) })
async def basic_message_auto_responder(msg, conn): await conn.send_async({ "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/" "basicmessage/1.0/message", "~l10n": {"locale": "en"}, "sent_time": utils.timestamp(), "content": "You said: {}".format(msg['content']) })
async def message(self, _msg, conn): """ Respond to basic messages with a count of messages received. """ self.count += 1 await conn.send_async({ "@type": self.type("message"), "~l10n": {"locale": "en"}, "sent_time": utils.timestamp(), "content": "{} message(s) received.".format(self.count) })
async def basic_message_auto_responder(msg, conn): await conn.send_async({ "@type": "https://didcomm.org/" "basicmessage/1.0/message", "~l10n": { "locale": "en" }, "sent_time": utils.timestamp(), "content": "You said: {}".format(msg["content"]), })
async def basic_message(msg, conn): """Respond to a basic message.""" await conn.send_async( { "@type": "https://didcomm.org/" "basicmessage/1.0/message", "~l10n": {"locale": "en"}, "sent_time": utils.timestamp(), "content": "The preprocessor validated this message", } )
def main(): """Send message from cron job.""" keys, target, _args = config() conn = Connection(keys, target) conn.send({ "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/basicmessage/1.0/message", "~l10n": { "locale": "en" }, "sent_time": utils.timestamp(), "content": "The Cron script was executed.", })
async def test_webserver_with_websockets(example_keys, test_keys, connection_ws, listening_endpoint, unused_tcp_port_factory): """Test the webserver with websockets example.""" example_port = unused_tcp_port_factory() connection_ws.target.update( endpoint="http://*****:*****@type": "https://didcomm.org/" "basicmessage/1.0/message", "~l10n": { "locale": "en" }, "sent_time": utils.timestamp(), "content": "Your hovercraft is full of eels.", }, return_route="all", ) msg = await queue.get(timeout=30) assert "basicmessage" in msg.type assert msg["content"] == "You said: Your hovercraft is full of eels." process.terminate() await process.wait()
def main(): """Send message from cron job.""" args = config() conn = StaticConnection( (args.my_verkey, args.my_sigkey), their_vk=args.their_verkey, endpoint=args.endpoint, ) conn.send({ "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/" "basicmessage/1.0/message", "~l10n": { "locale": "en" }, "sent_time": utils.timestamp(), "content": "The Cron script was executed." })
def main(): """ Cron example. """ args = config() conn = StaticConnection( (args.mypublickey, args.myprivatekey), their_vk=args.endpointkey, endpoint=args.endpoint, ) conn.send({ "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/" "basicmessage/1.0/message", "~l10n": { "locale": "en" }, "sent_time": utils.timestamp(), "content": "The Cron Script has been executed." })
async def test_webserver_aiohttp(example_keys, test_keys, connection, listening_endpoint, unused_tcp_port_factory): """Test the webserver aiohttp example.""" example_port = unused_tcp_port_factory() connection.update(endpoint='http://*****:*****@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/" "basicmessage/1.0/message", "~l10n": { "locale": "en" }, "sent_time": utils.timestamp(), "content": "Your hovercraft is full of eels." }) msg = await asyncio.wait_for(next_msg, 30) assert 'basicmessage' in msg.type assert msg['content'] == 'You said: Your hovercraft is full of eels.' process.terminate() await process.wait()
def main(): """Start a server with a static connection.""" keys = crypto.create_keypair( seed=hashlib.sha256(b'client').digest() ) their_vk, _ = crypto.create_keypair( seed=hashlib.sha256(b'server').digest() ) conn = StaticConnection( keys, their_vk=their_vk, endpoint='http://*****:*****@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/" "basicmessage/1.0/message", "~l10n": {"locale": "en"}, "sent_time": utils.timestamp(), "content": "The Cron Script has been executed." }, return_route='all') print('Msg from conn:', reply and reply.pretty_print())
def main(): """Send a message and await the reply.""" their_vk, _ = crypto.create_keypair( seed=hashlib.sha256(b"server").digest()) conn = Connection.from_seed( hashlib.sha256(b"client").digest(), Target( their_vk=their_vk, endpoint="http://*****:*****@type": "https://didcomm.org/basicmessage/1.0/message", "~l10n": { "locale": "en" }, "sent_time": utils.timestamp(), "content": "The Cron script has been executed.", }, return_route="all", ) print("Msg from conn:", reply and reply.pretty_print())
def environ_or_required(key): if os.environ.get(key): return {'default': os.environ.get(key)} else: return {'required': True} # above from https://stackoverflow.com/questions/10551117/setting-options-from-environment-variables-when-using-argparse # Thought: Should we include arg parsing help into the staticagent library? # endpoint can be http or ws, auto handled by staticagent library. parser = argparse.ArgumentParser() parser.add_argument('--endpoint', **environ_or_required('ARIES_ENDPOINT')) parser.add_argument('--endpointkey', **environ_or_required('ARIES_ENDPOINT_KEY')) parser.add_argument('--mypublickey', **environ_or_required('ARIES_MY_PUBLIC_KEY')) parser.add_argument('--myprivatekey', **environ_or_required('ARIES_MY_PRIVATE_KEY')) args = parser.parse_args() # Config End a = StaticAgentConnection(args.endpoint, args.endpointkey, args.mypublickey, args.myprivatekey) # TODO: the send() method will apply an id if not present a.send({ "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/basicmessage/1.0/message", "~l10n": {"locale": "en"}, "sent_time": utils.timestamp(), "content": "The Cron Script has been executed." })
def test_timestamp(): """ Test that the timestamp looks right. """ timestamp = utils.timestamp() assert MATCH(timestamp)