vkteams-bot-cli 0.7.6

High-performance VK Teams Bot API toolkit with CLI and MCP server support
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
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
//! Chat management commands module
//!
//! This module contains all commands related to chat management and information.

use crate::commands::{Command, OutputFormat};
use crate::constants::api::actions;
use crate::errors::prelude::{CliError, Result as CliResult};
use crate::output::{CliResponse, OutputFormatter};
use crate::utils::output::print_success_result;
use crate::utils::{
    validate_chat_about, validate_chat_action, validate_chat_id, validate_chat_title,
    validate_cursor,
};
use async_trait::async_trait;
use clap::{Subcommand, ValueHint};
use serde_json::json;
use tracing::{debug, info};
use vkteams_bot::prelude::*;

/// All chat management commands
#[derive(Subcommand, Debug, Clone)]
pub enum ChatCommands {
    /// Get chat information
    GetChatInfo {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
    },
    /// Get user profile information
    GetProfile {
        #[arg(short = 'u', long, required = true, value_name = "USER_ID", value_hint = ValueHint::Username)]
        user_id: String,
    },
    /// Get chat members
    GetChatMembers {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(long, value_name = "CURSOR")]
        cursor: Option<String>,
    },
    /// Set chat title
    SetChatTitle {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 't', long, required = true, value_name = "TITLE")]
        title: String,
    },
    /// Set chat description
    SetChatAbout {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'a', long, required = true, value_name = "ABOUT")]
        about: String,
    },
    /// Send typing or looking action to chat
    SendAction {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'a', long, required = true, value_name = "ACTION")]
        action: String,
    },
    /// Get chat administrators
    GetChatAdmins {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
    },
}

#[async_trait]
impl Command for ChatCommands {
    async fn execute(&self, bot: &Bot) -> CliResult<()> {
        match self {
            ChatCommands::GetChatInfo { chat_id } => execute_get_chat_info(bot, chat_id).await,
            ChatCommands::GetProfile { user_id } => execute_get_profile(bot, user_id).await,
            ChatCommands::GetChatMembers { chat_id, cursor } => {
                execute_get_chat_members(bot, chat_id, cursor.as_deref()).await
            }
            ChatCommands::SetChatTitle { chat_id, title } => {
                execute_set_chat_title(bot, chat_id, title).await
            }
            ChatCommands::SetChatAbout { chat_id, about } => {
                execute_set_chat_about(bot, chat_id, about).await
            }
            ChatCommands::SendAction { chat_id, action } => {
                execute_send_action(bot, chat_id, action).await
            }
            ChatCommands::GetChatAdmins { chat_id } => execute_get_chat_admins(bot, chat_id).await,
        }
    }

    /// New method for structured output support
    async fn execute_with_output(&self, bot: &Bot, output_format: &OutputFormat) -> CliResult<()> {
        let response = match self {
            ChatCommands::GetChatInfo { chat_id } => {
                execute_get_chat_info_structured(bot, chat_id).await
            }
            ChatCommands::GetProfile { user_id } => {
                execute_get_profile_structured(bot, user_id).await
            }
            ChatCommands::GetChatMembers { chat_id, cursor } => {
                execute_get_chat_members_structured(bot, chat_id, cursor.as_deref()).await
            }
            ChatCommands::SetChatTitle { chat_id, title } => {
                execute_set_chat_title_structured(bot, chat_id, title).await
            }
            ChatCommands::SetChatAbout { chat_id, about } => {
                execute_set_chat_about_structured(bot, chat_id, about).await
            }
            ChatCommands::SendAction { chat_id, action } => {
                execute_send_action_structured(bot, chat_id, action).await
            }
            ChatCommands::GetChatAdmins { chat_id } => {
                execute_get_chat_admins_structured(bot, chat_id).await
            }
        };

        OutputFormatter::print(&response, output_format)?;

        if !response.success {
            return Err(CliError::UnexpectedError("Command failed".to_string()));
        }

        Ok(())
    }

