3030
3131
3232class SolapiMessageService :
33+ """Solapi Message Service for handling message-related operations.
34+
35+ This class provides methods to interact with the Solapi API for sending various types of messages
36+ (SMS, LMS, MMS, 알림톡, 친구톡, RCS, etc.), managing message groups, uploading files,
37+ and checking account balance.
38+ """
39+
3340 def __init__ (self , api_key : str , api_secret : str ):
41+ """Initialize the Solapi Message Service.
42+
43+ Args:
44+ api_key: The API key for authentication.
45+ api_secret: The API secret for authentication.
46+ """
3447 self .base_url = "https://api.solapi.com"
3548 self .auth_info : AuthenticationParameter = {
3649 "api_key" : api_key ,
@@ -42,6 +55,28 @@ def send(
4255 messages : Union [list [Message ], Message ],
4356 request_config : Optional [SendRequestConfig ] = None ,
4457 ) -> SendMessageResponse :
58+ """Send one or more messages using the Solapi API.
59+
60+ This method sends various types of messages (SMS, LMS, MMS, 알림톡, 친구톡, RCS, etc.) to recipients.
61+ It supports sending a single message or multiple messages in one request (대량 발송).
62+
63+ Args:
64+ messages: A single Message object or a list of Message objects to send.
65+ Each Message object contains recipient (수신번호), sender (발신번호), content (내용),
66+ and other message details.
67+ request_config: Optional configuration for the send request.
68+ Can include app_id, allow_duplicates (중복 수신번호 허용),
69+ scheduled_date (예약 발송), and other settings.
70+
71+ Returns:
72+ SendMessageResponse: The response from the API containing message status, group info,
73+ and other details about the sent messages.
74+
75+ Raises:
76+ TypeError: If messages parameter is not a Message object or list of Message objects.
77+ ValueError: If no valid messages are provided.
78+ MessageNotReceivedError: If all messages failed to be registered.
79+ """
4580 payload = []
4681 if isinstance (messages , Message ):
4782 payload .append (messages )
@@ -99,6 +134,22 @@ def send(
99134 def upload_file (
100135 self , file_path : str , upload_type : FileTypeEnum = FileTypeEnum .MMS
101136 ) -> FileUploadResponse :
137+ """Upload a file to the Solapi storage service.
138+
139+ This method uploads a file (such as an image) to be used in MMS (사진 문자) or other message types.
140+ The file is encoded in base64 before being sent to the API.
141+
142+ Args:
143+ file_path: The path to the file to be uploaded (파일 경로).
144+ upload_type: The type of file being uploaded, defaults to MMS (사진 문자용).
145+ Other possible values are defined in FileTypeEnum.
146+
147+ Returns:
148+ FileUploadResponse: The response from the API containing the file ID (파일 ID) and other details.
149+
150+ Raises:
151+ FileNotFoundError: If the specified file path does not exist.
152+ """
102153 path = Path (file_path )
103154 with open (path , "rb" ) as image_file :
104155 encoded_string = base64 .b64encode (image_file .read ())
@@ -118,6 +169,20 @@ def upload_file(
118169 return FileUploadResponse .model_validate (response )
119170
120171 def get_groups (self , query : Optional [GetGroupsRequest ] = None ) -> GetGroupsResponse :
172+ """Retrieve message groups (메시지 그룹) from the Solapi API.
173+
174+ This method fetches message groups based on the provided query parameters.
175+ If no query is provided, it returns all message groups.
176+ 메시지 그룹은 대량 발송 시 생성되는 메시지들의 묶음입니다.
177+
178+ Args:
179+ query: Optional query parameters to filter the groups.
180+ Can include group_id (그룹 ID), criteria, cond, value, and other filters.
181+
182+ Returns:
183+ GetGroupsResponse: The response from the API containing the list of message groups
184+ and other metadata.
185+ """
121186 request = GetGroupsFinalizeRequest ()
122187 if query is not None :
123188 request = request .model_copy (update = query .model_dump (exclude_unset = True ))
@@ -140,6 +205,17 @@ def get_groups(self, query: Optional[GetGroupsRequest] = None) -> GetGroupsRespo
140205 return GetGroupsResponse .model_validate (response )
141206
142207 def get_group (self , group_id : str ) -> GroupMessageResponse :
208+ """Retrieve a specific message group (메시지 그룹) by its ID.
209+
210+ This method fetches detailed information about a single message group.
211+ 특정 그룹 ID로 메시지 그룹 정보를 조회합니다.
212+
213+ Args:
214+ group_id: The unique identifier (그룹 ID) of the message group to retrieve.
215+
216+ Returns:
217+ GroupMessageResponse: The response from the API containing the message group details.
218+ """
143219 response = default_fetcher (
144220 self .auth_info ,
145221 request = {
@@ -150,6 +226,18 @@ def get_group(self, group_id: str) -> GroupMessageResponse:
150226 return GroupMessageResponse .model_validate (response )
151227
152228 def get_group_messages (self , group_id : str ) -> GetGroupMessagesResponse :
229+ """Retrieve all messages within a specific group (그룹 내 메시지 목록 조회).
230+
231+ This method fetches all messages that belong to the specified message group.
232+ 특정 메시지 그룹에 속한 모든 메시지를 조회합니다.
233+
234+ Args:
235+ group_id: The unique identifier (그룹 ID) of the message group whose messages should be retrieved.
236+
237+ Returns:
238+ GetGroupMessagesResponse: The response from the API containing the list of messages
239+ in the group and other metadata.
240+ """
153241 response = default_fetcher (
154242 self .auth_info ,
155243 request = {
@@ -162,6 +250,21 @@ def get_group_messages(self, group_id: str) -> GetGroupMessagesResponse:
162250 def get_messages (
163251 self , query : Optional [GetMessagesRequest ] = None
164252 ) -> GetMessagesResponse :
253+ """Retrieve messages based on query parameters (메시지 목록 조회).
254+
255+ This method fetches messages that match the specified query parameters.
256+ If no query is provided, it returns messages based on default parameters.
257+ 조건에 맞는 메시지 목록을 조회합니다.
258+
259+ Args:
260+ query: Optional query parameters to filter the messages.
261+ Can include criteria for message status (상태), date range (기간),
262+ recipient (수신번호), sender (발신번호), etc.
263+
264+ Returns:
265+ GetMessagesResponse: The response from the API containing the list of messages
266+ and other metadata.
267+ """
165268 request = GetMessagesRequest ()
166269 if query is not None :
167270 request = request .model_copy (update = query .model_dump (exclude_unset = True ))
@@ -182,6 +285,15 @@ def get_messages(
182285 return GetMessagesResponse .model_validate (response )
183286
184287 def get_balance (self ) -> GetBalanceResponse :
288+ """Retrieve the account balance information (잔액 조회).
289+
290+ This method fetches the current balance and point information for the account.
291+ 계정의 현재 잔액과 포인트 정보를 조회합니다.
292+
293+ Returns:
294+ GetBalanceResponse: The response from the API containing the account balance details
295+ including cash balance (잔액) and point balance (포인트).
296+ """
185297 response = default_fetcher (
186298 self .auth_info ,
187299 request = {
0 commit comments