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
//! 服务台(Helpdesk)服务
//!
//! 提供飞书服务台的完整功能集,支持工单管理、客户服务、知识库、
//! 自动化流程等企业级客户服务能力。是企业客户支持和服务的核心平台。
//!
//! # 核心功能
//!
//! ## 工单管理
//! - 📋 工单创建、分配和跟踪
//! - ⏰ 工单优先级和SLA管理
//! - 📊 工单状态和流程控制
//! - 🔄 工单转移和升级
//! - 📈 工单统计和报表
//!
//! ## 客户服务
//! - 👥 客户信息管理和查询
//! - 💬 多渠道客户沟通
//! - 📞 客服座席分配和管理
//! - 🎯 客户满意度调查
//! - 📊 服务质量监控
//!
//! ## 知识库管理
//! - 📚 知识文章创建和管理
//! - 🔍 智能知识搜索
//! - 📖 知识分类和标签
//! - 👥 知识共享和协作
//! - 📈 知识使用统计
//!
//! ## 自动化流程
//! - 🤖 工单自动分配规则
//! - 📧 自动回复和通知
//! - 🔄 流程自动化和触发器
//! - 📊 自动生成统计报表
//! - 🎯 智能推荐和建议
//!
//! # 使用示例
//!
//! ```rust
//! use open_lark::prelude::*;
//!
//! let client = LarkClient::builder("app_id", "app_secret")
//!     .with_app_type(AppType::SelfBuild)
//!     .build();
//!
//! // 获取服务台服务
//! let helpdesk = &client.helpdesk;
//!
//! // 创建工单
//! // let ticket_request = CreateTicketRequest::builder()
//! //     .title("登录问题咨询")
//! //     .description("用户反馈无法正常登录系统")
//! //     .priority("high")
//! //     .customer_id("customer_123")
//! //     .build();
//! // let ticket = helpdesk.v1.ticket.create(ticket_request, None).await?;
//!
//! // 查询工单列表
//! // let list_request = ListTicketsRequest::builder()
//! //     .status("open")
//! //     .page_size(20)
//! //     .build();
//! // let tickets = helpdesk.v1.ticket.list(list_request, None).await?;
//!
//! // 更新工单状态
//! // let update_request = UpdateTicketRequest::builder()
//! //     .ticket_id("ticket_123")
//! //     .status("resolved")
//! //     .resolution("问题已解决,用户可以正常登录")
//! //     .build();
//! // helpdesk.v1.ticket.update(update_request, None).await?;
//!
//! // 添加工单评论
//! // let comment_request = CreateTicketCommentRequest::builder()
//! //     .ticket_id("ticket_123")
//! //     .content("已联系技术团队,正在处理中")
//! //     .build();
//! // helpdesk.v1.ticket.add_comment(comment_request, None).await?;
//! ```
//!
//! # API版本
//!
//! 当前支持v1版本,提供基础的服务台功能:
//! - 工单全生命周期管理
//! - 客户服务和支持
//! - 知识库管理
//! - 基础的自动化功能
//!
//! # 服务台特性
//!
//! - 📱 多渠道客户接入
//! - 🤖 智能客服和机器人
//! - 📊 实时监控和报表
//! - 🔔 及时通知和提醒
//! - 🎯 个性化服务体验
//!
//! # 服务管理
//!
//! - 📈 服务质量监控和分析
//! - 👥 客服团队管理和培训
//! - 🎯 SLA目标设定和监控
//! - 📊 客户满意度评估
//! - 🔄 持续改进和优化

/// 数据模型定义
pub mod models;
/// 服务台服务 v1 版本
pub mod v1;

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

/// 服务台服务
///
/// 企业级客户服务的统一入口,提供工单管理、客户服务、
/// 知识库、自动化流程等完整的客户支持能力。
///
/// # 服务架构
///
/// - **v1**: 服务台API v1版本,提供基础功能集
/// - **models**: 数据模型和结构定义
///
/// # 核心特性
///
/// - 📋 完整的工单管理系统
/// - 👥 专业的客户服务支持
/// - 📚 智能的知识库管理
/// - 🤖 灵活的自动化流程
/// - 📊 全面的数据分析
///
/// # 适用场景
///
/// - 企业客户服务支持
/// - 内部IT服务台
/// - 技术支持和咨询
/// - 客户投诉处理
/// - 知识管理和共享
///
/// # 最佳实践
///
/// - 建立清晰的服务流程
/// - 设定合理的SLA目标
/// - 维护丰富的知识库
/// - 持续优化服务质量
/// - 重视客户反馈和满意度
pub struct HelpdeskService {
    /// v1版本API服务
    pub v1: v1::V1,
}

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

#[cfg(test)]
mod tests {
    use super::*;
    use std::time::Duration;

