diff --git a/lark_oapi/api/message/__init__.py b/lark_oapi/api/message/__init__.py new file mode 100644 index 000000000..6736ee239 --- /dev/null +++ b/lark_oapi/api/message/__init__.py @@ -0,0 +1 @@ +from utils.feishu.message import v4 diff --git a/lark_oapi/api/message/service.py b/lark_oapi/api/message/service.py new file mode 100644 index 000000000..84dd8314f --- /dev/null +++ b/lark_oapi/api/message/service.py @@ -0,0 +1,9 @@ +# Code generated by Lark OpenAPI. + +from lark_oapi.core.model import Config +from utils.feishu.message.v4.version import V4 + + +class MessageService(object): + def __init__(self, config: Config) -> None: + self.v4: V4 = V4(config) diff --git a/lark_oapi/api/message/v4/__init__.py b/lark_oapi/api/message/v4/__init__.py new file mode 100644 index 000000000..e97cecf79 --- /dev/null +++ b/lark_oapi/api/message/v4/__init__.py @@ -0,0 +1 @@ +from utils.feishu.message.v4.model import * diff --git a/lark_oapi/api/message/v4/model/__init__.py b/lark_oapi/api/message/v4/model/__init__.py new file mode 100644 index 000000000..78c5b4847 --- /dev/null +++ b/lark_oapi/api/message/v4/model/__init__.py @@ -0,0 +1,4 @@ +from utils.feishu.message.v4.model.create_batch_send_request import * +from utils.feishu.message.v4.model.create_batch_send_request_body import * +from utils.feishu.message.v4.model.create_batch_send_response import * +from utils.feishu.message.v4.model.create_batch_send_response_body import * diff --git a/lark_oapi/api/message/v4/model/create_batch_send_request.py b/lark_oapi/api/message/v4/model/create_batch_send_request.py new file mode 100644 index 000000000..665c04df2 --- /dev/null +++ b/lark_oapi/api/message/v4/model/create_batch_send_request.py @@ -0,0 +1,44 @@ +# Code generated by Lark OpenAPI. + +from typing import Optional + +from lark_oapi.core.enum import AccessTokenType, HttpMethod +from lark_oapi.core.model import BaseRequest + +from utils.feishu.message.v4.model.create_batch_send_request_body import ( + CreateBatchSendRequestBody, +) + + +class CreateBatchSendRequest(BaseRequest): + def __init__(self) -> None: + super().__init__() + self.receive_id_type: Optional[str] = None + self.request_body: Optional[CreateBatchSendRequestBody] = None + + @staticmethod + def builder() -> "CreateBatchSendRequestBuilder": + return CreateBatchSendRequestBuilder() + + +class CreateBatchSendRequestBuilder(object): + + def __init__(self) -> None: + create_message_request = CreateBatchSendRequest() + create_message_request.http_method = HttpMethod.POST + create_message_request.uri = "/open-apis/message/v4/batch_send" + create_message_request.token_types = { + AccessTokenType.TENANT, + AccessTokenType.USER, + } + self._create_message_request: CreateBatchSendRequest = create_message_request + + def request_body( + self, request_body: CreateBatchSendRequestBody + ) -> "CreateBatchSendRequestBuilder": + self._create_message_request.request_body = request_body + self._create_message_request.body = request_body + return self + + def build(self) -> CreateBatchSendRequest: + return self._create_message_request diff --git a/lark_oapi/api/message/v4/model/create_batch_send_request_body.py b/lark_oapi/api/message/v4/model/create_batch_send_request_body.py new file mode 100644 index 000000000..a5fcb7788 --- /dev/null +++ b/lark_oapi/api/message/v4/model/create_batch_send_request_body.py @@ -0,0 +1,73 @@ +# Code generated by Lark OpenAPI. + +from typing import Iterable, Optional + +from lark_oapi.core.construct import init + + +class CreateBatchSendRequestBody(object): + _types = { + "msg_type": str, + "content": dict, + "card": dict, + "department_ids": Iterable[str], + "open_ids": Iterable[str], + "bot_id_list": Iterable[str], + "user_ids": Iterable[str], + "union_ids": Iterable[str], + } + + def __init__(self, d=None): + self.msg_type: Optional[str] = None + self.content: Optional[dict] = None + self.card: Optional[dict] = None + self.department_ids: Optional[Iterable[str]] = None + self.open_ids: Optional[Iterable[str]] = None + self.bot_id_list: Optional[Iterable[str]] = None + self.user_ids: Optional[Iterable[str]] = None + self.union_ids: Optional[Iterable[str]] = None + init(self, d, self._types) + + @staticmethod + def builder() -> "CreateBatchSendRequestBodyBuilder": + return CreateBatchSendRequestBodyBuilder() + + +class CreateBatchSendRequestBodyBuilder(object): + def __init__(self) -> None: + self._create_batch_send_request_body = CreateBatchSendRequestBody() + + def msg_type(self, msg_type: str) -> "CreateBatchSendRequestBodyBuilder": + self._create_batch_send_request_body.msg_type = msg_type + return self + + def content(self, content: dict) -> "CreateBatchSendRequestBodyBuilder": + self._create_batch_send_request_body.content = content + return self + + def card(self, card: dict) -> "CreateBatchSendRequestBodyBuilder": + self._create_batch_send_request_body.card = card + return self + + def department_ids( + self, department_ids: Iterable[str] + ) -> "CreateBatchSendRequestBodyBuilder": + self._create_batch_send_request_body.department_ids = department_ids + return self + + def open_ids(self, open_ids: Iterable[str]) -> "CreateBatchSendRequestBodyBuilder": + self._create_batch_send_request_body.open_ids = open_ids + return self + + def user_ids(self, user_ids: Iterable[str]) -> "CreateBatchSendRequestBodyBuilder": + self._create_batch_send_request_body.user_ids = user_ids + return self + + def union_ids( + self, union_ids: Iterable[str] + ) -> "CreateBatchSendRequestBodyBuilder": + self._create_batch_send_request_body.union_ids = union_ids + return self + + def build(self) -> "CreateBatchSendRequestBody": + return self._create_batch_send_request_body diff --git a/lark_oapi/api/message/v4/model/create_batch_send_response.py b/lark_oapi/api/message/v4/model/create_batch_send_response.py new file mode 100644 index 000000000..750e0618e --- /dev/null +++ b/lark_oapi/api/message/v4/model/create_batch_send_response.py @@ -0,0 +1,19 @@ +# Code generated by Lark OpenAPI. + +from typing import Optional + +from lark_oapi.core.construct import init +from lark_oapi.core.model import BaseResponse + +from utils.feishu.message.v4.model.create_batch_send_response_body import ( + CreateBatchSendResponseBody, +) + + +class CreateBatchSendResponse(BaseResponse): + _types = {"data": CreateBatchSendResponseBody} + + def __init__(self, d=None): + super().__init__(d) + self.data: Optional[CreateBatchSendResponseBody] = None + init(self, d, self._types) diff --git a/lark_oapi/api/message/v4/model/create_batch_send_response_body.py b/lark_oapi/api/message/v4/model/create_batch_send_response_body.py new file mode 100644 index 000000000..bf75ac664 --- /dev/null +++ b/lark_oapi/api/message/v4/model/create_batch_send_response_body.py @@ -0,0 +1,65 @@ +# Code generated by Lark OpenAPI. + +from typing import Iterable, Optional + +from lark_oapi.core.construct import init + + +class CreateBatchSendResponseBody(object): + _types = { + "message_id": str, + "invalid_department_ids": Iterable[str], + "invalid_open_ids": Iterable[str], + "invalid_user_ids": Iterable[str], + "invalid_union_ids": Iterable[str], + } + + def __init__(self, d=None): + self.message_id: Optional[str] = None + self.invalid_department_ids: Optional[Iterable[str]] = None + self.invalid_open_ids: Optional[Iterable[str]] = None + self.invalid_user_ids: Optional[Iterable[str]] = None + self.invalid_union_ids: Optional[Iterable[str]] = None + init(self, d, self._types) + + @staticmethod + def builder() -> "CreateBatchSendResponseBodyBuilder": + return CreateBatchSendResponseBodyBuilder() + + +class CreateBatchSendResponseBodyBuilder(object): + def __init__(self) -> None: + self._create_batch_send_response_body = CreateBatchSendResponseBody() + + def message_id(self, message_id: str) -> "CreateBatchSendResponseBodyBuilder": + self._create_batch_send_response_body.message_id = message_id + return self + + def invalid_department_ids( + self, invalid_department_ids: Iterable[str] + ) -> "CreateBatchSendResponseBodyBuilder": + self._create_batch_send_response_body.invalid_department_ids = ( + invalid_department_ids + ) + return self + + def invalid_open_ids( + self, invalid_open_ids: Iterable[str] + ) -> "CreateBatchSendResponseBodyBuilder": + self._create_batch_send_response_body.invalid_open_ids = invalid_open_ids + return self + + def invalid_user_ids( + self, invalid_user_ids: Iterable[str] + ) -> "CreateBatchSendResponseBodyBuilder": + self._create_batch_send_response_body.invalid_user_ids = invalid_user_ids + return self + + def invalid_union_ids( + self, invalid_union_ids: Iterable[str] + ) -> "CreateBatchSendResponseBodyBuilder": + self._create_batch_send_response_body.invalid_union_ids = invalid_union_ids + return self + + def build(self) -> "CreateBatchSendResponseBody": + return self._create_batch_send_response_body diff --git a/lark_oapi/api/message/v4/resource/__init__.py b/lark_oapi/api/message/v4/resource/__init__.py new file mode 100644 index 000000000..1310ffb65 --- /dev/null +++ b/lark_oapi/api/message/v4/resource/__init__.py @@ -0,0 +1 @@ +from utils.feishu.message.v4.resource.batch_send import * diff --git a/lark_oapi/api/message/v4/resource/batch_send.py b/lark_oapi/api/message/v4/resource/batch_send.py new file mode 100644 index 000000000..addb41a58 --- /dev/null +++ b/lark_oapi/api/message/v4/resource/batch_send.py @@ -0,0 +1,44 @@ +# Code generated by Lark OpenAPI. + +from typing import Optional + +from lark_oapi.core import JSON +from lark_oapi.core.const import APPLICATION_JSON, CONTENT_TYPE, UTF_8 +from lark_oapi.core.http import Transport +from lark_oapi.core.model import Config, RawResponse, RequestOption +from lark_oapi.core.token import verify +from utils.feishu.message.v4.model.create_batch_send_request import ( + CreateBatchSendRequest, +) +from utils.feishu.message.v4.model.create_batch_send_response import ( + CreateBatchSendResponse, +) + + +class BatchSend(object): + def __init__(self, config: Config) -> None: + self.config: Config = config + + def create( + self, request: CreateBatchSendRequest, option: Optional[RequestOption] = None + ) -> CreateBatchSendResponse: + if option is None: + option = RequestOption() + + # 鉴权、获取 token + verify(self.config, request, option) + + # 添加 content-type + if request.body is not None: + option.headers[CONTENT_TYPE] = f"{APPLICATION_JSON}; charset=utf-8" + + # 发起请求 + resp: RawResponse = Transport.execute(self.config, request, option) + + # 反序列化 + response: CreateBatchSendResponse = JSON.unmarshal( + str(resp.content, UTF_8), CreateBatchSendResponse + ) + response.raw = resp + + return response diff --git a/lark_oapi/api/message/v4/version.py b/lark_oapi/api/message/v4/version.py new file mode 100644 index 000000000..412d0764b --- /dev/null +++ b/lark_oapi/api/message/v4/version.py @@ -0,0 +1,6 @@ +from utils.feishu.message.v4.resource import * + + +class V4(object): + def __init__(self, config: Config) -> None: + self.batch_send: BatchSend = BatchSend(config) diff --git a/lark_oapi/client.py b/lark_oapi/client.py index 28765aa29..d41ab16e3 100644 --- a/lark_oapi/client.py +++ b/lark_oapi/client.py @@ -61,6 +61,7 @@ from .api.optical_char_recognition.service import OpticalCharRecognitionService from .api.attendance.service import AttendanceService from .api.event.service import EventService +from .api.message.service import MessageService class Client(object): @@ -119,12 +120,15 @@ def __init__(self) -> None: self.optical_char_recognition: Optional[OpticalCharRecognitionService] = None self.attendance: Optional[AttendanceService] = None self.event: Optional[EventService] = None + self.message: Optional[MessageService] = None @staticmethod def builder() -> "ClientBuilder": return ClientBuilder() - def request(self, request: BaseRequest, option: Optional[RequestOption] = None) -> BaseResponse: + def request( + self, request: BaseRequest, option: Optional[RequestOption] = None + ) -> BaseResponse: if option is None: option = RequestOption() @@ -145,7 +149,9 @@ def request(self, request: BaseRequest, option: Optional[RequestOption] = None) return resp - async def arequest(self, request: BaseRequest, option: Optional[RequestOption] = None) -> BaseResponse: + async def arequest( + self, request: BaseRequest, option: Optional[RequestOption] = None + ) -> BaseResponse: if option is None: option = RequestOption() @@ -274,7 +280,7 @@ def build(self) -> Client: client.optical_char_recognition = OpticalCharRecognitionService(self._config) client.attendance = AttendanceService(self._config) client.event = EventService(self._config) - + client.message = MessageService(self._config) return client def _init_cache(self):