botrs 0.2.9

A Rust QQ Bot framework based on QQ Guild Bot API
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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# Interactive Messages Example

This example demonstrates how to create interactive messages with buttons, keyboards, and rich embeds using BotRS.

## Overview

Interactive messages allow users to interact with your bot through buttons, select menus, and other UI components. This creates a more engaging user experience compared to text-only interactions.

## Basic Interactive Components

### Simple Button Example

```rust
use botrs::{
    Client, Context, EventHandler, Intents, Message, Ready, Token, BotError,
    models::message::{
        Keyboard, KeyboardContent, KeyboardRow, KeyboardButton,
        KeyboardButtonRenderData, KeyboardButtonAction, MessageParams
    }
};

struct InteractiveBot;

#[async_trait::async_trait]
impl EventHandler for InteractiveBot {
    async fn ready(&self, _ctx: Context, ready: Ready) {
        println!("Interactive bot ready: {}", ready.user.username);
    }

    async fn message_create(&self, ctx: Context, message: Message) {
        if message.is_from_bot() {
            return;
        }

        if let Some(content) = &message.content {
            match content.trim() {
                "!button" => {
                    if let Err(e) = self.send_button_message(&ctx, &message).await {
                        eprintln!("Failed to send button message: {}", e);
                    }
                }
                "!poll" => {
                    if let Err(e) = self.send_poll_message(&ctx, &message).await {
                        eprintln!("Failed to send poll: {}", e);
                    }
                }
                "!menu" => {
                    if let Err(e) = self.send_menu_message(&ctx, &message).await {
                        eprintln!("Failed to send menu: {}", e);
                    }
                }
                _ => {}
            }
        }
    }
}

impl InteractiveBot {
    async fn send_button_message(&self, ctx: &Context, message: &Message) -> Result<(), BotError> {
        let keyboard = Keyboard {
            content: Some(KeyboardContent {
                rows: vec![
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("btn_action".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "Click Me! 👆".to_string(),
                                    visited_label: "Clicked! ✅".to_string(),
                                    style: Some(1), // Primary style
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2), // Callback action
                                    permission: None,
                                    click_limit: None,
                                    data: Some("button_clicked".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                ],
            }),
        };

        let params = MessageParams {
            content: Some("Here's an interactive button:".to_string()),
            keyboard: Some(keyboard),
            ..Default::default()
        };

        ctx.send_message(&message.channel_id, &params).await?;
        Ok(())
    }
}
```

### Poll with Multiple Options

```rust
impl InteractiveBot {
    async fn send_poll_message(&self, ctx: &Context, message: &Message) -> Result<(), BotError> {
        let keyboard = Keyboard {
            content: Some(KeyboardContent {
                rows: vec![
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("poll_option_1".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "Option A 🅰️".to_string(),
                                    visited_label: "Voted for A ✅".to_string(),
                                    style: Some(1),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: Some(1), // One vote per user
                                    data: Some("vote_a".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some("poll_option_2".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "Option B 🅱️".to_string(),
                                    visited_label: "Voted for B ✅".to_string(),
                                    style: Some(2),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: Some(1),
                                    data: Some("vote_b".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("poll_option_3".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "Option C 🅲".to_string(),
                                    visited_label: "Voted for C ✅".to_string(),
                                    style: Some(3),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: Some(1),
                                    data: Some("vote_c".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some("poll_results".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "View Results 📊".to_string(),
                                    visited_label: "Results Shown".to_string(),
                                    style: Some(4),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("show_results".to_string()),
                                    reply: None,
                                    enter: Some(false),
                                }),
                            },
                        ],
                    },
                ],
            }),
        };

        let params = MessageParams {
            content: Some("📊 **Quick Poll: What's your favorite programming language?**\n\nChoose one option below:".to_string()),
            keyboard: Some(keyboard),
            ..Default::default()
        };

        ctx.send_message(&message.channel_id, &params).await?;
        Ok(())
    }
}
```

### Navigation Menu

