2021-04-09 10:17:38 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2021-04-15 16:14:54 +02:00
|
|
|
from aiogrpcclient import BaseGrpcClient
|
2021-04-12 19:47:21 +02:00
|
|
|
from idm.api.proto.chat_manager_service_pb2 import Chat as ChatPb
|
2021-04-09 10:17:38 +02:00
|
|
|
from nexus.hub.proto.delivery_service_pb2 import \
|
|
|
|
StartDeliveryRequest as StartDeliveryRequestPb
|
|
|
|
from nexus.hub.proto.delivery_service_pb2 import \
|
|
|
|
StartDeliveryResponse as StartDeliveryResponsePb
|
|
|
|
from nexus.hub.proto.delivery_service_pb2_grpc import DeliveryStub
|
|
|
|
from nexus.hub.proto.submitter_service_pb2 import \
|
|
|
|
SubmitRequest as SubmitRequestPb
|
|
|
|
from nexus.hub.proto.submitter_service_pb2 import \
|
|
|
|
SubmitResponse as SubmitResponsePb
|
|
|
|
from nexus.hub.proto.submitter_service_pb2_grpc import SubmitterStub
|
|
|
|
from nexus.models.proto.typed_document_pb2 import \
|
|
|
|
TypedDocument as TypedDocumentPb
|
|
|
|
|
|
|
|
|
2021-04-15 16:14:54 +02:00
|
|
|
class HubGrpcClient(BaseGrpcClient):
|
|
|
|
stub_clses = {
|
|
|
|
'delivery': DeliveryStub,
|
|
|
|
'submitter': SubmitterStub,
|
|
|
|
}
|
2021-04-09 10:17:38 +02:00
|
|
|
|
|
|
|
async def start_delivery(
|
|
|
|
self,
|
|
|
|
typed_document_pb: TypedDocumentPb,
|
2021-04-12 19:47:21 +02:00
|
|
|
chat: ChatPb,
|
2021-04-09 10:17:38 +02:00
|
|
|
request_id: Optional[str],
|
|
|
|
session_id: Optional[str],
|
|
|
|
) -> StartDeliveryResponsePb:
|
2021-04-15 16:14:54 +02:00
|
|
|
return await self.stubs['delivery'].start_delivery(
|
2021-04-09 10:17:38 +02:00
|
|
|
StartDeliveryRequestPb(
|
|
|
|
typed_document=typed_document_pb,
|
|
|
|
chat=chat,
|
|
|
|
),
|
|
|
|
metadata=(('request-id', request_id), ('session-id', session_id))
|
|
|
|
)
|
|
|
|
|
|
|
|
async def submit(
|
|
|
|
self,
|
|
|
|
telegram_document: bytes,
|
|
|
|
telegram_file_id: str,
|
2021-04-12 19:47:21 +02:00
|
|
|
chat: ChatPb,
|
2021-04-09 10:17:38 +02:00
|
|
|
request_id: Optional[str] = None,
|
|
|
|
session_id: Optional[str] = None,
|
|
|
|
) -> SubmitResponsePb:
|
2021-04-15 16:14:54 +02:00
|
|
|
return await self.stubs['submitter'].submit(
|
2021-04-09 10:17:38 +02:00
|
|
|
SubmitRequestPb(
|
|
|
|
telegram_document=telegram_document,
|
|
|
|
telegram_file_id=telegram_file_id,
|
|
|
|
chat=chat,
|
|
|
|
),
|
|
|
|
metadata=(('request-id', request_id), ('session-id', session_id))
|
|
|
|
)
|