-
Notifications
You must be signed in to change notification settings - Fork 9
/
messaging.py
95 lines (81 loc) · 3.01 KB
/
messaging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from aries_cloudcontroller import PingRequest, PingRequestResponse, SendMessage
from fastapi import APIRouter, Depends
from app.dependencies.acapy_clients import client_from_auth
from app.dependencies.auth import AcaPyAuth, acapy_auth_from_header
from app.exceptions.handle_acapy_call import handle_acapy_call
from app.models.messaging import Message, TrustPingMsg
from shared.log_config import get_logger
logger = get_logger(__name__)
router = APIRouter(prefix="/v1/messaging", tags=["messaging"])
@router.post("/send-message", summary="Send a Message")
async def send_messages(
message: Message,
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> None:
"""
Send basic message
---
Send a message to a tenant via a connection. The other tenant will receive
the message on topic `basic-message` for their webhook events.
See the Aries
[Basic Message Protocol](https://github.com/hyperledger/aries-rfcs/blob/main/features/0095-basic-message/README.md)
for more information.
Request body:
---
message: Message
connection_id: str
Connection ID of the connection to send the message to.
content: str
The message to send.
Returns:
---
Status code 204
"""
logger.debug("POST request received: Send message")
request_body = SendMessage(content=message.content)
async with client_from_auth(auth) as aries_controller:
await handle_acapy_call(
logger=logger,
acapy_call=aries_controller.basicmessage.send_message,
conn_id=message.connection_id,
body=request_body,
)
logger.debug("Successfully sent message.")
@router.post(
"/trust-ping", summary="Send Trust Ping", response_model=PingRequestResponse
)
async def send_trust_ping(
trustping_msg: TrustPingMsg,
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> PingRequestResponse:
"""
Send trust ping
---
Send a trust ping to a connection to ensure that the connection is active and ready.
See the Aries
[Trust Ping Protocol](https://github.com/hyperledger/aries-rfcs/blob/main/features/0048-trust-ping/README.md)
for more information.
Request body:
---
TrustPingMsg :
connection_id: str
Connection ID of the connection to send the trust ping to.
comment: str
Comment to include in the trust ping.
Returns:
---
PingRequestResponse
thread_id: str
Thread ID of the ping message
"""
logger.debug("POST request received: Send trust ping")
request_body = PingRequest(comment=trustping_msg.comment)
async with client_from_auth(auth) as aries_controller:
response = await handle_acapy_call(
logger=logger,
acapy_call=aries_controller.trustping.send_ping,
conn_id=trustping_msg.connection_id,
body=request_body,
)
logger.debug("Successfully sent trust ping.")
return response