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
//! Messaging commands module
//!
//! This module contains all commands related to sending and managing messages.

use crate::commands::{Command, OutputFormat};
use crate::constants::ui::emoji;
use crate::errors::prelude::{CliError, Result as CliResult};
use crate::file_utils;
use crate::output::{CliResponse, OutputFormatter};
use crate::utils::output::print_success_result;
use crate::utils::{
    validate_chat_id, validate_file_path, validate_message_id, validate_message_text,
    validate_voice_file_path,
};

use async_trait::async_trait;
use clap::{Subcommand, ValueHint};
use colored::Colorize;
use serde_json::json;
use tracing::{debug, info};
use vkteams_bot::prelude::*;

/// All messaging-related commands
#[derive(Subcommand, Debug, Clone)]
pub enum MessagingCommands {
    /// Send text message to user or chat
    SendText {
        #[arg(short = 'u', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'm', long, required = true, value_name = "MESSAGE")]
        message: String,
    },
    /// Send file to user or chat
    SendFile {
        #[arg(short = 'u', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'p', long, required = true, value_name = "FILE_PATH", value_hint = ValueHint::FilePath)]
        file_path: String,
    },
    /// Send voice message to user or chat
    SendVoice {
        #[arg(short = 'u', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'p', long, required = true, value_name = "FILE_PATH", value_hint = ValueHint::FilePath)]
        file_path: String,
    },
    /// Edit existing message
    EditMessage {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'm', long, required = true, value_name = "MESSAGE_ID")]
        message_id: String,
        #[arg(short = 't', long, required = true, value_name = "NEW_TEXT")]
        new_text: String,
    },
    /// Delete message from chat
    DeleteMessage {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'm', long, required = true, value_name = "MESSAGE_ID")]
        message_id: String,
    },
    /// Pin message in chat
    PinMessage {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'm', long, required = true, value_name = "MESSAGE_ID")]
        message_id: String,
    },
    /// Unpin message from chat
    UnpinMessage {
        #[arg(short = 'c', long, required = true, value_name = "CHAT_ID", value_hint = ValueHint::Username)]
        chat_id: String,
        #[arg(short = 'm', long, required = true, value_name = "MESSAGE_ID")]
        message_id: String,
    },
}

#[async_trait]
impl Command for MessagingCommands {
    async fn execute(&self, bot: &Bot) -> CliResult<()> {
        match self {
            MessagingCommands::SendText { chat_id, message } => {
                execute_send_text(bot, chat_id, message).await
            }
            MessagingCommands::SendFile { chat_id, file_path } => {
                execute_send_file(bot, chat_id, file_path).await
            }
            MessagingCommands::SendVoice { chat_id, file_path } => {
                execute_send_voice(bot, chat_id, file_path).await
            }
            MessagingCommands::EditMessage {
                chat_id,
                message_id,
                new_text,
            } => execute_edit_message(bot, chat_id, message_id, new_text).await,
            MessagingCommands::DeleteMessage {
                chat_id,
                message_id,
            } => execute_delete_message(bot, chat_id, message_id).await,
            MessagingCommands::PinMessage {
                chat_id,
                message_id,
            } => execute_pin_message(bot, chat_id, message_id).await,
            MessagingCommands::UnpinMessage {
                chat_id,
                message_id,
            } => execute_unpin_message(bot, chat_id, message_id).await,
        }
    }