```rust
impl InteractiveBot {
    async fn send_menu_message(&self, ctx: &Context, message: &Message) -> Result<(), BotError> {
        let keyboard = Keyboard {
            content: Some(KeyboardContent {
                rows: vec![
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("menu_help".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "📖 Help".to_string(),
                                    visited_label: "Help Viewed".to_string(),
                                    style: Some(1),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("show_help".to_string()),
                                    reply: None,
                                    enter: Some(false),
                                }),
                            },
                            KeyboardButton {
                                id: Some("menu_settings".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "⚙️ Settings".to_string(),
                                    visited_label: "Settings Opened".to_string(),
                                    style: Some(2),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("show_settings".to_string()),
                                    reply: None,
                                    enter: Some(false),
                                }),
                            },
                        ],
                    },
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("menu_stats".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "📈 Statistics".to_string(),
                                    visited_label: "Stats Viewed".to_string(),
                                    style: Some(3),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("show_stats".to_string()),
                                    reply: None,
                                    enter: Some(false),
                                }),
                            },
                            KeyboardButton {
                                id: Some("menu_about".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "ℹ️ About".to_string(),
                                    visited_label: "About Viewed".to_string(),
                                    style: Some(4),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("show_about".to_string()),
                                    reply: None,
                                    enter: Some(false),
                                }),
                            },
                        ],
                    },
                ],
            }),
        };

        let params = MessageParams {
            content: Some("🎛️ **Main Menu**\n\nSelect an option to continue:".to_string()),
            keyboard: Some(keyboard),
            ..Default::default()
        };

        ctx.send_message(&message.channel_id, &params).await?;
        Ok(())
    }
}
```

## Rich Interactive Messages with Embeds

### Embed with Interactive Elements

```rust
use botrs::models::message::{Embed, EmbedField, EmbedFooter};

impl InteractiveBot {
    async fn send_rich_interactive_message(&self, ctx: &Context, message: &Message) -> Result<(), BotError> {
        let embed = Embed {
            title: Some("🎮 Game Selection".to_string()),
            description: Some("Choose a game to play with the bot!".to_string()),
            color: Some(0x7289da), // Discord blurple
            fields: vec![
                EmbedField {
                    name: "🎲 Rock Paper Scissors".to_string(),
                    value: "Classic game of chance".to_string(),
                    inline: Some(true),
                },
                EmbedField {
                    name: "🎯 Trivia".to_string(),
                    value: "Test your knowledge".to_string(),
                    inline: Some(true),
                },
                EmbedField {
                    name: "🎪 Random Fun".to_string(),
                    value: "Surprise me!".to_string(),
                    inline: Some(true),
                },
            ],
            footer: Some(EmbedFooter {
                text: "Click a button below to start".to_string(),
                icon_url: None,
            }),
            timestamp: Some(chrono::Utc::now().to_rfc3339()),
            ..Default::default()
        };

        let keyboard = Keyboard {
            content: Some(KeyboardContent {
                rows: vec![
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("game_rps".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🎲 Rock Paper Scissors".to_string(),
                                    visited_label: "Game Started!".to_string(),
                                    style: Some(1),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("start_rps".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("game_trivia".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🎯 Start Trivia".to_string(),
                                    visited_label: "Trivia Started!".to_string(),
                                    style: Some(2),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("start_trivia".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some("game_random".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🎪 Random Fun".to_string(),
                                    visited_label: "Surprise Activated!".to_string(),
                                    style: Some(3),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("start_random".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                ],
            }),
        };

        let params = MessageParams {
            embed: Some(embed),
            keyboard: Some(keyboard),
            ..Default::default()
        };

        ctx.send_message(&message.channel_id, &params).await?;
        Ok(())
    }
}
```

## Advanced Interactive Patterns

### Multi-Step Interaction

