open-lark 0.14.0

Enterprise-grade Lark/Feishu Open API SDK with comprehensive Chinese documentation and advanced error handling
Documentation
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
//! 群组(Group)服务
//!
//! 提供飞书群组的完整功能集,支持群组管理、群成员管理、群公告发布、
//! 会话标签页、群菜单配置等企业级群组协作能力。是团队沟通和协作的核心工具。
//!
//! # 核心功能
//!
//! ## 群组管理
//! - 👥 群组创建、编辑和删除
//! - 📋 群组信息查询和更新
//! - 🔍 群组搜索和筛选
//! - 📊 群组统计和分析
//! - ⚙️ 群组设置和配置
//!
//! ## 群成员管理
//! - 👤 群成员添加和移除
//! - 👑 群管理员权限设置
//! - 📋 群成员列表查询
//! - 🔐 成员权限管理
//! - 📊 成员活跃度统计
//!
//! ## 群公告管理
//! - 📢 群公告创建和发布
//! - 📝 公告内容编辑和更新
//! - 📅 公告定时发布
//! - 📊 公告阅读统计
//! - 🔔 公告提醒设置
//!
//! ## 会话标签页
//! - 🏷️ 群聊标签页管理
//! - 📱 自定义标签页配置
//! - 🔗 标签页跳转链接
//! - 📊 标签页使用统计
//! - 🎨 标签页外观定制
//!
//! ## 群菜单配置
//! - 🍔 群菜单创建和管理
//! - 🔗 菜单功能链接配置
//! - 🎨 菜单样式自定义
//! - 📊 菜单使用数据统计
//! - 🔧 菜单权限控制
//!
//! # 使用示例
//!
//! ```rust
//! use open_lark::prelude::*;
//!
//! let client = LarkClient::builder("app_id", "app_secret")
//!     .with_app_type(AppType::SelfBuild)
//!     .build();
//!
//! // 获取群组服务
//! let group = &client.group;
//!
//! // 创建群组
//! // let create_request = CreateGroupRequest::builder()
//! //     .name("项目讨论组")
//! //     .description("项目开发讨论群组")
//! //     .members(vec!["user1", "user2", "user3"])
//! //     .build();
//! // let new_group = group.v1.group.create(create_request, None).await?;
//!
//! // 添加群成员
//! // let add_member_request = AddGroupMemberRequest::builder()
//! //     .group_id("group_123")
//! //     .user_ids(vec!["user4", "user5"])
//! //     .build();
//! // group.v1.member.add(add_member_request, None).await?;
//!
//! // 发布群公告
//! // let announcement_request = CreateAnnouncementRequest::builder()
//! //     .group_id("group_123")
//! //     .title("重要通知")
//! //     .content("项目进度更新,请大家查看")
//! //     .build();
//! // group.v1.announcement.create(announcement_request, None).await?;
//!
//! // 配置群菜单
//! // let menu_request = SetGroupMenuRequest::builder()
//! //     .group_id("group_123")
//! //     .menu_items(vec![
//! //         MenuItem::new("项目文档", "https://docs.company.com"),
//! //         MenuItem::new("会议室预约", "https://meeting.company.com")
//! //     ])
//! //     .build();
//! // group.v1.menu.set(menu_request, None).await?;
//! ```
//!
//! # API版本
//!
//! 当前支持v1版本,提供完整的群组功能:
//! - 群组全生命周期管理
//! - 群成员权限控制
//! - 群公告发布系统
//! - 会话标签页定制
//! - 群菜单配置管理
//!
//! # 群组协作特性
//!
//! - 👥 多人实时协作
//! - 📱 跨平台同步支持
//! - 🔔 智能消息提醒
//! - 📊 群组数据分析
//! - 🔐 企业级安全控制
//!
//! # 团队管理
//!
//! - 🎯 高效的团队沟通
//! - 📋 项目协作管理
//! - 📊 团队活跃度监控
//! - 🏆 团队文化建设
//! - 📈 协作效率提升

