1111// APP_SECRET=your_app_secret
1212
1313use open_lark:: prelude:: * ;
14- use std:: collections:: HashMap ;
1514
1615#[ tokio:: main]
1716async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -22,7 +21,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2221 let app_secret = std:: env:: var ( "APP_SECRET" ) . expect ( "请设置 APP_SECRET 环境变量" ) ;
2322
2423 // 创建Lark客户端
25- let client = LarkClient :: builder ( & app_id, & app_secret)
24+ let _client = LarkClient :: builder ( & app_id, & app_secret)
2625 . with_app_type ( AppType :: SelfBuild )
2726 . with_enable_token_cache ( true )
2827 . build ( ) ;
@@ -293,195 +292,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
293292 Ok ( ( ) )
294293}
295294
296- // 辅助函数:创建卡片消息构建器
297- struct CardMessageBuilder {
298- config : Option < Config > ,
299- header : Option < Header > ,
300- elements : Vec < serde_json:: Value > ,
301- }
302-
303- impl CardMessageBuilder {
304- fn new ( ) -> Self {
305- Self {
306- config : None ,
307- header : None ,
308- elements : Vec :: new ( ) ,
309- }
310- }
311-
312- fn config ( mut self , config : Config ) -> Self {
313- self . config = Some ( config) ;
314- self
315- }
316-
317- fn header ( mut self , header : Header ) -> Self {
318- self . header = Some ( header) ;
319- self
320- }
321-
322- fn element ( mut self , element : impl serde:: Serialize ) -> Self {
323- if let Ok ( json) = serde_json:: to_value ( element) {
324- self . elements . push ( json) ;
325- }
326- self
327- }
328-
329- fn build ( self ) -> serde_json:: Value {
330- let mut card = serde_json:: json!( { } ) ;
331-
332- if let Some ( config) = self . config {
333- card[ "config" ] = serde_json:: to_value ( config) . unwrap ( ) ;
334- }
335-
336- if let Some ( header) = self . header {
337- card[ "header" ] = serde_json:: to_value ( header) . unwrap ( ) ;
338- }
339-
340- if !self . elements . is_empty ( ) {
341- card[ "elements" ] = serde_json:: Value :: Array ( self . elements ) ;
342- }
343-
344- serde_json:: json!( { "card" : card } )
345- }
346- }
347-
348- #[ derive( serde:: Serialize ) ]
349- struct Config {
350- wide_screen_mode : bool ,
351- enable_forward : bool ,
352- }
353-
354- impl Config {
355- fn new ( wide_screen_mode : bool , enable_forward : bool ) -> Self {
356- Self {
357- wide_screen_mode,
358- enable_forward,
359- }
360- }
361- }
362-
363- #[ derive( serde:: Serialize ) ]
364- struct Header {
365- title : PlainText ,
366- template : Option < TemplateColor > ,
367- }
368-
369- impl Header {
370- fn new ( title : impl ToString ) -> Self {
371- Self {
372- title : PlainText {
373- tag : "plain_text" . to_string ( ) ,
374- content : title. to_string ( ) ,
375- } ,
376- template : None ,
377- }
378- }
379-
380- fn template ( mut self , color : TemplateColor ) -> Self {
381- self . template = Some ( color) ;
382- self
383- }
384- }
385-
386- #[ derive( serde:: Serialize ) ]
387- struct PlainText {
388- tag : String ,
389- content : String ,
390- }
391-
392- #[ derive( serde:: Serialize ) ]
393- #[ serde( rename_all = "lowercase" ) ]
394- enum TemplateColor {
395- Blue ,
396- Wathet ,
397- Turquoise ,
398- Green ,
399- Yellow ,
400- Orange ,
401- Red ,
402- Carmine ,
403- Violet ,
404- Purple ,
405- Indigo ,
406- Grey ,
407- }
408-
409- #[ derive( serde:: Serialize ) ]
410- struct DivElement {
411- tag : String ,
412- text : Option < PlainText > ,
413- extra : Option < Button > ,
414- }
415-
416- impl DivElement {
417- fn new ( ) -> Self {
418- Self {
419- tag : "div" . to_string ( ) ,
420- text : None ,
421- extra : None ,
422- }
423- }
424-
425- fn text ( mut self , content : impl ToString ) -> Self {
426- self . text = Some ( PlainText {
427- tag : "plain_text" . to_string ( ) ,
428- content : content. to_string ( ) ,
429- } ) ;
430- self
431- }
432-
433- fn extra ( mut self , button : Button ) -> Self {
434- self . extra = Some ( button) ;
435- self
436- }
437- }
438-
439- #[ derive( serde:: Serialize ) ]
440- struct Button {
441- tag : String ,
442- text : PlainText ,
443- url : Option < String > ,
444- #[ serde( rename = "type" ) ]
445- type_ : Option < ButtonType > ,
446- }
447-
448- impl Button {
449- fn new ( text : impl ToString ) -> Self {
450- Self {
451- tag : "button" . to_string ( ) ,
452- text : PlainText {
453- tag : "plain_text" . to_string ( ) ,
454- content : text. to_string ( ) ,
455- } ,
456- url : None ,
457- type_ : None ,
458- }
459- }
460-
461- fn url ( mut self , url : impl ToString ) -> Self {
462- self . url = Some ( url. to_string ( ) ) ;
463- self
464- }
465-
466- fn type_ ( mut self , button_type : ButtonType ) -> Self {
467- self . type_ = Some ( button_type) ;
468- self
469- }
470- }
471-
472- #[ derive( serde:: Serialize ) ]
473- #[ serde( rename_all = "lowercase" ) ]
474- enum ButtonType {
475- Default ,
476- Primary ,
477- Danger ,
478- }
479-
480295// 模拟权限枚举(实际会从SDK导入)
481296#[ derive( Debug , Clone , Copy ) ]
482297enum Permission {
483298 FullAccess ,
484299 Edit ,
485300 Comment ,
301+ #[ allow( dead_code) ]
486302 View ,
487303}
0 commit comments