-
Notifications
You must be signed in to change notification settings - Fork 9k
/
Copy pathfeishu_api_utils.py
822 lines (760 loc) · 26.7 KB
/
feishu_api_utils.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
import json
from typing import Optional
import httpx
from core.tools.errors import ToolProviderCredentialValidationError
from extensions.ext_redis import redis_client
def auth(credentials):
app_id = credentials.get("app_id")
app_secret = credentials.get("app_secret")
if not app_id or not app_secret:
raise ToolProviderCredentialValidationError("app_id and app_secret is required")
try:
assert FeishuRequest(app_id, app_secret).tenant_access_token is not None
except Exception as e:
raise ToolProviderCredentialValidationError(str(e))
def convert_add_records(json_str):
try:
data = json.loads(json_str)
if not isinstance(data, list):
raise ValueError("Parsed data must be a list")
converted_data = [{"fields": json.dumps(item, ensure_ascii=False)} for item in data]
return converted_data
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
except Exception as e:
raise ValueError(f"An error occurred while processing the data: {e}")
def convert_update_records(json_str):
try:
data = json.loads(json_str)
if not isinstance(data, list):
raise ValueError("Parsed data must be a list")
converted_data = [
{"fields": json.dumps(record["fields"], ensure_ascii=False), "record_id": record["record_id"]}
for record in data
if "fields" in record and "record_id" in record
]
if len(converted_data) != len(data):
raise ValueError("Each record must contain 'fields' and 'record_id'")
return converted_data
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
except Exception as e:
raise ValueError(f"An error occurred while processing the data: {e}")
class FeishuRequest:
API_BASE_URL = "https://lark-plugin-api.solutionsuite.cn/lark-plugin"
def __init__(self, app_id: str, app_secret: str):
self.app_id = app_id
self.app_secret = app_secret
@property
def tenant_access_token(self):
feishu_tenant_access_token = f"tools:{self.app_id}:feishu_tenant_access_token"
if redis_client.exists(feishu_tenant_access_token):
return redis_client.get(feishu_tenant_access_token).decode()
res = self.get_tenant_access_token(self.app_id, self.app_secret)
redis_client.setex(feishu_tenant_access_token, res.get("expire"), res.get("tenant_access_token"))
return res.get("tenant_access_token")
def _send_request(
self,
url: str,
method: str = "post",
require_token: bool = True,
payload: Optional[dict] = None,
params: Optional[dict] = None,
):
headers = {
"Content-Type": "application/json",
"user-agent": "Dify",
}
if require_token:
headers["tenant-access-token"] = f"{self.tenant_access_token}"
res = httpx.request(method=method, url=url, headers=headers, json=payload, params=params, timeout=30).json()
if res.get("code") != 0:
raise Exception(res)
return res
def get_tenant_access_token(self, app_id: str, app_secret: str) -> dict:
"""
API url: https://open.feishu.cn/document/server-docs/authentication-management/access-token/tenant_access_token_internal
Example Response:
{
"code": 0,
"msg": "ok",
"tenant_access_token": "t-caecc734c2e3328a62489fe0648c4b98779515d3",
"expire": 7200
}
"""
url = f"{self.API_BASE_URL}/access_token/get_tenant_access_token"
payload = {"app_id": app_id, "app_secret": app_secret}
res = self._send_request(url, require_token=False, payload=payload)
return res
def create_document(self, title: str, content: str, folder_token: str) -> dict:
"""
API url: https://open.larkoffice.com/document/server-docs/docs/docs/docx-v1/document/create
Example Response:
{
"data": {
"title": "title",
"url": "https://svi136aogf123.feishu.cn/docx/VWbvd4fEdoW0WSxaY1McQTz8n7d",
"type": "docx",
"token": "VWbvd4fEdoW0WSxaY1McQTz8n7d"
},
"log_id": "021721281231575fdbddc0200ff00060a9258ec0000103df61b5d",
"code": 0,
"msg": "创建飞书文档成功,请查看"
}
"""
url = f"{self.API_BASE_URL}/document/create_document"
payload = {
"title": title,
"content": content,
"folder_token": folder_token,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def write_document(self, document_id: str, content: str, position: str = "end") -> dict:
url = f"{self.API_BASE_URL}/document/write_document"
payload = {"document_id": document_id, "content": content, "position": position}
res = self._send_request(url, payload=payload)
return res
def get_document_content(self, document_id: str, mode: str = "markdown", lang: str = "0") -> dict:
"""
API url: https://open.larkoffice.com/document/server-docs/docs/docs/docx-v1/document/raw_content
Example Response:
{
"code": 0,
"msg": "success",
"data": {
"content": "云文档\n多人实时协同,插入一切元素。不仅是在线文档,更是强大的创作和互动工具\n云文档:专为协作而生\n"
}
}
""" # noqa: E501
params = {
"document_id": document_id,
"mode": mode,
"lang": lang,
}
url = f"{self.API_BASE_URL}/document/get_document_content"
res = self._send_request(url, method="GET", params=params)
return res.get("data").get("content")
def list_document_blocks(
self, document_id: str, page_token: str, user_id_type: str = "open_id", page_size: int = 500
) -> dict:
"""
API url: https://open.larkoffice.com/document/server-docs/docs/docs/docx-v1/document/list
"""
params = {
"user_id_type": user_id_type,
"document_id": document_id,
"page_size": page_size,
"page_token": page_token,
}
url = f"{self.API_BASE_URL}/document/list_document_blocks"
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def send_bot_message(self, receive_id_type: str, receive_id: str, msg_type: str, content: str) -> dict:
"""
API url: https://open.larkoffice.com/document/server-docs/im-v1/message/create
"""
url = f"{self.API_BASE_URL}/message/send_bot_message"
params = {
"receive_id_type": receive_id_type,
}
payload = {
"receive_id": receive_id,
"msg_type": msg_type,
"content": content.strip('"').replace(r"\"", '"').replace(r"\\", "\\"),
}
res = self._send_request(url, params=params, payload=payload)
return res.get("data")
def send_webhook_message(self, webhook: str, msg_type: str, content: str) -> dict:
url = f"{self.API_BASE_URL}/message/send_webhook_message"
payload = {
"webhook": webhook,
"msg_type": msg_type,
"content": content.strip('"').replace(r"\"", '"').replace(r"\\", "\\"),
}
res = self._send_request(url, require_token=False, payload=payload)
return res
def get_chat_messages(
self,
container_id: str,
start_time: str,
end_time: str,
page_token: str,
sort_type: str = "ByCreateTimeAsc",
page_size: int = 20,
) -> dict:
"""
API url: https://open.larkoffice.com/document/server-docs/im-v1/message/list
"""
url = f"{self.API_BASE_URL}/message/get_chat_messages"
params = {
"container_id": container_id,
"start_time": start_time,
"end_time": end_time,
"sort_type": sort_type,
"page_token": page_token,
"page_size": page_size,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def get_thread_messages(
self, container_id: str, page_token: str, sort_type: str = "ByCreateTimeAsc", page_size: int = 20
) -> dict:
"""
API url: https://open.larkoffice.com/document/server-docs/im-v1/message/list
"""
url = f"{self.API_BASE_URL}/message/get_thread_messages"
params = {
"container_id": container_id,
"sort_type": sort_type,
"page_token": page_token,
"page_size": page_size,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def create_task(self, summary: str, start_time: str, end_time: str, completed_time: str, description: str) -> dict:
# 创建任务
url = f"{self.API_BASE_URL}/task/create_task"
payload = {
"summary": summary,
"start_time": start_time,
"end_time": end_time,
"completed_at": completed_time,
"description": description,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def update_task(
self, task_guid: str, summary: str, start_time: str, end_time: str, completed_time: str, description: str
) -> dict:
# 更新任务
url = f"{self.API_BASE_URL}/task/update_task"
payload = {
"task_guid": task_guid,
"summary": summary,
"start_time": start_time,
"end_time": end_time,
"completed_time": completed_time,
"description": description,
}
res = self._send_request(url, method="PATCH", payload=payload)
return res.get("data")
def delete_task(self, task_guid: str) -> dict:
# 删除任务
url = f"{self.API_BASE_URL}/task/delete_task"
payload = {
"task_guid": task_guid,
}
res = self._send_request(url, method="DELETE", payload=payload)
return res
def add_members(self, task_guid: str, member_phone_or_email: str, member_role: str) -> dict:
# 删除任务
url = f"{self.API_BASE_URL}/task/add_members"
payload = {
"task_guid": task_guid,
"member_phone_or_email": member_phone_or_email,
"member_role": member_role,
}
res = self._send_request(url, payload=payload)
return res
def get_wiki_nodes(self, space_id: str, parent_node_token: str, page_token: str, page_size: int = 20) -> dict:
# 获取知识库全部子节点列表
url = f"{self.API_BASE_URL}/wiki/get_wiki_nodes"
payload = {
"space_id": space_id,
"parent_node_token": parent_node_token,
"page_token": page_token,
"page_size": page_size,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def get_primary_calendar(self, user_id_type: str = "open_id") -> dict:
url = f"{self.API_BASE_URL}/calendar/get_primary_calendar"
params = {
"user_id_type": user_id_type,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def create_event(
self,
summary: str,
description: str,
start_time: str,
end_time: str,
attendee_ability: str,
need_notification: bool = True,
auto_record: bool = False,
) -> dict:
url = f"{self.API_BASE_URL}/calendar/create_event"
payload = {
"summary": summary,
"description": description,
"need_notification": need_notification,
"start_time": start_time,
"end_time": end_time,
"auto_record": auto_record,
"attendee_ability": attendee_ability,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def update_event(
self,
event_id: str,
summary: str,
description: str,
need_notification: bool,
start_time: str,
end_time: str,
auto_record: bool,
) -> dict:
url = f"{self.API_BASE_URL}/calendar/update_event/{event_id}"
payload = {}
if summary:
payload["summary"] = summary
if description:
payload["description"] = description
if start_time:
payload["start_time"] = start_time
if end_time:
payload["end_time"] = end_time
if need_notification:
payload["need_notification"] = need_notification
if auto_record:
payload["auto_record"] = auto_record
res = self._send_request(url, method="PATCH", payload=payload)
return res
def delete_event(self, event_id: str, need_notification: bool = True) -> dict:
url = f"{self.API_BASE_URL}/calendar/delete_event/{event_id}"
params = {
"need_notification": need_notification,
}
res = self._send_request(url, method="DELETE", params=params)
return res
def list_events(self, start_time: str, end_time: str, page_token: str, page_size: int = 50) -> dict:
url = f"{self.API_BASE_URL}/calendar/list_events"
params = {
"start_time": start_time,
"end_time": end_time,
"page_token": page_token,
"page_size": page_size,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def search_events(
self,
query: str,
start_time: str,
end_time: str,
page_token: str,
user_id_type: str = "open_id",
page_size: int = 20,
) -> dict:
url = f"{self.API_BASE_URL}/calendar/search_events"
payload = {
"query": query,
"start_time": start_time,
"end_time": end_time,
"page_token": page_token,
"user_id_type": user_id_type,
"page_size": page_size,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def add_event_attendees(self, event_id: str, attendee_phone_or_email: str, need_notification: bool = True) -> dict:
# 参加日程参会人
url = f"{self.API_BASE_URL}/calendar/add_event_attendees"
payload = {
"event_id": event_id,
"attendee_phone_or_email": attendee_phone_or_email,
"need_notification": need_notification,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def create_spreadsheet(
self,
title: str,
folder_token: str,
) -> dict:
# 创建电子表格
url = f"{self.API_BASE_URL}/spreadsheet/create_spreadsheet"
payload = {
"title": title,
"folder_token": folder_token,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def get_spreadsheet(
self,
spreadsheet_token: str,
user_id_type: str = "open_id",
) -> dict:
# 获取电子表格信息
url = f"{self.API_BASE_URL}/spreadsheet/get_spreadsheet"
params = {
"spreadsheet_token": spreadsheet_token,
"user_id_type": user_id_type,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def list_spreadsheet_sheets(
self,
spreadsheet_token: str,
) -> dict:
# 列出电子表格的所有工作表
url = f"{self.API_BASE_URL}/spreadsheet/list_spreadsheet_sheets"
params = {
"spreadsheet_token": spreadsheet_token,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def add_rows(
self,
spreadsheet_token: str,
sheet_id: str,
sheet_name: str,
length: int,
values: str,
) -> dict:
# 增加行,在工作表最后添加
url = f"{self.API_BASE_URL}/spreadsheet/add_rows"
payload = {
"spreadsheet_token": spreadsheet_token,
"sheet_id": sheet_id,
"sheet_name": sheet_name,
"length": length,
"values": values,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def add_cols(
self,
spreadsheet_token: str,
sheet_id: str,
sheet_name: str,
length: int,
values: str,
) -> dict:
# 增加列,在工作表最后添加
url = f"{self.API_BASE_URL}/spreadsheet/add_cols"
payload = {
"spreadsheet_token": spreadsheet_token,
"sheet_id": sheet_id,
"sheet_name": sheet_name,
"length": length,
"values": values,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def read_rows(
self,
spreadsheet_token: str,
sheet_id: str,
sheet_name: str,
start_row: int,
num_rows: int,
user_id_type: str = "open_id",
) -> dict:
# 读取工作表行数据
url = f"{self.API_BASE_URL}/spreadsheet/read_rows"
params = {
"spreadsheet_token": spreadsheet_token,
"sheet_id": sheet_id,
"sheet_name": sheet_name,
"start_row": start_row,
"num_rows": num_rows,
"user_id_type": user_id_type,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def read_cols(
self,
spreadsheet_token: str,
sheet_id: str,
sheet_name: str,
start_col: int,
num_cols: int,
user_id_type: str = "open_id",
) -> dict:
# 读取工作表列数据
url = f"{self.API_BASE_URL}/spreadsheet/read_cols"
params = {
"spreadsheet_token": spreadsheet_token,
"sheet_id": sheet_id,
"sheet_name": sheet_name,
"start_col": start_col,
"num_cols": num_cols,
"user_id_type": user_id_type,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def read_table(
self,
spreadsheet_token: str,
sheet_id: str,
sheet_name: str,
num_range: str,
query: str,
user_id_type: str = "open_id",
) -> dict:
# 自定义读取行列数据
url = f"{self.API_BASE_URL}/spreadsheet/read_table"
params = {
"spreadsheet_token": spreadsheet_token,
"sheet_id": sheet_id,
"sheet_name": sheet_name,
"range": num_range,
"query": query,
"user_id_type": user_id_type,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def create_base(
self,
name: str,
folder_token: str,
) -> dict:
# 创建多维表格
url = f"{self.API_BASE_URL}/base/create_base"
payload = {
"name": name,
"folder_token": folder_token,
}
res = self._send_request(url, payload=payload)
return res.get("data")
def add_records(
self,
app_token: str,
table_id: str,
table_name: str,
records: str,
user_id_type: str = "open_id",
) -> dict:
# 新增多条记录
url = f"{self.API_BASE_URL}/base/add_records"
params = {
"app_token": app_token,
"table_id": table_id,
"table_name": table_name,
"user_id_type": user_id_type,
}
payload = {
"records": convert_add_records(records),
}
res = self._send_request(url, params=params, payload=payload)
return res.get("data")
def update_records(
self,
app_token: str,
table_id: str,
table_name: str,
records: str,
user_id_type: str,
) -> dict:
# 更新多条记录
url = f"{self.API_BASE_URL}/base/update_records"
params = {
"app_token": app_token,
"table_id": table_id,
"table_name": table_name,
"user_id_type": user_id_type,
}
payload = {
"records": convert_update_records(records),
}
res = self._send_request(url, params=params, payload=payload)
return res.get("data")
def delete_records(
self,
app_token: str,
table_id: str,
table_name: str,
record_ids: str,
) -> dict:
# 删除多条记录
url = f"{self.API_BASE_URL}/base/delete_records"
params = {
"app_token": app_token,
"table_id": table_id,
"table_name": table_name,
}
if not record_ids:
record_id_list = []
else:
try:
record_id_list = json.loads(record_ids)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
payload = {
"records": record_id_list,
}
res = self._send_request(url, params=params, payload=payload)
return res.get("data")
def search_record(
self,
app_token: str,
table_id: str,
table_name: str,
view_id: str,
field_names: str,
sort: str,
filters: str,
page_token: str,
automatic_fields: bool = False,
user_id_type: str = "open_id",
page_size: int = 20,
) -> dict:
# 查询记录,单次最多查询 500 行记录。
url = f"{self.API_BASE_URL}/base/search_record"
params = {
"app_token": app_token,
"table_id": table_id,
"table_name": table_name,
"user_id_type": user_id_type,
"page_token": page_token,
"page_size": page_size,
}
if not field_names:
field_name_list = []
else:
try:
field_name_list = json.loads(field_names)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
if not sort:
sort_list = []
else:
try:
sort_list = json.loads(sort)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
if not filters:
filter_dict = {}
else:
try:
filter_dict = json.loads(filters)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
payload = {}
if view_id:
payload["view_id"] = view_id
if field_names:
payload["field_names"] = field_name_list
if sort:
payload["sort"] = sort_list
if filters:
payload["filter"] = filter_dict
if automatic_fields:
payload["automatic_fields"] = automatic_fields
res = self._send_request(url, params=params, payload=payload)
return res.get("data")
def get_base_info(
self,
app_token: str,
) -> dict:
# 获取多维表格元数据
url = f"{self.API_BASE_URL}/base/get_base_info"
params = {
"app_token": app_token,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def create_table(
self,
app_token: str,
table_name: str,
default_view_name: str,
fields: str,
) -> dict:
# 新增一个数据表
url = f"{self.API_BASE_URL}/base/create_table"
params = {
"app_token": app_token,
}
if not fields:
fields_list = []
else:
try:
fields_list = json.loads(fields)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
payload = {
"name": table_name,
"fields": fields_list,
}
if default_view_name:
payload["default_view_name"] = default_view_name
res = self._send_request(url, params=params, payload=payload)
return res.get("data")
def delete_tables(
self,
app_token: str,
table_ids: str,
table_names: str,
) -> dict:
# 删除多个数据表
url = f"{self.API_BASE_URL}/base/delete_tables"
params = {
"app_token": app_token,
}
if not table_ids:
table_id_list = []
else:
try:
table_id_list = json.loads(table_ids)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
if not table_names:
table_name_list = []
else:
try:
table_name_list = json.loads(table_names)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
payload = {
"table_ids": table_id_list,
"table_names": table_name_list,
}
res = self._send_request(url, params=params, payload=payload)
return res.get("data")
def list_tables(
self,
app_token: str,
page_token: str,
page_size: int = 20,
) -> dict:
# 列出多维表格下的全部数据表
url = f"{self.API_BASE_URL}/base/list_tables"
params = {
"app_token": app_token,
"page_token": page_token,
"page_size": page_size,
}
res = self._send_request(url, method="GET", params=params)
return res.get("data")
def read_records(
self,
app_token: str,
table_id: str,
table_name: str,
record_ids: str,
user_id_type: str = "open_id",
) -> dict:
url = f"{self.API_BASE_URL}/base/read_records"
params = {
"app_token": app_token,
"table_id": table_id,
"table_name": table_name,
}
if not record_ids:
record_id_list = []
else:
try:
record_id_list = json.loads(record_ids)
except json.JSONDecodeError:
raise ValueError("The input string is not valid JSON")
payload = {
"record_ids": record_id_list,
"user_id_type": user_id_type,
}
res = self._send_request(url, method="GET", params=params, payload=payload)
return res.get("data")