    /// New method for structured output support
    async fn execute_with_output(&self, bot: &Bot, output_format: &OutputFormat) -> CliResult<()> {
        let response = match self {
            MessagingCommands::SendText { chat_id, message } => {
                execute_send_text_structured(bot, chat_id, message).await
            }
            MessagingCommands::SendFile { chat_id, file_path } => {
                execute_send_file_structured(bot, chat_id, file_path).await
            }
            MessagingCommands::SendVoice { chat_id, file_path } => {
                execute_send_voice_structured(bot, chat_id, file_path).await
            }
            MessagingCommands::EditMessage {
                chat_id,
                message_id,
                new_text,
            } => execute_edit_message_structured(bot, chat_id, message_id, new_text).await,
            MessagingCommands::DeleteMessage {
                chat_id,
                message_id,
            } => execute_delete_message_structured(bot, chat_id, message_id).await,
            MessagingCommands::PinMessage {
                chat_id,
                message_id,
            } => execute_pin_message_structured(bot, chat_id, message_id).await,
            MessagingCommands::UnpinMessage {
                chat_id,
                message_id,
            } => execute_unpin_message_structured(bot, chat_id, message_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 {
            MessagingCommands::SendText { .. } => "send-text",
            MessagingCommands::SendFile { .. } => "send-file",
            MessagingCommands::SendVoice { .. } => "send-voice",
            MessagingCommands::EditMessage { .. } => "edit-message",
            MessagingCommands::DeleteMessage { .. } => "delete-message",
            MessagingCommands::PinMessage { .. } => "pin-message",
            MessagingCommands::UnpinMessage { .. } => "unpin-message",
        }
    }

    fn validate(&self) -> CliResult<()> {
        match self {
            MessagingCommands::SendText { chat_id, message } => {
                validate_chat_id(chat_id)?;
                validate_message_text(message)?;
            }
            MessagingCommands::SendFile { chat_id, file_path } => {
                validate_chat_id(chat_id)?;
                validate_file_path(file_path)?;
            }
            MessagingCommands::SendVoice { chat_id, file_path } => {
                validate_chat_id(chat_id)?;
                validate_voice_file_path(file_path)?;
            }
            MessagingCommands::EditMessage {
                chat_id,
                message_id,
                new_text,
            } => {
                validate_chat_id(chat_id)?;
                validate_message_id(message_id)?;
                validate_message_text(new_text)?;
            }
            MessagingCommands::DeleteMessage {
                chat_id,
                message_id,
            }
            | MessagingCommands::PinMessage {
                chat_id,
                message_id,
            }
            | MessagingCommands::UnpinMessage {
                chat_id,
                message_id,
            } => {
                validate_chat_id(chat_id)?;
                validate_message_id(message_id)?;
            }
        }
        Ok(())
    }
}

// Command execution functions

// Structured output versions
async fn execute_send_text_structured(
    bot: &Bot,
    chat_id: &str,
    message: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Sending text message to {}", chat_id);

    let parser = MessageTextParser::new().add(MessageTextFormat::Plain(message.to_string()));
    let request =
        match RequestMessagesSendText::new(ChatId::from_borrowed_str(chat_id)).set_text(parser) {
            Ok(req) => req,
            Err(e) => {
                return CliResponse::error("send-text", format!("Failed to create message: {e}"));
            }
        };

    match bot.send_api_request(request).await {
        Ok(result) => {
            info!("Successfully sent text message to {}", chat_id);
            let data = json!({
                "chat_id": chat_id,
                "message": message,
                "message_id": result.msg_id
            });
            CliResponse::success("send-text", data)
        }
        Err(e) => CliResponse::error("send-text", format!("Failed to send message: {e}")),
    }
}

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

    match file_utils::upload_file(bot, chat_id, file_path).await {
        Ok(file_id) => {
            info!("Successfully sent file to {}", chat_id);
            let data = json!({
                "chat_id": chat_id,
                "file_path": file_path,
                "file_id": file_id
            });
            CliResponse::success("send-file", data)
        }
        Err(e) => CliResponse::error("send-file", format!("Failed to send file: {e}")),
    }
}

async fn execute_send_voice_structured(
    bot: &Bot,
    chat_id: &str,
    file_path: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Sending voice message {} to {}", file_path, chat_id);

    match file_utils::upload_voice(bot, chat_id, file_path).await {
        Ok(file_id) => {
            info!("Successfully sent voice message to {}", chat_id);
            let data = json!({
                "chat_id": chat_id,
                "file_path": file_path,
                "file_id": file_id
            });
            CliResponse::success("send-voice", data)
        }
        Err(e) => CliResponse::error("send-voice", format!("Failed to send voice: {e}")),
    }
}

async fn execute_edit_message_structured(
    bot: &Bot,
    chat_id: &str,
    message_id: &str,
    new_text: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Editing message {} in {}", message_id, chat_id);

    let parser = MessageTextParser::new().add(MessageTextFormat::Plain(new_text.to_string()));
    let request = match RequestMessagesEditText::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ))
    .set_text(parser)
    {
        Ok(req) => req,
        Err(e) => {
            return CliResponse::error("edit-message", format!("Failed to set message text: {e}"));
        }
    };

    match bot.send_api_request(request).await {
        Ok(_result) => {
            info!("Successfully edited message {} in {}", message_id, chat_id);
            let data = json!({
                "chat_id": chat_id,
                "message_id": message_id,
                "new_text": new_text
            });
            CliResponse::success("edit-message", data)
        }
        Err(e) => CliResponse::error("edit-message", format!("Failed to edit message: {e}")),
    }
}