    fn name(&self) -> &'static str {
        match self {
            ChatCommands::GetChatInfo { .. } => "get-chat-info",
            ChatCommands::GetProfile { .. } => "get-profile",
            ChatCommands::GetChatMembers { .. } => "get-chat-members",
            ChatCommands::SetChatTitle { .. } => "set-chat-title",
            ChatCommands::SetChatAbout { .. } => "set-chat-about",
            ChatCommands::SendAction { .. } => "send-action",
            ChatCommands::GetChatAdmins { .. } => "get-chat-admins",
        }
    }

    fn validate(&self) -> CliResult<()> {
        match self {
            ChatCommands::GetChatInfo { chat_id }
            | ChatCommands::GetProfile { user_id: chat_id } => {
                validate_chat_id(chat_id)?;
            }
            ChatCommands::GetChatMembers { chat_id, cursor } => {
                validate_chat_id(chat_id)?;
                if let Some(cursor_val) = cursor {
                    validate_cursor(cursor_val)?;
                }
            }
            ChatCommands::SetChatTitle { chat_id, title } => {
                validate_chat_id(chat_id)?;
                validate_chat_title(title)?;
            }
            ChatCommands::SetChatAbout { chat_id, about } => {
                validate_chat_id(chat_id)?;
                validate_chat_about(about)?;
            }
            ChatCommands::SendAction { chat_id, action } => {
                validate_chat_id(chat_id)?;
                validate_chat_action(action)?;
            }
            ChatCommands::GetChatAdmins { chat_id } => {
                validate_chat_id(chat_id)?;
            }
        }
        Ok(())
    }
}

// Command execution functions

// Structured output versions
async fn execute_get_chat_info_structured(
    bot: &Bot,
    chat_id: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Getting chat info for {}", chat_id);

    let request = RequestChatsGetInfo::new(ChatId::from_borrowed_str(chat_id));
    match bot.send_api_request(request).await {
        Ok(result) => {
            info!("Successfully retrieved chat info for {}", chat_id);
            let data = json!({
                "chat_id": chat_id,
                "chat_info": result
            });
            CliResponse::success("get-chat-info", data)
        }
        Err(e) => CliResponse::error("get-chat-info", format!("Failed to get chat info: {e}")),
    }
}

async fn execute_get_profile_structured(
    bot: &Bot,
    user_id: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Getting profile for user {}", user_id);

    let request = RequestChatsGetInfo::new(ChatId::from_borrowed_str(user_id));
    match bot.send_api_request(request).await {
        Ok(result) => {
            info!("Successfully retrieved profile for user {}", user_id);
            let data = json!({
                "user_id": user_id,
                "profile": result
            });
            CliResponse::success("get-profile", data)
        }
        Err(e) => CliResponse::error("get-profile", format!("Failed to get profile: {e}")),
    }
}

async fn execute_get_chat_members_structured(
    bot: &Bot,
    chat_id: &str,
    cursor: Option<&str>,
) -> CliResponse<serde_json::Value> {
    debug!("Getting chat members for {}", chat_id);

    let mut request = RequestChatsGetMembers::new(ChatId::from_borrowed_str(chat_id));
    if let Some(cursor_val) = cursor {
        match cursor_val.parse::<u32>() {
            Ok(cursor_num) => {
                request = request.with_cursor(cursor_num);
            }
            Err(e) => {
                return CliResponse::error(
                    "get-chat-members",
                    format!("Invalid cursor value, must be a number: {e}"),
                );
            }
        }
    }

    match bot.send_api_request(request).await {
        Ok(result) => {
            info!("Successfully retrieved members for chat {}", chat_id);
            let data = json!({
                "chat_id": chat_id,
                "cursor": cursor,
                "members": result
            });
            CliResponse::success("get-chat-members", data)
        }
        Err(e) => CliResponse::error(
            "get-chat-members",
            format!("Failed to get chat members: {e}"),
        ),
    }
}

async fn execute_set_chat_title_structured(
    bot: &Bot,
    chat_id: &str,
    title: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Setting chat title for {} to {}", chat_id, title);

    let request =
        RequestChatsSetTitle::new((ChatId::from_borrowed_str(chat_id), title.to_string()));

    match bot.send_api_request(request).await {
        Ok(_result) => {
            info!("Successfully set title for chat {}: {}", chat_id, title);
            let data = json!({
                "chat_id": chat_id,
                "title": title,
                "action": "title_updated"
            });
            CliResponse::success("set-chat-title", data)
        }
        Err(e) => CliResponse::error("set-chat-title", format!("Failed to set chat title: {e}")),
    }
}