use crate::core::config::Config;

/// 群组服务 v1 版本
pub mod v1;

/// 群组服务
///
/// 企业级群组协作的统一入口,提供群组管理、群成员管理、
/// 群公告发布、会话标签页、群菜单配置等完整的群组功能。
///
/// # 服务架构
///
/// - **v1**: 群组API v1版本,提供完整功能集
///
/// # 核心特性
///
/// - 👥 全面的群组管理功能
/// - 👑 灵活的权限控制系统
/// - 📢 专业的公告发布机制
/// - 🏷️ 个性化标签页配置
/// - 🍔 自定义群菜单系统
///
/// # 适用场景
///
/// - 团队项目协作
/// - 部门内部沟通
/// - 跨部门工作协调
/// - 企业公告发布
/// - 工作流程管理
///
/// # 最佳实践
///
/// - 合理设置群组权限
/// - 定期发布群公告
/// - 优化群菜单配置
/// - 监控群组活跃度
/// - 建立群组规范
pub struct GroupService {
    /// v1版本API服务
    pub v1: v1::V1,
}

impl GroupService {
    /// 创建新的群组服务实例
    ///
    /// # 参数
    /// - `config`: 客户端配置,包含认证信息和API设置
    ///
    /// # 返回值
    /// 配置完成的群组服务实例
    pub fn new(config: Config) -> Self {
        Self {
            v1: v1::V1::new(config),
        }
    }
}

#[cfg(test)]
#[allow(unused_variables, unused_unsafe)]
mod tests {
    use super::*;
    use crate::core::config::Config;

    fn create_test_config() -> Config {
        Config::default()
    }