async fn execute_delete_message_structured(
    bot: &Bot,
    chat_id: &str,
    message_id: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Deleting message {} from {}", message_id, chat_id);

    let request = RequestMessagesDeleteMessages::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ));

    match bot.send_api_request(request).await {
        Ok(_result) => {
            info!(
                "Successfully deleted message {} from {}",
                message_id, chat_id
            );
            let data = json!({
                "chat_id": chat_id,
                "message_id": message_id,
                "action": "deleted"
            });
            CliResponse::success("delete-message", data)
        }
        Err(e) => CliResponse::error("delete-message", format!("Failed to delete message: {e}")),
    }
}

async fn execute_pin_message_structured(
    bot: &Bot,
    chat_id: &str,
    message_id: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Pinning message {} in {}", message_id, chat_id);

    let request = RequestChatsPinMessage::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ));

    match bot.send_api_request(request).await {
        Ok(_result) => {
            info!("Successfully pinned message {} in {}", message_id, chat_id);
            let data = json!({
                "chat_id": chat_id,
                "message_id": message_id,
                "action": "pinned"
            });
            CliResponse::success("pin-message", data)
        }
        Err(e) => CliResponse::error("pin-message", format!("Failed to pin message: {e}")),
    }
}

async fn execute_unpin_message_structured(
    bot: &Bot,
    chat_id: &str,
    message_id: &str,
) -> CliResponse<serde_json::Value> {
    debug!("Unpinning message {} from {}", message_id, chat_id);

    let request = RequestChatsUnpinMessage::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ));

    match bot.send_api_request(request).await {
        Ok(_result) => {
            info!(
                "Successfully unpinned message {} from {}",
                message_id, chat_id
            );
            let data = json!({
                "chat_id": chat_id,
                "message_id": message_id,
                "action": "unpinned"
            });
            CliResponse::success("unpin-message", data)
        }
        Err(e) => CliResponse::error("unpin-message", format!("Failed to unpin message: {e}")),
    }
}

// Legacy output versions (for backward compatibility)
async fn execute_send_text(bot: &Bot, chat_id: &str, message: &str) -> CliResult<()> {
    debug!("Sending text message to {}", chat_id);

    let parser = MessageTextParser::new().add(MessageTextFormat::Plain(message.to_string()));
    let request = RequestMessagesSendText::new(ChatId::from_borrowed_str(chat_id))
        .set_text(parser)
        .map_err(|e| CliError::InputError(format!("Failed to create message: {e}")))?;

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

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

async fn execute_send_file(bot: &Bot, chat_id: &str, file_path: &str) -> CliResult<()> {
    debug!("Sending file {} to {}", file_path, chat_id);

    file_utils::upload_file(bot, chat_id, file_path).await?;

    info!("Successfully sent file to {}", chat_id);
    println!(
        "{} File sent successfully to {}",
        emoji::CHECK,
        chat_id.green()
    );
    Ok(())
}

async fn execute_send_voice(bot: &Bot, chat_id: &str, file_path: &str) -> CliResult<()> {
    debug!("Sending voice message {} to {}", file_path, chat_id);

    file_utils::upload_voice(bot, chat_id, file_path).await?;

    info!("Successfully sent voice message to {}", chat_id);
    println!(
        "{} Voice message sent successfully to {}",
        emoji::CHECK,
        chat_id.green()
    );
    Ok(())
}

async fn execute_edit_message(
    bot: &Bot,
    chat_id: &str,
    message_id: &str,
    new_text: &str,
) -> CliResult<()> {
    debug!("Editing message {} in {}", message_id, chat_id);

    let parser = MessageTextParser::new().add(MessageTextFormat::Plain(new_text.to_string()));
    let request = RequestMessagesEditText::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ))
    .set_text(parser)
    .map_err(|e| CliError::InputError(format!("Failed to set message text: {e}")))?;

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

    info!("Successfully edited message {} in {}", message_id, chat_id);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_delete_message(bot: &Bot, chat_id: &str, message_id: &str) -> CliResult<()> {
    debug!("Deleting message {} from {}", message_id, chat_id);

    let request = RequestMessagesDeleteMessages::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ));

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

    info!(
        "Successfully deleted message {} from {}",
        message_id, chat_id
    );
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_pin_message(bot: &Bot, chat_id: &str, message_id: &str) -> CliResult<()> {
    debug!("Pinning message {} in {}", message_id, chat_id);

    let request = RequestChatsPinMessage::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ));

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

    info!("Successfully pinned message {} in {}", message_id, chat_id);
    print_success_result(&result, &OutputFormat::Pretty)?;
    Ok(())
}