```rust
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::Mutex;

#[derive(Clone)]
pub struct InteractionState {
    pub user_id: String,
    pub step: u32,
    pub data: HashMap<String, String>,
}

pub struct AdvancedInteractiveBot {
    interaction_states: Arc<Mutex<HashMap<String, InteractionState>>>,
}

impl AdvancedInteractiveBot {
    pub fn new() -> Self {
        Self {
            interaction_states: Arc::new(Mutex::new(HashMap::new())),
        }
    }

    async fn start_setup_wizard(&self, ctx: &Context, message: &Message) -> Result<(), BotError> {
        let user_id = message.author.as_ref().unwrap().id.clone();
        
        // Initialize interaction state
        {
            let mut states = self.interaction_states.lock().await;
            states.insert(user_id.clone(), InteractionState {
                user_id: user_id.clone(),
                step: 1,
                data: HashMap::new(),
            });
        }

        let keyboard = Keyboard {
            content: Some(KeyboardContent {
                rows: vec![
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("setup_step1_beginner".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🌱 Beginner".to_string(),
                                    visited_label: "Beginner Selected".to_string(),
                                    style: Some(1),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("level_beginner".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some("setup_step1_intermediate".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🌿 Intermediate".to_string(),
                                    visited_label: "Intermediate Selected".to_string(),
                                    style: Some(2),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("level_intermediate".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some("setup_step1_advanced".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🌳 Advanced".to_string(),
                                    visited_label: "Advanced Selected".to_string(),
                                    style: Some(3),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("level_advanced".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                ],
            }),
        };

        let params = MessageParams {
            content: Some("🛠️ **Setup Wizard - Step 1/3**\n\nWhat's your experience level?".to_string()),
            keyboard: Some(keyboard),
            ..Default::default()
        };

        ctx.send_message(&message.channel_id, &params).await?;
        Ok(())
    }

    async fn handle_setup_step2(&self, ctx: &Context, channel_id: &str, user_id: &str) -> Result<(), BotError> {
        let keyboard = Keyboard {
            content: Some(KeyboardContent {
                rows: vec![
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("setup_step2_gaming".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🎮 Gaming".to_string(),
                                    visited_label: "Gaming Selected".to_string(),
                                    style: Some(1),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("interest_gaming".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some("setup_step2_music".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🎵 Music".to_string(),
                                    visited_label: "Music Selected".to_string(),
                                    style: Some(2),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("interest_music".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some("setup_step2_tech".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "💻 Technology".to_string(),
                                    visited_label: "Tech Selected".to_string(),
                                    style: Some(3),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("interest_tech".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some("setup_step2_art".to_string()),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "🎨 Art & Design".to_string(),
                                    visited_label: "Art Selected".to_string(),
                                    style: Some(4),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: None,
                                    data: Some("interest_art".to_string()),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                ],
            }),
        };

        let params = MessageParams {
            content: Some("🛠️ **Setup Wizard - Step 2/3**\n\nWhat are your main interests?".to_string()),
            keyboard: Some(keyboard),
            ..Default::default()
        };

        ctx.send_message(channel_id, &params).await?;
        Ok(())
    }

    async fn complete_setup(&self, ctx: &Context, channel_id: &str, user_id: &str) -> Result<(), BotError> {
        let state = {
            let states = self.interaction_states.lock().await;
            states.get(user_id).cloned()
        };

        if let Some(user_state) = state {
            let level = user_state.data.get("level").unwrap_or(&"unknown".to_string());
            let interest = user_state.data.get("interest").unwrap_or(&"unknown".to_string());

            let embed = Embed {
                title: Some("✅ Setup Complete!".to_string()),
                description: Some("Your preferences have been saved.".to_string()),
                color: Some(0x00ff00), // Green
                fields: vec![
                    EmbedField {
                        name: "Experience Level".to_string(),
                        value: level.clone(),
                        inline: Some(true),
                    },
                    EmbedField {
                        name: "Primary Interest".to_string(),
                        value: interest.clone(),
                        inline: Some(true),
                    },
                ],
                footer: Some(EmbedFooter {
                    text: "You can change these settings anytime with !setup".to_string(),
                    icon_url: None,
                }),
                ..Default::default()
            };

            let params = MessageParams {
                embed: Some(embed),
                ..Default::default()
            };

            ctx.send_message(channel_id, &params).await?;

            // Clean up interaction state
            let mut states = self.interaction_states.lock().await;
            states.remove(user_id);
        }

        Ok(())
    }
}
```

## Best Practices

### 1. Button State Management