    #[test]
    fn test_helpdesk_service_creation() {
        let config = Config::default();
        let service = HelpdeskService::new(config.clone());

        // Verify all 11 sub-services are configured correctly
        assert_eq!(service.v1.agent.config.app_id, config.app_id);
        assert_eq!(service.v1.agent.config.app_secret, config.app_secret);
        assert_eq!(service.v1.agent_schedule.config.app_id, config.app_id);
        assert_eq!(service.v1.agent_skill.config.app_id, config.app_id);
        assert_eq!(service.v1.agent_skill_rule.config.app_id, config.app_id);
        assert_eq!(service.v1.category.config.app_id, config.app_id);
        assert_eq!(service.v1.event.config.app_id, config.app_id);
        assert_eq!(service.v1.faq.config.app_id, config.app_id);
        assert_eq!(service.v1.notification.config.app_id, config.app_id);
        assert_eq!(service.v1.ticket.config.app_id, config.app_id);
        assert_eq!(
            service.v1.ticket_customized_field.config.app_id,
            config.app_id
        );
        assert_eq!(service.v1.ticket_message.config.app_id, config.app_id);
    }

    #[test]
    fn test_helpdesk_service_with_custom_config() {
        let config = Config::builder()
            .app_id("helpdesk_test_app")
            .app_secret("helpdesk_test_secret")
            .req_timeout(Duration::from_secs(470))
            .build();

        let service = HelpdeskService::new(config.clone());

        assert_eq!(service.v1.agent.config.app_id, "helpdesk_test_app");
        assert_eq!(service.v1.agent.config.app_secret, "helpdesk_test_secret");
        assert_eq!(
            service.v1.agent.config.req_timeout,
            Some(Duration::from_secs(470))
        );
        assert_eq!(service.v1.agent_schedule.config.app_id, "helpdesk_test_app");
        assert_eq!(
            service.v1.agent_skill.config.req_timeout,
            Some(Duration::from_secs(470))
        );
        assert_eq!(
            service.v1.agent_skill_rule.config.app_id,
            "helpdesk_test_app"
        );
        assert_eq!(
            service.v1.category.config.req_timeout,
            Some(Duration::from_secs(470))
        );
        assert_eq!(service.v1.event.config.app_id, "helpdesk_test_app");
        assert_eq!(
            service.v1.faq.config.req_timeout,
            Some(Duration::from_secs(470))
        );
        assert_eq!(service.v1.notification.config.app_id, "helpdesk_test_app");
        assert_eq!(
            service.v1.ticket.config.req_timeout,
            Some(Duration::from_secs(470))
        );
        assert_eq!(
            service.v1.ticket_customized_field.config.app_id,
            "helpdesk_test_app"
        );
        assert_eq!(
            service.v1.ticket_message.config.req_timeout,
            Some(Duration::from_secs(470))
        );
    }

    #[test]
    fn test_helpdesk_service_config_independence() {
        let config1 = Config::builder().app_id("helpdesk_app_1").build();

        let config2 = Config::builder().app_id("helpdesk_app_2").build();

        let service1 = HelpdeskService::new(config1);
        let service2 = HelpdeskService::new(config2);

        assert_eq!(service1.v1.agent.config.app_id, "helpdesk_app_1");
        assert_eq!(service2.v1.agent.config.app_id, "helpdesk_app_2");
        assert_ne!(
            service1.v1.agent.config.app_id,
            service2.v1.agent.config.app_id
        );
        assert_ne!(
            service1.v1.agent_schedule.config.app_id,
            service2.v1.agent_schedule.config.app_id
        );
        assert_ne!(
            service1.v1.agent_skill.config.app_id,
            service2.v1.agent_skill.config.app_id
        );
        assert_ne!(
            service1.v1.agent_skill_rule.config.app_id,
            service2.v1.agent_skill_rule.config.app_id
        );
        assert_ne!(
            service1.v1.category.config.app_id,
            service2.v1.category.config.app_id
        );
        assert_ne!(
            service1.v1.event.config.app_id,
            service2.v1.event.config.app_id
        );
        assert_ne!(service1.v1.faq.config.app_id, service2.v1.faq.config.app_id);
        assert_ne!(
            service1.v1.notification.config.app_id,
            service2.v1.notification.config.app_id
        );
        assert_ne!(
            service1.v1.ticket.config.app_id,
            service2.v1.ticket.config.app_id
        );
        assert_ne!(
            service1.v1.ticket_customized_field.config.app_id,
            service2.v1.ticket_customized_field.config.app_id
        );
        assert_ne!(
            service1.v1.ticket_message.config.app_id,
            service2.v1.ticket_message.config.app_id
        );
    }

    #[test]
    fn test_helpdesk_service_sub_services_accessible() {
        let config = Config::default();
        let service = HelpdeskService::new(config.clone());

        // Test that all 11 sub-services are accessible
        assert_eq!(service.v1.agent.config.app_id, config.app_id);
        assert_eq!(service.v1.agent_schedule.config.app_id, config.app_id);
        assert_eq!(service.v1.agent_skill.config.app_id, config.app_id);
        assert_eq!(service.v1.agent_skill_rule.config.app_id, config.app_id);
        assert_eq!(service.v1.category.config.app_id, config.app_id);
        assert_eq!(service.v1.event.config.app_id, config.app_id);
        assert_eq!(service.v1.faq.config.app_id, config.app_id);
        assert_eq!(service.v1.notification.config.app_id, config.app_id);
        assert_eq!(service.v1.ticket.config.app_id, config.app_id);
        assert_eq!(
            service.v1.ticket_customized_field.config.app_id,
            config.app_id
        );
        assert_eq!(service.v1.ticket_message.config.app_id, config.app_id);
    }