async fn execute_unpin_message(bot: &Bot, chat_id: &str, message_id: &str) -> CliResult<()> {
    debug!("Unpinning message {} from {}", message_id, chat_id);

    let request = RequestChatsUnpinMessage::new((
        ChatId::from_borrowed_str(chat_id),
        MsgId(message_id.to_string()),
    ));

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

    info!(
        "Successfully unpinned message {} from {}",
        message_id, 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_send_text_valid() {
        let cmd = MessagingCommands::SendText {
            chat_id: "user123".to_string(),
            message: "Hello".to_string(),
        };
        assert!(cmd.validate().is_ok());
    }

    #[test]
    fn test_send_text_invalid_chat_id() {
        let cmd = MessagingCommands::SendText {
            chat_id: "user with spaces".to_string(),
            message: "Hello".to_string(),
        };
        assert!(cmd.validate().is_err());
    }

    #[test]
    fn test_send_text_empty_message() {
        let cmd = MessagingCommands::SendText {
            chat_id: "user123".to_string(),
            message: "".to_string(),
        };
        assert!(cmd.validate().is_err());
    }

    #[test]
    fn test_send_file_invalid_path() {
        let cmd = MessagingCommands::SendFile {
            chat_id: "user123".to_string(),
            file_path: "nonexistent.file".to_string(),
        };
        // Путь не существует, validate_file_path вернет ошибку
        assert!(cmd.validate().is_err());
    }

    #[test]
    fn test_send_voice_invalid_path() {
        let cmd = MessagingCommands::SendVoice {
            chat_id: "user123".to_string(),
            file_path: "nonexistent.ogg".to_string(),
        };
        assert!(cmd.validate().is_err());
    }

    #[test]
    fn test_edit_message_invalid_message_id() {
        let cmd = MessagingCommands::EditMessage {
            chat_id: "user123".to_string(),
            message_id: "id with space".to_string(),
            new_text: "new text".to_string(),
        };
        assert!(cmd.validate().is_err());
    }

    #[test]
    fn test_delete_message_empty_message_id() {
        let cmd = MessagingCommands::DeleteMessage {
            chat_id: "user123".to_string(),
            message_id: "".to_string(),
        };
        assert!(cmd.validate().is_err());
    }

    #[test]
    fn test_pin_message_valid() {
        let cmd = MessagingCommands::PinMessage {
            chat_id: "user123".to_string(),
            message_id: "msg123".to_string(),
        };
        assert!(cmd.validate().is_ok());
    }

    #[test]
    fn test_unpin_message_invalid_chat_id() {
        let cmd = MessagingCommands::UnpinMessage {
            chat_id: "invalid id".to_string(),
            message_id: "msg123".to_string(),
        };
        assert!(cmd.validate().is_err());
    }

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

    #[test]
    fn test_execute_send_text_api_error() {
        let cmd = MessagingCommands::SendText {
            chat_id: "12345@chat".to_string(),
            message: "hello".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_file_api_error() {
        let cmd = MessagingCommands::SendFile {
            chat_id: "12345@chat".to_string(),
            file_path: "/tmp/file.txt".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_voice_api_error() {
        let cmd = MessagingCommands::SendVoice {
            chat_id: "12345@chat".to_string(),
            file_path: "/tmp/voice.ogg".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_edit_message_api_error() {
        let cmd = MessagingCommands::EditMessage {
            chat_id: "12345@chat".to_string(),
            message_id: "msgid".to_string(),
            new_text: "new 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_delete_message_api_error() {
        let cmd = MessagingCommands::DeleteMessage {
            chat_id: "12345@chat".to_string(),
            message_id: "msgid".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_pin_message_api_error() {
        let cmd = MessagingCommands::PinMessage {
            chat_id: "12345@chat".to_string(),
            message_id: "msgid".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_unpin_message_api_error() {
        let cmd = MessagingCommands::UnpinMessage {
            chat_id: "12345@chat".to_string(),
            message_id: "msgid".to_string(),
        };
        let bot = dummy_bot();
        let rt = Runtime::new().unwrap();
        let res = rt.block_on(cmd.execute(&bot));
        assert!(res.is_err());
    }
}