```rust
pub struct ButtonStateManager {
    button_states: Arc<Mutex<HashMap<String, ButtonState>>>,
}

#[derive(Clone)]
pub struct ButtonState {
    pub enabled: bool,
    pub click_count: u32,
    pub last_clicked: Option<chrono::DateTime<chrono::Utc>>,
    pub clicked_by: Vec<String>,
}

impl ButtonStateManager {
    pub async fn handle_button_click(&self, button_id: &str, user_id: &str) -> bool {
        let mut states = self.button_states.lock().await;
        let state = states.entry(button_id.to_string()).or_insert(ButtonState {
            enabled: true,
            click_count: 0,
            last_clicked: None,
            clicked_by: Vec::new(),
        });

        if !state.enabled {
            return false;
        }

        // Check if user already clicked (for polls)
        if state.clicked_by.contains(&user_id.to_string()) {
            return false;
        }

        state.click_count += 1;
        state.last_clicked = Some(chrono::Utc::now());
        state.clicked_by.push(user_id.to_string());

        true
    }
}
```

### 2. Timeout Handling

```rust
impl InteractiveBot {
    async fn send_timed_interactive_message(&self, ctx: &Context, message: &Message) -> Result<(), BotError> {
        let keyboard = self.create_timed_keyboard();
        
        let params = MessageParams {
            content: Some("⏰ **Timed Poll** (expires in 60 seconds)\n\nVote now!".to_string()),
            keyboard: Some(keyboard),
            ..Default::default()
        };

        let sent_message = ctx.send_message(&message.channel_id, &params).await?;

        // Schedule message update after timeout
        let ctx_clone = ctx.clone();
        let channel_id = message.channel_id.clone();
        tokio::spawn(async move {
            tokio::time::sleep(std::time::Duration::from_secs(60)).await;
            
            let expired_params = MessageParams {
                content: Some("⏰ **Poll Expired**\n\nThis poll has ended. Thanks to everyone who participated!".to_string()),
                ..Default::default()
            };

            // Note: In a real implementation, you'd need message editing capabilities
            // For now, we send a new message
            let _ = ctx_clone.send_message(&channel_id, &expired_params).await;
        });

        Ok(())
    }

    fn create_timed_keyboard(&self) -> Keyboard {
        // Create keyboard with timestamp in button data
        let timestamp = chrono::Utc::now().timestamp();
        
        Keyboard {
            content: Some(KeyboardContent {
                rows: vec![
                    KeyboardRow {
                        buttons: vec![
                            KeyboardButton {
                                id: Some(format!("timed_yes_{}", timestamp)),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "👍 Yes".to_string(),
                                    visited_label: "Voted Yes".to_string(),
                                    style: Some(1),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: Some(1),
                                    data: Some(format!("vote_yes_{}", timestamp)),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                            KeyboardButton {
                                id: Some(format!("timed_no_{}", timestamp)),
                                render_data: Some(KeyboardButtonRenderData {
                                    label: "👎 No".to_string(),
                                    visited_label: "Voted No".to_string(),
                                    style: Some(2),
                                }),
                                action: Some(KeyboardButtonAction {
                                    action_type: Some(2),
                                    permission: None,
                                    click_limit: Some(1),
                                    data: Some(format!("vote_no_{}", timestamp)),
                                    reply: None,
                                    enter: Some(true),
                                }),
                            },
                        ],
                    },
                ],
            }),
        }
    }
}
```

## Usage Examples

### Basic Interactive Commands

```
# Send a simple button
!button

# Create a poll
!poll

# Show navigation menu
!menu

# Start setup wizard
!setup
```

### Advanced Features

- **Multi-step interactions**: Guide users through complex workflows
- **State persistence**: Remember user choices across sessions
- **Conditional buttons**: Show different options based on user state
- **Timed interactions**: Auto-expire interactive elements
- **Permission-based buttons**: Show buttons only to authorized users

## Integration Tips

1. **Combine with embeds**: Use rich embeds to provide context for interactive elements
2. **Handle timeouts**: Always have fallback behavior for expired interactions
3. **Validate permissions**: Check user permissions before showing sensitive buttons
4. **Provide feedback**: Always acknowledge button clicks with appropriate responses
5. **Clean up state**: Remove interaction states after completion to prevent memory leaks

## See Also

- [Rich Messages]./rich-messages.md - Advanced message formatting
- [Command Handler]./command-handler.md - Structured command processing
- [Event Handling]./event-handling.md - Comprehensive event processing
- [File Uploads]./file-uploads.md - Working with attachments and media