    #[test]
    fn test_helpdesk_service_config_cloning() {
        let config = Config::builder()
            .app_id("clone_test_app")
            .app_secret("clone_test_secret")
            .build();

        let service = HelpdeskService::new(config.clone());

        assert_eq!(service.v1.agent.config.app_id, "clone_test_app");
        assert_eq!(service.v1.agent.config.app_secret, "clone_test_secret");
        assert_eq!(
            service.v1.agent_schedule.config.app_secret,
            "clone_test_secret"
        );
        assert_eq!(service.v1.agent_skill.config.app_id, "clone_test_app");
        assert_eq!(
            service.v1.agent_skill_rule.config.app_secret,
            "clone_test_secret"
        );
        assert_eq!(service.v1.category.config.app_id, "clone_test_app");
        assert_eq!(service.v1.event.config.app_secret, "clone_test_secret");
        assert_eq!(service.v1.faq.config.app_id, "clone_test_app");
        assert_eq!(
            service.v1.notification.config.app_secret,
            "clone_test_secret"
        );
        assert_eq!(service.v1.ticket.config.app_id, "clone_test_app");
        assert_eq!(
            service.v1.ticket_customized_field.config.app_secret,
            "clone_test_secret"
        );
        assert_eq!(service.v1.ticket_message.config.app_id, "clone_test_app");
    }

    #[test]
    fn test_helpdesk_service_timeout_propagation() {
        let config = Config::builder()
            .req_timeout(Duration::from_secs(480))
            .build();

        let service = HelpdeskService::new(config);

        // Verify timeout is propagated to all 11 sub-services
        assert_eq!(
            service.v1.agent.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.agent_schedule.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.agent_skill.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.agent_skill_rule.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.category.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.event.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.faq.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.notification.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.ticket.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.ticket_customized_field.config.req_timeout,
            Some(Duration::from_secs(480))
        );
        assert_eq!(
            service.v1.ticket_message.config.req_timeout,
            Some(Duration::from_secs(480))
        );
    }

    #[test]
    fn test_helpdesk_service_multiple_instances() {
        let config = Config::default();

        let service1 = HelpdeskService::new(config.clone());
        let service2 = HelpdeskService::new(config.clone());

        // Both services should have the same config values
        assert_eq!(
            service1.v1.agent.config.app_id,
            service2.v1.agent.config.app_id
        );
        assert_eq!(
            service1.v1.agent.config.app_secret,
            service2.v1.agent.config.app_secret
        );
        assert_eq!(
            service1.v1.agent_schedule.config.app_id,
            service2.v1.agent_schedule.config.app_id
        );
        assert_eq!(
            service1.v1.agent_skill.config.app_secret,
            service2.v1.agent_skill.config.app_secret
        );
        assert_eq!(
            service1.v1.agent_skill_rule.config.app_id,
            service2.v1.agent_skill_rule.config.app_id
        );
        assert_eq!(
            service1.v1.category.config.app_secret,
            service2.v1.category.config.app_secret
        );
        assert_eq!(
            service1.v1.event.config.app_id,
            service2.v1.event.config.app_id
        );
        assert_eq!(
            service1.v1.faq.config.app_secret,
            service2.v1.faq.config.app_secret
        );
        assert_eq!(
            service1.v1.notification.config.app_id,
            service2.v1.notification.config.app_id
        );
        assert_eq!(
            service1.v1.ticket.config.app_secret,
            service2.v1.ticket.config.app_secret
        );
        assert_eq!(
            service1.v1.ticket_customized_field.config.app_id,
            service2.v1.ticket_customized_field.config.app_id
        );
        assert_eq!(
            service1.v1.ticket_message.config.app_secret,
            service2.v1.ticket_message.config.app_secret
        );
    }

    #[test]
    fn test_helpdesk_service_config_consistency() {
        let config = Config::builder()
            .app_id("consistency_test")
            .app_secret("consistency_secret")
            .req_timeout(Duration::from_secs(490))
            .build();

        let service = HelpdeskService::new(config);

        // Verify all 11 sub-services have consistent configurations
        let configs = [
            &service.v1.agent.config,
            &service.v1.agent_schedule.config,
            &service.v1.agent_skill.config,
            &service.v1.agent_skill_rule.config,
            &service.v1.category.config,
            &service.v1.event.config,
            &service.v1.faq.config,
            &service.v1.notification.config,
            &service.v1.ticket.config,
            &service.v1.ticket_customized_field.config,
            &service.v1.ticket_message.config,
        ];

        for config in &configs {
            assert_eq!(config.app_id, "consistency_test");
            assert_eq!(config.app_secret, "consistency_secret");
            assert_eq!(config.req_timeout, Some(Duration::from_secs(490)));
        }
    }
}