    #[test]
    fn test_group_service_creation() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify service structure
    }

    #[test]
    fn test_group_service_with_custom_config() {
        let config = Config::builder()
            .app_id("group_app")
            .app_secret("group_secret")
            .req_timeout(std::time::Duration::from_millis(14000))
            .base_url("https://group.api.com")
            .build();

        let group_service = GroupService::new(config);

        // Verify service creation with custom config
    }

    #[test]
    fn test_group_service_configuration_scenarios() {
        let test_configs = vec![
            Config::builder()
                .app_id("group_basic")
                .app_secret("basic_secret")
                .build(),
            Config::builder()
                .app_id("group_timeout")
                .app_secret("timeout_secret")
                .req_timeout(std::time::Duration::from_millis(16000))
                .build(),
            Config::builder()
                .app_id("group_custom")
                .app_secret("custom_secret")
                .base_url("https://custom.group.com")
                .build(),
            Config::builder()
                .app_id("group_enterprise")
                .app_secret("enterprise_secret")
                .req_timeout(std::time::Duration::from_millis(30000))
                .base_url("https://enterprise.group.com")
                .enable_token_cache(false)
                .build(),
        ];

        for config in test_configs {
            let group_service = GroupService::new(config);

            // Each configuration should create a valid service
        }
    }

    #[test]
    fn test_group_service_multiple_instances() {
        let config1 = create_test_config();
        let config2 = Config::builder()
            .app_id("group2")
            .app_secret("secret2")
            .build();

        let group_service1 = GroupService::new(config1);
        let group_service2 = GroupService::new(config2);

        // Services should be independent instances
        let service1_ptr = std::ptr::addr_of!(group_service1) as *const _;
        let service2_ptr = std::ptr::addr_of!(group_service2) as *const _;

        assert_ne!(
            service1_ptr, service2_ptr,
            "Services should be independent instances"
        );

        // Each service should have valid v1 API
    }

    #[test]
    fn test_group_service_config_cloning_behavior() {
        let original_config = create_test_config();

        // Test that the service works with cloned configs
        let group_service1 = GroupService::new(original_config.clone());
        let group_service2 = GroupService::new(original_config);

        // Both should work independently

        // But should be different service instances
        let service1_ptr = std::ptr::addr_of!(group_service1) as *const _;
        let service2_ptr = std::ptr::addr_of!(group_service2) as *const _;
        assert_ne!(service1_ptr, service2_ptr);
    }

    #[test]
    fn test_group_service_v1_api_structure() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify that the v1 API is properly structured

        // Test that service maintains proper memory layout
    }

    #[test]
    fn test_group_service_v1_chat_service_access() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify that chat service is accessible and properly configured
        let chat_ptr = std::ptr::addr_of!(group_service.v1.chat) as *const u8;
        assert!(
            !chat_ptr.is_null(),
            "Chat service should be properly instantiated"
        );
    }

    #[test]
    fn test_group_service_v1_member_service_access() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify that chat member service is accessible and properly configured
        let member_ptr = std::ptr::addr_of!(group_service.v1.chat_member) as *const u8;
        assert!(
            !member_ptr.is_null(),
            "Chat member service should be properly instantiated"
        );
    }

    #[test]
    fn test_group_service_v1_announcement_service_access() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify that chat announcement service is accessible
        let announcement_ptr = std::ptr::addr_of!(group_service.v1.chat_announcement) as *const u8;
        assert!(
            !announcement_ptr.is_null(),
            "Chat announcement service should be properly instantiated"
        );
    }

    #[test]
    fn test_group_service_v1_tab_service_access() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify that chat tab service is accessible
        let tab_ptr = std::ptr::addr_of!(group_service.v1.chat_tab) as *const u8;
        assert!(
            !tab_ptr.is_null(),
            "Chat tab service should be properly instantiated"
        );
    }

    #[test]
    fn test_group_service_v1_menu_tree_service_access() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify that chat menu tree service is accessible
        let menu_ptr = std::ptr::addr_of!(group_service.v1.chat_menu_tree) as *const u8;
        assert!(
            !menu_ptr.is_null(),
            "Chat menu tree service should be properly instantiated"
        );
    }

    #[test]
    fn test_group_service_v1_services_independence() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Verify that all sub-services are independent instances
        let chat_ptr = std::ptr::addr_of!(group_service.v1.chat) as *const _;
        let member_ptr = std::ptr::addr_of!(group_service.v1.chat_member) as *const _;
        let announcement_ptr = std::ptr::addr_of!(group_service.v1.chat_announcement) as *const _;
        let tab_ptr = std::ptr::addr_of!(group_service.v1.chat_tab) as *const _;
        let menu_ptr = std::ptr::addr_of!(group_service.v1.chat_menu_tree) as *const _;

        assert_ne!(
            chat_ptr, member_ptr,
            "Chat and member services should be independent"
        );
        assert_ne!(
            chat_ptr, announcement_ptr,
            "Chat and announcement services should be independent"
        );
        assert_ne!(
            chat_ptr, tab_ptr,
            "Chat and tab services should be independent"
        );
        assert_ne!(
            chat_ptr, menu_ptr,
            "Chat and menu services should be independent"
        );
        assert_ne!(
            member_ptr, announcement_ptr,
            "Member and announcement services should be independent"
        );
        assert_ne!(
            member_ptr, tab_ptr,
            "Member and tab services should be independent"
        );
        assert_ne!(
            member_ptr, menu_ptr,
            "Member and menu services should be independent"
        );
        assert_ne!(
            announcement_ptr, tab_ptr,
            "Announcement and tab services should be independent"
        );
        assert_ne!(
            announcement_ptr, menu_ptr,
            "Announcement and menu services should be independent"
        );
        assert_ne!(
            tab_ptr, menu_ptr,
            "Tab and menu services should be independent"
        );
    }

    #[test]
    fn test_group_service_with_different_timeouts() {
        let fast_config = Config::builder()
            .app_id("fast_group")
            .app_secret("fast_secret")
            .req_timeout(std::time::Duration::from_millis(5000))
            .build();

        let slow_config = Config::builder()
            .app_id("slow_group")
            .app_secret("slow_secret")
            .req_timeout(std::time::Duration::from_millis(60000))
            .build();

        let fast_service = GroupService::new(fast_config);
        let slow_service = GroupService::new(slow_config);

        // Both services should be created successfully regardless of timeout settings
        let fast_ptr = std::ptr::addr_of!(fast_service) as *const _;
        let slow_ptr = std::ptr::addr_of!(slow_service) as *const _;
        assert_ne!(
            fast_ptr, slow_ptr,
            "Services with different configs should be independent"
        );
    }

    #[test]
    fn test_group_service_with_different_base_urls() {
        let dev_config = Config::builder()
            .app_id("dev_group")
            .app_secret("dev_secret")
            .base_url("https://dev.group.api")
            .build();

        let prod_config = Config::builder()
            .app_id("prod_group")
            .app_secret("prod_secret")
            .base_url("https://api.group.lark.com")
            .build();

        let dev_service = GroupService::new(dev_config);
        let prod_service = GroupService::new(prod_config);

        // Both services should be created successfully with different base URLs
        let dev_ptr = std::ptr::addr_of!(dev_service) as *const _;
        let prod_ptr = std::ptr::addr_of!(prod_service) as *const _;
        assert_ne!(
            dev_ptr, prod_ptr,
            "Services with different base URLs should be independent"
        );
    }

    #[test]
    fn test_group_service_v1_struct_memory_layout() {
        let config = create_test_config();
        let group_service = GroupService::new(config);

        // Test that the V1 struct is properly aligned and accessible
        let v1_ptr = std::ptr::addr_of!(group_service.v1) as *const u8;
        assert!(
            !v1_ptr.is_null(),
            "V1 service should be properly instantiated"
        );

        // Verify all services are properly embedded within V1
        let chat_offset =
            unsafe { std::ptr::addr_of!(group_service.v1.chat) as usize - v1_ptr as usize };
        let member_offset =
            unsafe { std::ptr::addr_of!(group_service.v1.chat_member) as usize - v1_ptr as usize };
        let announcement_offset = unsafe {
            std::ptr::addr_of!(group_service.v1.chat_announcement) as usize - v1_ptr as usize
        };
        let tab_offset =
            unsafe { std::ptr::addr_of!(group_service.v1.chat_tab) as usize - v1_ptr as usize };
        let menu_offset = unsafe {
            std::ptr::addr_of!(group_service.v1.chat_menu_tree) as usize - v1_ptr as usize
        };

        // All offsets should be different, indicating proper struct layout
        let offsets = vec![
            chat_offset,
            member_offset,
            announcement_offset,
            tab_offset,
            menu_offset,
        ];
        let mut unique_offsets = offsets.clone();
        unique_offsets.sort();
        unique_offsets.dedup();

        assert_eq!(
            offsets.len(),
            unique_offsets.len(),
            "All services should have unique memory positions within V1"
        );
    }

    #[test]
    fn test_group_service_config_propagation() {
        let config = Config::builder()
            .app_id("config_test")
            .app_secret("config_secret")
            .base_url("https://config.test.com")
            .req_timeout(std::time::Duration::from_millis(45000))
            .enable_token_cache(false)
            .build();

        let group_service = GroupService::new(config);

        // All sub-services should be properly instantiated with the config
        // We can't directly access their configs, but we can verify they exist
        assert!(!(std::ptr::addr_of!(group_service.v1.chat) as *const u8).is_null());
        assert!(!(std::ptr::addr_of!(group_service.v1.chat_member) as *const u8).is_null());
        assert!(!(std::ptr::addr_of!(group_service.v1.chat_announcement) as *const u8).is_null());
        assert!(!(std::ptr::addr_of!(group_service.v1.chat_tab) as *const u8).is_null());
        assert!(!(std::ptr::addr_of!(group_service.v1.chat_menu_tree) as *const u8).is_null());
    }
}