async fn execute_set_chat_about_structured(
    bot: &Bot,
    chat_id: &str,
    about: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Setting chat description for {} to {}", chat_id, about);

    let request =
        RequestChatsSetAbout::new((ChatId::from_borrowed_str(chat_id), about.to_string()));

    match bot.send_api_request(request).await {
        Ok(_result) => {
            info!(
                "Successfully set description for chat {}: {}",
                chat_id, about
            );
            let data = json!({
                "chat_id": chat_id,
                "about": about,
                "action": "about_updated"
            });
            CliResponse::success("set-chat-about", data)
        }
        Err(e) => CliResponse::error("set-chat-about", format!("Failed to set chat about: {e}")),
    }
}

async fn execute_send_action_structured(
    bot: &Bot,
    chat_id: &str,
    action: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Sending {} action to chat {}", action, chat_id);

    let chat_action = match action {
        actions::TYPING => ChatActions::Typing,
        actions::LOOKING => ChatActions::Looking,
        _ => {
            return CliResponse::error(
                "send-action",
                format!(
                    "Unknown action: {}. Available actions: {}, {}",
                    action,
                    actions::TYPING,
                    actions::LOOKING
                ),
            );
        }
    };

    let request = RequestChatsSendAction::new((ChatId::from_borrowed_str(chat_id), chat_action));

    match bot.send_api_request(request).await {
        Ok(_result) => {
            info!("Successfully sent {} action to chat {}", action, chat_id);
            let data = json!({
                "chat_id": chat_id,
                "action": action,
                "status": "sent"
            });
            CliResponse::success("send-action", data)
        }
        Err(e) => CliResponse::error("send-action", format!("Failed to send action: {e}")),
    }
}

async fn execute_get_chat_admins_structured(
    bot: &Bot,
    chat_id: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Getting chat administrators for {}", chat_id);

    let request = RequestChatsGetAdmins::new(ChatId::from_borrowed_str(chat_id));
    match bot.send_api_request(request).await {
        Ok(result) => {
            info!("Successfully retrieved administrators for chat {}", chat_id);
            let data = json!({
                "chat_id": chat_id,
                "admins": result
            });
            CliResponse::success("get-chat-admins", data)
        }
        Err(e) => CliResponse::error("get-chat-admins", format!("Failed to get chat admins: {e}")),
    }
}

