Skip to content

Commit eb9163a

Browse files
committed
Refactor attachment protocol tutorial
* TODO: release v0.4 of aries-agent-controller * is required because the setup pulls aries-agent-controller from pypi and the current version 0.3 lacks the new controller layout
1 parent 9c6c56b commit eb9163a

File tree

6 files changed

+38
-25
lines changed

6 files changed

+38
-25
lines changed

helpers/create_connection/create_connection.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
BOB_WEBHOOK_BASE = os.getenv('BOB_WEBHOOK_BASE')
2020

2121

22-
23-
24-
2522
async def start_agent():
2623

2724
time.sleep(10)
2825

2926
# Inviter
30-
bob_agent_controller = AriesAgentController(webhook_host=BOB_WEBHOOK_HOST, webhook_port=BOB_WEBHOOK_PORT,
31-
webhook_base=BOB_WEBHOOK_BASE, admin_url=BOB_ADMIN_URL)
32-
27+
bob_agent_controller = AriesAgentController(admin_url=BOB_ADMIN_URL)
3328

3429
# Invitee
35-
alice_agent_controller = AriesAgentController(webhook_host=ALICE_WEBHOOK_HOST, webhook_port=ALICE_WEBHOOK_PORT,
36-
webhook_base=ALICE_WEBHOOK_BASE, admin_url=ALICE_ADMIN_URL, api_key=ALICE_API_KEY)
30+
alice_agent_controller = AriesAgentController(
31+
admin_url=ALICE_ADMIN_URL,
32+
api_key=ALICE_API_KEY)
3733

34+
# alice_agent_controller.init_webhook_server(
35+
# webhook_host=ALICE_WEBHOOK_HOST,
36+
# webhook_port=ALICE_WEBHOOK_PORT,
37+
# webhook_base=ALICE_WEBHOOK_BASE)
3838

3939
# await alice_agent_controller.listen_webhooks()
4040
#
@@ -113,4 +113,3 @@ async def start_agent():
113113
asyncio.get_event_loop().run_until_complete(start_agent())
114114
except KeyboardInterrupt:
115115
os._exit(1)
116-
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from aries_basic_controller.aries_controller import AriesAgentController
22
from .protocol_controller import ProtocolController
33

4+
from dataclasses import dataclass
45

6+
7+
@dataclass
58
class AttachmentController(AriesAgentController):
69

7-
def __init__(self, webhook_host: str, webhook_port: int, admin_url: str, webhook_base: str = "",
8-
connections: bool = True, messaging: bool = True, issuer: bool = True, api_key = None):
9-
super().__init__(webhook_host, webhook_port, admin_url, webhook_base,
10-
connections, messaging, issuer, api_key=api_key)
10+
def __post_init__(self):
11+
super().__post_init__()
1112

12-
self.protocol = ProtocolController(admin_url, self.client_session, self.connections)
13+
self.protocol = ProtocolController(
14+
self.admin_url, self.client_session, self.connections)

libs/attachment-controller/attachment_controller/protocol_controller.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
from aiohttp import ClientSession
55

6+
67
# This is an example for how we might extend the basic controller
78
class ProtocolController(BaseController):
89

9-
def __init__(self, admin_url: str, client_session: ClientSession, connections_controller: ConnectionsController):
10+
def __init__(
11+
self, admin_url: str,
12+
client_session: ClientSession,
13+
connections_controller: ConnectionsController):
14+
1015
super().__init__(admin_url, client_session)
1116
self.connections = connections_controller
1217

@@ -17,6 +22,4 @@ async def send_attachment(self, connection_id, data):
1722
path = f"/connections/{connection_id}/send-attachment"
1823
return await self.admin_POST(path, data=data)
1924

20-
# async def store_attachment(self,data):
21-
22-
25+
# async def store_attachment(self,data):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aries-basic-controller>=0.1.1
1+
aries-basic-controller>=0.4

tutorials/3. Attachments/notebooks/alice/attachment.ipynb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,18 @@
4545
"API_KEY = \"alice_api_123456789\"\n",
4646
"\n",
4747
"# Based on the aca-py agent you wish to control\n",
48-
"attach_controller = AttachmentController(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT,\n",
49-
" webhook_base=WEBHOOK_BASE, admin_url=ADMIN_URL, api_key=API_KEY)"
48+
"attach_controller = AttachmentController(admin_url=ADMIN_URL, api_key=API_KEY)"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"attach_controller.init_webhook_server(webhook_host=WEBHOOK_HOST,\n",
58+
" webhook_port=WEBHOOK_PORT,\n",
59+
" webhook_base=WEBHOOK_BASE)"
5060
]
5161
},
5262
{
@@ -193,7 +203,7 @@
193203
"name": "python",
194204
"nbconvert_exporter": "python",
195205
"pygments_lexer": "ipython3",
196-
"version": "3.7.6"
206+
"version": "3.8.5"
197207
},
198208
"pycharm": {
199209
"stem_cell": {

tutorials/3. Attachments/notebooks/bob/attachment.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
"ADMIN_URL = \"http://bob-agent:8051\"\n",
3838
"\n",
3939
"# Based on the aca-py agent you wish to control\n",
40-
"attach_controller = AttachmentController(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT,\n",
41-
" webhook_base=WEBHOOK_BASE, admin_url=ADMIN_URL)"
40+
"attach_controller = AttachmentController(admin_url=ADMIN_URL)"
4241
]
4342
},
4443
{
@@ -161,7 +160,7 @@
161160
"name": "python",
162161
"nbconvert_exporter": "python",
163162
"pygments_lexer": "ipython3",
164-
"version": "3.7.6"
163+
"version": "3.8.5"
165164
}
166165
},
167166
"nbformat": 4,

0 commit comments

Comments
 (0)