// Legacy output versions (for backward compatibility)
async fn execute_get_chat_info(bot: &Bot, chat_id: &str) -> CliResult<()> {
    debug!("Getting chat info for {}", chat_id);

    let request = RequestChatsGetInfo::new(ChatId::from_borrowed_str(chat_id));
    let result = bot
        .send_api_request(request)
        .await
        .map_err(CliError::ApiError)?;

    info!("Successfully retrieved chat info for {}", chat_id);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_get_profile(bot: &Bot, user_id: &str) -> CliResult<()> {
    debug!("Getting profile for user {}", user_id);

    let request = RequestChatsGetInfo::new(ChatId::from_borrowed_str(user_id));
    let result = bot
        .send_api_request(request)
        .await
        .map_err(CliError::ApiError)?;

    info!("Successfully retrieved profile for user {}", user_id);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_get_chat_members(bot: &Bot, chat_id: &str, cursor: Option<&str>) -> CliResult<()> {
    debug!("Getting chat members for {}", chat_id);

    let mut request = RequestChatsGetMembers::new(ChatId::from_borrowed_str(chat_id));
    if let Some(cursor_val) = cursor {
        match cursor_val.parse::<u32>() {
            Ok(cursor_num) => {
                request = request.with_cursor(cursor_num);
            }
            Err(e) => {
                return Err(CliError::InputError(format!(
                    "Invalid cursor value, must be a number: {e}"
                )));
            }
        }
    }

    let result = bot
        .send_api_request(request)
        .await
        .map_err(CliError::ApiError)?;

    info!("Successfully retrieved members for chat {}", chat_id);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_set_chat_title(bot: &Bot, chat_id: &str, title: &str) -> CliResult<()> {
    debug!("Setting chat title for {} to {}", chat_id, title);

    let request =
        RequestChatsSetTitle::new((ChatId::from_borrowed_str(chat_id), title.to_string()));

    let result = bot
        .send_api_request(request)
        .await
        .map_err(CliError::ApiError)?;

    info!("Successfully set title for chat {}: {}", chat_id, title);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_set_chat_about(bot: &Bot, chat_id: &str, about: &str) -> CliResult<()> {
    debug!("Setting chat description for {} to {}", chat_id, about);

    let request =
        RequestChatsSetAbout::new((ChatId::from_borrowed_str(chat_id), about.to_string()));

    let result = bot
        .send_api_request(request)
        .await
        .map_err(CliError::ApiError)?;

    info!(
        "Successfully set description for chat {}: {}",
        chat_id, about
    );
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_send_action(bot: &Bot, chat_id: &str, action: &str) -> CliResult<()> {
    debug!("Sending {} action to chat {}", action, chat_id);

    let chat_action = match action {
        actions::TYPING => ChatActions::Typing,
        actions::LOOKING => ChatActions::Looking,
        _ => {
            return Err(CliError::InputError(format!(
                "Unknown action: {}. Available actions: {}, {}",
                action,
                actions::TYPING,
                actions::LOOKING
            )));
        }
    };

    let request = RequestChatsSendAction::new((ChatId::from_borrowed_str(chat_id), chat_action));

    let result = bot
        .send_api_request(request)
        .await
        .map_err(CliError::ApiError)?;

    info!("Successfully sent {} action to chat {}", action, chat_id);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_get_chat_admins(bot: &Bot, chat_id: &str) -> CliResult<()> {
    debug!("Getting chat administrators for {}", chat_id);

    let request = RequestChatsGetAdmins::new(ChatId::from_borrowed_str(chat_id));
    let result = bot
        .send_api_request(request)
        .await
        .map_err(CliError::ApiError)?;

    info!("Successfully retrieved administrators for chat {}", chat_id);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

// Validation functions are now imported from utils/validation module

#[cfg(test)]
mod tests {
    use super::*;
    use tokio::runtime::Runtime;

    #[test]
    fn test_parse_chat_id_valid() {
        let input = "12345@chat";
        let res = validate_chat_id(input);
        assert!(res.is_ok());
    }

    #[test]
    fn test_parse_chat_id_invalid() {
        let input = "user with spaces";
        let res = validate_chat_id(input);
        assert!(res.is_err());
    }

    #[test]
    fn test_handle_empty_input() {
        let input = "";
        let res = validate_chat_id(input);
        assert!(res.is_err());
    }

    #[test]
    fn test_parse_cursor_valid() {
        let input = "123";
        let res = validate_cursor(input);
        assert!(res.is_ok());
    }

    #[test]
    fn test_parse_cursor_empty() {
        let input = "";
        let res = validate_cursor(input);
        assert!(res.is_err());
    }

    #[test]
    fn test_validate_set_chat_title_invalid() {
        let cmd = ChatCommands::SetChatTitle {
            chat_id: "12345@chat".to_string(),
            title: "".to_string(),
        };
        let res = cmd.validate();
        assert!(res.is_err());
    }

    #[test]
    fn test_validate_set_chat_about_invalid() {
        let cmd = ChatCommands::SetChatAbout {
            chat_id: "12345@chat".to_string(),
            about: "".to_string(),
        };
        let res = cmd.validate();
        assert!(res.is_err());
    }

    #[test]
    fn test_validate_send_action_invalid() {
        let cmd = ChatCommands::SendAction {
            chat_id: "12345@chat".to_string(),
            action: "invalid_action".to_string(),
        };
        let res = cmd.validate();
        assert!(res.is_err());
    }

    #[test]
    fn test_validate_get_profile_invalid() {
        let cmd = ChatCommands::GetProfile {
            user_id: "".to_string(),
        };
        let res = cmd.validate();
        assert!(res.is_err());
    }

    #[test]
    fn test_validate_get_chat_members_invalid_cursor() {
        let cmd = ChatCommands::GetChatMembers {
            chat_id: "12345@chat".to_string(),
            cursor: Some("not_a_number".to_string()),
        };
        let res = cmd.validate();
        assert!(res.is_err()); // cursor должен быть числом
    }

    #[test]
    fn test_validate_get_chat_members_empty_cursor() {
        let cmd = ChatCommands::GetChatMembers {
            chat_id: "12345@chat".to_string(),
            cursor: Some("".to_string()),
        };
        let res = cmd.validate();
        assert!(res.is_err());
    }

    // Property-based тесты для title/about/action (короткие и длинные строки)
    #[test]
    fn test_validate_set_chat_title_long() {
        let cmd = ChatCommands::SetChatTitle {
            chat_id: "12345@chat".to_string(),
            title: "a".repeat(300),
        };
        let res = cmd.validate();
        assert!(res.is_err());
    }

    #[test]
    fn test_validate_set_chat_about_long() {
        let cmd = ChatCommands::SetChatAbout {
            chat_id: "12345@chat".to_string(),
            about: "a".repeat(300),
        };
        let res = cmd.validate();
        assert!(res.is_ok()); // валидация не ограничивает длину
    }

    fn dummy_bot() -> Bot {
        Bot::with_params(&APIVersionUrl::V1, "dummy_token", "https://dummy.api.com").unwrap()
    }

    #[test]
    fn test_execute_get_chat_info_api_error() {
        let cmd = ChatCommands::GetChatInfo {
            chat_id: "12345@chat".to_string(),
        };
        let bot = dummy_bot();
        let rt = Runtime::new().unwrap();
        let res = rt.block_on(cmd.execute(&bot));
        assert!(res.is_err());
    }

    #[test]
    fn test_execute_get_profile_api_error() {
        let cmd = ChatCommands::GetProfile {
            user_id: "user123".to_string(),
        };
        let bot = dummy_bot();
        let rt = Runtime::new().unwrap();
        let res = rt.block_on(cmd.execute(&bot));
        assert!(res.is_err());
    }

    #[test]
    fn test_execute_get_chat_members_api_error() {
        let cmd = ChatCommands::GetChatMembers {
            chat_id: "12345@chat".to_string(),
            cursor: None,
        };
        let bot = dummy_bot();
        let rt = Runtime::new().unwrap();
        let res = rt.block_on(cmd.execute(&bot));
        assert!(res.is_err());
    }

    #[test]
    fn test_execute_set_chat_title_api_error() {
        let cmd = ChatCommands::SetChatTitle {
            chat_id: "12345@chat".to_string(),
            title: "New Title".to_string(),
        };
        let bot = dummy_bot();
        let rt = Runtime::new().unwrap();
        let res = rt.block_on(cmd.execute(&bot));
        assert!(res.is_err());
    }

    #[test]
    fn test_execute_set_chat_about_api_error() {
        let cmd = ChatCommands::SetChatAbout {
            chat_id: "12345@chat".to_string(),
            about: "About text".to_string(),
        };
        let bot = dummy_bot();
        let rt = Runtime::new().unwrap();
        let res = rt.block_on(cmd.execute(&bot));
        assert!(res.is_err());
    }

    #[test]
    fn test_execute_send_action_invalid_action() {
        let cmd = ChatCommands::SendAction {
            chat_id: "12345@chat".to_string(),
            action: "invalid".to_string(),
        };
        let bot = dummy_bot();
        let rt = Runtime::new().unwrap();
        let res = rt.block_on(cmd.execute(&bot));
        assert!(res.is_err());
        let err = res.unwrap_err();
        match err {
            CliError::InputError(msg) => assert!(msg.contains("Unknown action")),
            _ => panic!("Expected InputError for unknown action"),
        }
    }
}

#[cfg(test)]
mod happy_path_tests {
    use super::*;
    use crate::utils::bot::create_dummy_bot;
    use tokio_test::block_on;

    #[test]
    fn test_execute_get_chat_info_success() {
        let bot = create_dummy_bot();
        let res = block_on(execute_get_chat_info(&bot, "chat123"));
        // Dummy bot may return error or Ok, but function should not panic
        let _ = res;
    }

    #[test]
    fn test_execute_get_profile_success() {
        let bot = create_dummy_bot();
        let res = block_on(execute_get_profile(&bot, "user123"));
        let _ = res;
    }

    #[test]
    fn test_execute_get_chat_members_success() {
        let bot = create_dummy_bot();
        let res = block_on(execute_get_chat_members(&bot, "chat123", Some("1")));
        let _ = res;
    }

    #[test]
    fn test_execute_set_chat_title_success() {
        let bot = create_dummy_bot();
        let res = block_on(execute_set_chat_title(&bot, "chat123", "New Title"));
        let _ = res;
    }

    #[test]
    fn test_execute_set_chat_about_success() {
        let bot = create_dummy_bot();
        let res = block_on(execute_set_chat_about(&bot, "chat123", "About"));
        let _ = res;
    }

    #[test]
    fn test_execute_send_action_success() {
        let bot = create_dummy_bot();
        let res = block_on(execute_send_action(&bot, "chat123", "typing"));
        let _ = res;
    }
}