ruwa 1.0.0

Rust client for WhatsApp Web
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
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
# RuWa

> **WhatsApp Web API dalam Rust** - Library paling lengkap untuk membuat bot WhatsApp

<div align="center">

[![Version](https://img.shields.io/crates/v/ruwa.svg?style=for-the-badge&logo=rust)](https://crates.io/crates/ruwa)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![Build](https://img.shields.io/github/actions/workflow/status/jrevanaldi-ai/ruwa/main.yml?style=for-the-badge&logo=github)](https://github.com/jrevanaldi-ai/ruwa/actions)
[![Downloads](https://img.shields.io/crates/d/ruwa?style=for-the-badge&color=orange)](https://crates.io/crates/ruwa)

</div>

---

<div align="center">

## 📬 Kontak Developer

[![WhatsApp](https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge&logo=whatsapp&logoColor=white)](https://wa.me/62895416602000)
[![Instagram](https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white)](https://instagram.com/chrisjoo_uww)
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/AstraluneSuport)
[![Email](https://img.shields.io/badge/Email-D14836?style=for-the-badge&logo=gmail&logoColor=white)](mailto:support@nathan.christmas)
[![GitHub](https://img.shields.io/badge/GitHub-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/jrevanaldi-ai/ruwa)

> 🤖 **Note**: Dokumentasi dibuat dengan AI. Found a bug? Contact developer!

</div>

---

## 🎯 Kenapa RuWa?

| Feature | RuWa | Library Lain |
|---------|------|--------------|
| **Performance** | ⚡ Rust (native speed) | 🐢 Node.js/Python |
| **Memory Usage** | 💾 < 50MB | 📦 200MB+ |
| **Type Safety** | ✅ Compile-time checks | ❌ Runtime errors |
| **E2E Encryption** | ✅ Signal Protocol | ✅ Varies |
| **Multi-device** | ✅ Up to 4 devices | ⚠️ Limited |
| **Documentation** | 📖 Complete | ⚠️ Incomplete |

---

## 📑 Table of Contents

<details>
<summary><b>📖 Klik untuk expand semua section</b></summary>

1. [🚀 Quick Start]#-quick-start - Mulai dalam 5 menit
2. [📦 Instalasi Lengkap]#-instalasi-lengkap - Step-by-step
3. [✨ Fitur Lengkap]#-fitur-lengkap - Semua yang tersedia
4. [🔐 Autentikasi]#-autentikasi - QR & Pair code
5. [💬 Messaging]#-messaging - Kirim & terima pesan
6. [📸 Media]#-media - Upload & download
7. [👥 Grup Management]#-grup-management
8. [📊 Presence & Receipts]#-presence--receipts
9. [⚙️ Advanced Usage]#-advanced-usage
10. [🐛 Troubleshooting]#-troubleshooting
11. [❓ FAQ]#-faq
12. [⚠️ Disclaimer]#-disclaimer

</details>

---

## 🚀 Quick Start

### Mulai dalam 5 Menit

```bash
# 1. Clone atau buat project baru
cargo new my-whatsapp-bot
cd my-whatsapp-bot

# 2. Tambahkan dependencies
cargo add ruwa ruwa-sqlite-storage ruwa-tokio-transport ruwa-ureq-http-client
cargo add tokio --features full
```

### Contoh Bot Sederhana

```rust
// src/main.rs
use ruwa::bot::Bot;
use ruwa::store::SqliteStore;
use ruwa_tokio_transport::TokioWebSocketTransportFactory;
use ruwa_ureq_http_client::UreqHttpClient;
use wacore::types::events::Event;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Setup storage
    let store = SqliteStore::new("whatsapp.db").await?;
    
    // 2. Build bot
    let mut bot = Bot::builder()
        .with_backend(store)
        .with_transport_factory(TokioWebSocketTransportFactory::new())
        .with_http_client(UreqHttpClient::new())
        .on_event(|event, client| async move {
            match event {
                // QR Code received
                Event::PairingQrCode { code, timeout } => {
                    println!("📱 Scan QR code (valid {} detik):", timeout.as_secs());
                    println!("{}", code);
                }
                
                // Pair code received
                Event::PairingCode { code, timeout } => {
                    println!("🔢 Masukkan kode ini: {}", code);
                }
                
                // Message received
                Event::Message(msg, info) => {
                    println!("💬 Pesan dari {}", info.source.sender);
                    
                    // Auto reply "ping" dengan "pong"
                    if let Some(text) = msg.text_content() {
                        if text.to_lowercase() == "ping" {
                            let _ = client.send_message(
                                info.source.chat,
                                waproto::whatsapp::Message {
                                    conversation: Some("🏓 Pong!".to_string()),
                                    ..Default::default()
                                }
                            ).await;
                        }
                    }
                }
                
                // Connected
                Event::Connected(_) => {
                    println!("✅ Bot connected & ready!");
                }
                
                _ => {}
            }
        })
        .build()
        .await?;
    
    // 3. Run bot
    bot.run().await?.await?;
    
    Ok(())
}
```

### Jalankan

```bash
# Run dengan QR code
cargo run

# Run dengan pair code (nomor telepon)
cargo run -- --phone 6281234567890

# Run dengan custom pair code
cargo run -- -p 6281234567890 --code ABCD1234
```

---

## 📦 Instalasi Lengkap

### 1. Cargo.toml

```toml
[package]
name = "my-whatsapp-bot"
version = "0.1.0"
edition = "2021"

[dependencies]
# RuWa core
ruwa = "1.0.0"

# Storage (pilih salah satu)
ruwa-sqlite-storage = "1.0.0"  # SQLite (recommended)

# Transport
ruwa-tokio-transport = "1.0.0"  # WebSocket

# HTTP Client
ruwa-ureq-http-client = "1.0.0"

# Async runtime
tokio = { version = "1.48", features = ["full"] }

# Utilities
log = "0.4"
env_logger = "0.11"
chrono = "0.4"
```

### 2. System Requirements

```bash
# Install Rust (Linux/Mac)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install Rust (Windows)
# Download dari https://rustup.rs/

# Install Rust (Termux/Android)
pkg install rust

# Install protoc (Protocol Buffers)
# Ubuntu/Debian
sudo apt install protobuf-compiler

# macOS
brew install protobuf

# Windows
# Download dari https://github.com/protocolbuffers/protobuf/releases

# Verify installation
rustc --version    # Should be 1.70+
cargo --version
protoc --version
```

### 3. Build & Run

```bash
# Development build
cargo build

# Release build (optimized)
cargo build --release

# Run
cargo run

# Run with logging
RUST_LOG=info cargo run
```

---

## ✨ Fitur Lengkap

### 🔐 Autentikasi

| Method | Deskripsi | Status |
|--------|-----------|--------|
| **QR Code** | Scan QR dari WhatsApp | ✅ Ready |
| **Pair Code** | 8-digit code via phone | ✅ Ready |
| **Session Persist** | Auto-reconnect | ✅ Ready |
| **Multi-device** | Link up to 4 devices | ✅ Ready |

### 💬 Messaging

| Feature | Status | Example |
|---------|--------|---------|
| Text messages || `conversation: Some("Hello")` |
| Image messages || `image_message: Some(...)` |
| Video messages || `video_message: Some(...)` |
| Audio messages || `audio_message: Some(...)` |
| Document messages || `document_message: Some(...)` |
| Location messages || `location_message: Some(...)` |
| Contact messages || `contact_message: Some(...)` |
| Sticker messages | ⚠️ | Partial support |
| Edit messages || `edit_message(id, new_msg)` |
| Delete messages || `revoke_message(id)` |
| Reply/Quote || `context_info: Some(...)` |
| Reactions || `reaction_message: Some(...)` |

### 📸 Media

| Type | Upload | Download | Status |
|------|--------|----------|--------|
| Images ||| Full support |
| Videos ||| Full support |
| Audio ||| Full support |
| Documents ||| Full support |
| GIFs ||| Full support |
| Stickers | ⚠️ | ⚠️ | Partial |

### 👥 Grup

| Feature | Status | Method |
|---------|--------|--------|
| Create group || `groups().create()` |
| List groups || `groups().list()` |
| Get metadata || `groups().get_metadata()` |
| Add participants || `groups().add_participants()` |
| Remove participants || `groups().remove_participants()` |
| Promote to admin || `groups().promote_participants()` |
| Demote admin || `groups().demote_participants()` |
| Update subject || `groups().set_subject()` |
| Update description || `groups().set_description()` |
| Set ephemeral || `groups().set_ephemeral()` |
| Invite link || `groups().get_invite_link()` |
| Leave group || `groups().leave()` |

### 📊 Presence & Receipts

| Feature | Status |
|---------|--------|
| Set online/offline ||
| Subscribe presence ||
| Typing indicator ||
| Recording indicator ||
| Read receipts ||
| Delivery receipts ||
| Played receipts (audio) ||

---

## 🔐 Autentikasi Detail

### Method 1: QR Code (Default)

```rust
Bot::builder()
    .with_backend(store)
    .on_event(|event, _client| async move {
        if let Event::PairingQrCode { code, timeout } = event {
            println!("QR Code valid untuk {} detik", timeout.as_secs());
            println!("{}", code);
            // QR akan auto-rotate jika expired
        }
        
        if let Event::PairSuccess(_) = event {
            println!("✅ Pairing berhasil!");
        }
    })
    .build()
    .await?
```

### Method 2: Pair Code (Phone Number)

```rust
use ruwa::bot::{Bot, PairCodeOptions};
use ruwa::pair_code::PlatformId;

Bot::builder()
    .with_backend(store)
    .with_pair_code(PairCodeOptions {
        phone_number: "6281234567890".to_string(),
        custom_code: None,  // Atau Some("ABCD1234") untuk custom
        platform: PlatformId::Chrome,  // Chrome, Firefox, Edge, Safari
    })
    .on_event(|event, _client| async move {
        if let Event::PairingCode { code, timeout } = event {
            println!("Masukkan kode di WhatsApp:");
            println!("WhatsApp > Linked Devices > Link a Device");
            println!("> Link with phone number instead");
            println!("Kode: {}", code);
        }
    })
    .build()
    .await?
```

### Method 3: Session Persist (Auto-login)

```rust
// Session otomatis tersimpan di database
// Restart aplikasi = auto reconnect tanpa pairing ulang

let bot = Bot::builder()
    .with_backend(SqliteStore::new("whatsapp.db").await?)
    .build()
    .await?;

// Jika session masih valid, langsung connected
// Jika expired, akan trigger QR/Pair code
```

---

## 💬 Messaging Detail

### Kirim Pesan Teks

```rust
use ruwa::Jid;
use waproto::whatsapp as wa;

let chat_id: Jid = "6281234567890@s.whatsapp.net".parse()?;

let msg_id = client.send_message(chat_id, wa::Message {
    conversation: Some("Hello, World!".to_string()),
    ..Default::default()
}).await?;

println!("Pesan terkirim dengan ID: {}", msg_id);
```

### Reply/Quote Pesan

```rust
use wacore::proto_helpers::build_quote_context;

// Build quote context
let quote_context = build_quote_context(
    &original_msg_id,      // ID pesan yang di-quote
    &original_sender_jid,  // JID pengirim pesan original
    &chat_jid,             // JID chat
    &original_message      // Pesan original
);

// Kirim reply
client.send_message(chat_jid, wa::Message {
    extended_text_message: Some(Box::new(
        wa::message::ExtendedTextMessage {
            text: Some("Ini balasan".to_string()),
            context_info: Some(Box::new(quote_context)),
            ..Default::default()
        }
    )),
    ..Default::default()
}).await?;
```

### Reaction (Emoji)

```rust
use chrono::Utc;

client.send_message(chat_jid, wa::Message {
    reaction_message: Some(wa::message::ReactionMessage {
        key: Some(wa::MessageKey {
            remote_jid: Some(chat_jid.to_string()),
            id: Some(msg_id.to_string()),
            from_me: Some(false),
            participant: None,
        }),
        text: Some("👍".to_string()),
        sender_timestamp_ms: Some(Utc::now().timestamp_millis()),
        ..Default::default()
    }),
    ..Default::default()
}).await?;
```

### Edit Pesan

```rust
let new_message = wa::Message {
    conversation: Some("Pesan yang sudah diedit".to_string()),
    ..Default::default()
};

client.edit_message(
    chat_jid,
    original_msg_id,
    new_message
).await?;
```

### Delete Pesan (Revoke)

```rust
use ruwa::send::RevokeType;

// Delete pesan sendiri
client.revoke_message(
    chat_jid,
    msg_id.to_string(),
    RevokeType::Sender,
).await?;

// Admin delete pesan user lain (di grup)
client.revoke_message(
    group_jid,
    msg_id.to_string(),
    RevokeType::Admin { 
        original_sender: sender_jid 
    },
).await?;
```

### Forward Pesan

```rust
// Forward ke chat lain
client.send_message(
    target_chat_jid,
    original_message.clone()  // Clone pesan original
).await?;
```

---

## 📸 Media Detail

### Upload & Kirim Gambar

```rust
use ruwa::download::MediaType;

// 1. Baca file
let image_data = std::fs::read("foto.jpg")?;

// 2. Upload ke WhatsApp server
let upload = client.upload(image_data, MediaType::Image).await?;

// 3. Build message
let message = wa::Message {
    image_message: Some(Box::new(wa::message::ImageMessage {
        url: Some(upload.url),
        direct_path: Some(upload.direct_path),
        media_key: Some(upload.media_key),
        mimetype: Some("image/jpeg".to_string()),
        file_enc_sha256: Some(upload.file_enc_sha256),
        file_sha256: Some(upload.file_sha256),
        file_length: Some(upload.file_length),
        caption: Some("Caption untuk gambar".to_string()),
        ..Default::default()
    })),
    ..Default::default()
};

// 4. Kirim
client.send_message(chat_jid, message).await?;
```

### Download Media

```rust
use ruwa::download::{Downloadable, MediaType};
use std::io::Cursor;

// Dapatkan message yang punya media
if let Some(image_msg) = &message.image_message {
    // Download ke buffer
    let mut buffer = Cursor::new(Vec::new());
    client.download_to_file(image_msg, &mut buffer).await?;
    
    // Simpan ke file
    let data = buffer.into_inner();
    std::fs::write("downloaded.jpg", &data)?;
    
    println!("Media berhasil didownload: {} bytes", data.len());
}
```

### Upload Video

```rust
let video_data = std::fs::read("video.mp4")?;

let upload = client.upload(video_data, MediaType::Video).await?;

client.send_message(chat_jid, wa::Message {
    video_message: Some(Box::new(wa::message::VideoMessage {
        url: Some(upload.url),
        direct_path: Some(upload.direct_path),
        media_key: Some(upload.media_key),
        mimetype: Some("video/mp4".to_string()),
        file_enc_sha256: Some(upload.file_enc_sha256),
        file_sha256: Some(upload.file_sha256),
        file_length: Some(upload.file_length),
        caption: Some("Video caption".to_string()),
        gif_playback: Some(false),
        ..Default::default()
    })),
    ..Default::default()
}).await?;
```

### Upload Audio/Voice Note

```rust
let audio_data = std::fs::read("audio.ogg")?;

let upload = client.upload(audio_data, MediaType::Audio).await?;

client.send_message(chat_jid, wa::Message {
    audio_message: Some(Box::new(wa::message::AudioMessage {
        url: Some(upload.url),
        direct_path: Some(upload.direct_path),
        media_key: Some(upload.media_key),
        mimetype: Some("audio/ogg; codecs=opus".to_string()),
        file_enc_sha256: Some(upload.file_enc_sha256),
        file_sha256: Some(upload.file_sha256),
        file_length: Some(upload.file_length),
        seconds: Some(30),  // Durasi dalam detik
        ..Default::default()
    })),
    ..Default::default()
}).await?;
```

### Upload Document

```rust
let doc_data = std::fs::read("document.pdf")?;

let upload = client.upload(doc_data, MediaType::Document).await?;

client.send_message(chat_jid, wa::Message {
    document_message: Some(Box::new(wa::message::DocumentMessage {
        url: Some(upload.url),
        direct_path: Some(upload.direct_path),
        media_key: Some(upload.media_key),
        mimetype: Some("application/pdf".to_string()),
        file_enc_sha256: Some(upload.file_enc_sha256),
        file_sha256: Some(upload.file_sha256),
        file_length: Some(upload.file_length),
        title: Some("document.pdf".to_string()),
        caption: Some("Document caption".to_string()),
        ..Default::default()
    })),
    ..Default::default()
}).await?;
```

---

## 👥 Grup Management Detail

### Buat Grup Baru

```rust
use ruwa::features::{Groups, GroupCreateOptions};

let participants = vec![
    "6281234567890@s.whatsapp.net".parse()?,
    "6289876543210@s.whatsapp.net".parse()?,
];

let result = client.groups().create(
    "Nama Grup",
    participants,
    GroupCreateOptions {
        description: Some("Deskripsi grup".to_string()),
        ephemeral: Some(86400),  // 24 jam
        ..Default::default()
    }
).await?;

println!("Grup dibuat: {}", result.jid);
```

### Dapatkan Info Grup

```rust
let metadata = client.groups().get_metadata(group_jid).await?;

println!("Nama: {}", metadata.subject);
println!("Deskripsi: {:?}", metadata.description);
println!("Owner: {}", metadata.owner);
println!("Created: {}", metadata.creation);

// List participants
for participant in &metadata.participants {
    println!("  - {} (Admin: {})", participant.jid, participant.is_admin);
}
```

### Manage Participants

```rust
let groups = client.groups();

// Add participants
groups.add_participants(group_jid, vec![
    "6281234567890@s.whatsapp.net".parse()?,
]).await?;

// Remove participants
groups.remove_participants(group_jid, vec![
    "6289876543210@s.whatsapp.net".parse()?,
]).await?;

// Promote to admin
groups.promote_participants(group_jid, vec![
    "6281234567890@s.whatsapp.net".parse()?,
]).await?;

// Demote admin
groups.demote_participants(group_jid, vec![
    "6289876543210@s.whatsapp.net".parse()?,
]).await?;
```

### Update Group Settings

```rust
let groups = client.groups();

// Update nama
groups.set_subject(group_jid, "Nama Grup Baru").await?;

// Update deskripsi
groups.set_description(group_jid, "Deskripsi baru").await?;

// Set disappearing messages (24 jam)
groups.set_ephemeral(group_jid, Some(86400)).await?;

// Disable disappearing messages
groups.set_ephemeral(group_jid, None).await?;

// Get invite link
let invite_link = groups.get_invite_link(group_jid).await?;
println!("Invite link: {}", invite_link);

// Revoke invite link
groups.revoke_invite_link(group_jid).await?;

// Leave group
groups.leave(group_jid).await?;
```

---

## 📊 Presence & Receipts

### Set Presence

```rust
// Set online
client.presence().set_available(true).await?;

// Set offline
client.presence().set_available(false).await?;

// Subscribe presence kontak
client.presence().subscribe_presence(contact_jid).await?;

// Unsubscribe
client.presence().unsubscribe_presence(contact_jid).await?;
```

### Typing Indicator

```rust
use ruwa::features::{Chatstate, ChatStateType};

// Mulai mengetik
client.chatstate().send_chatstate(
    chat_jid,
    ChatStateType::Composing,
).await?;

// Stop mengetik (auto setelah 3 detik)
client.chatstate().send_chatstate(
    chat_jid,
    ChatStateType::Paused,
).await?;

// Recording audio
client.chatstate().send_chatstate(
    chat_jid,
    ChatStateType::Recording,
).await?;
```

### Handle Receipts

```rust
.on_event(|event, _client| async move {
    if let Event::Receipt(receipt) = event {
        match receipt.r#type {
            // Pesan terkirim ke server
            wa::receipt::Type::Delivery => {
                println!("Pesan {:?} delivered", receipt.message_ids);
            }
            // Pesan sudah dibaca
            wa::receipt::Type::Read => {
                println!("Pesan {:?} read", receipt.message_ids);
            }
            // Audio sudah diputar
            wa::receipt::Type::Played => {
                println!("Audio {:?} played", receipt.message_ids);
            }
            _ => {}
        }
    }
})
```

---

## ⚙️ Advanced Usage

### Custom Event Handler

```rust
use ruwa::bot::Bot;
use std::sync::Arc;

let bot = Bot::builder()
    .with_backend(store)
    .on_event(|event, client| async move {
        match event {
            Event::Message(msg, info) => {
                // Handle message
                tokio::spawn(async move {
                    // Process in background
                });
            }
            _ => {}
        }
    })
    .build()
    .await?;
```

### Multiple Clients

```rust
// Run multiple bots/accounts
let bot1 = Bot::builder()
    .with_backend(SqliteStore::new("account1.db").await?)
    .build()
    .await?;

let bot2 = Bot::builder()
    .with_backend(SqliteStore::new("account2.db").await?)
    .build()
    .await?;

// Run concurrently
tokio::try_join!(bot1.run(), bot2.run())?;
```

### Custom Cache Config

```rust
use ruwa::{CacheConfig, CacheEntryConfig};
use std::time::Duration;

let cache_config = CacheConfig {
    group_cache: CacheEntryConfig::new()
        .with_ttl(Duration::from_secs(3600))
        .with_capacity(1000),
    device_cache: CacheEntryConfig::new()
        .with_ttl(Duration::from_secs(3600))
        .with_capacity(5000),
    ..Default::default()
};

let bot = Bot::builder()
    .with_backend(store)
    .with_cache_config(cache_config)
    .build()
    .await?;
```

---

## 🐛 Troubleshooting

### Build Errors

#### Error: SIMD feature requires nightly

**Problem:**
```
error[E0554]: `#![feature]` may not be used on the stable release channel
```

**Solution:**
Feature SIMD sudah di-disable by default. Pastikan tidak enable SIMD di Cargo.toml:

```toml
# ❌ Jangan enable SIMD
ruwa = { version = "1.0.0", features = ["simd"] }

# ✅ Gunakan default (tanpa SIMD)
ruwa = "1.0.0"
```

#### Error: protoc not found

**Problem:**
```
failed to execute command: protoc: No such file or directory
```

**Solution:**
```bash
# Ubuntu/Debian
sudo apt install protobuf-compiler

# macOS
brew install protobuf

# Verify
protoc --version
```

### Runtime Errors

#### QR Code tidak muncul

**Problem:** Event `PairingQrCode` tidak trigger

**Solution:**
1. Pastikan session lama dihapus: `rm whatsapp.db`
2. Check event handler sudah benar
3. Enable logging: `RUST_LOG=debug cargo run`

#### Connection failed

**Problem:**
```
Error: Connection refused
```

**Solution:**
1. Check internet connection
2. Check firewall tidak block WebSocket
3. Session expired, delete database dan pair ulang

#### Message tidak terkirim

**Problem:** `send_message` return error

**Solution:**
1. Pastikan recipient JID benar: `number@s.whatsapp.net`
2. Check session sudah established (tunggu retry receipt)
3. Untuk grup, pastikan bot masih member

### Performance Issues

#### Memory usage tinggi

**Solution:**
```toml
# Build release untuk optimasi
cargo build --release

# Profile release di Cargo.toml
[profile.release]
opt-level = 3
lto = true
```

#### Slow message processing

**Solution:**
```rust
// Process messages async
.on_event(|event, client| async move {
    if let Event::Message(msg, info) = event {
        let client_clone = client.clone();
        tokio::spawn(async move {
            // Process in background
            process_message(client_clone, msg, info).await;
        });
    }
})
```

---

## ❓ FAQ

<details>
<summary><b>📱 Apakah ini resmi dari WhatsApp?</b></summary>

❌ **TIDAK**. Ini adalah **unofficial library** hasil reverse engineering WhatsApp Web. Penggunaan dapat melanggar ToS WhatsApp.
</details>

<details>
<summary><b>⚠️ Apakah akun bisa di-banned?</b></summary>

⚠️ **YA, ada kemungkinan**. WhatsApp dapat detect client tidak resmi dan melakukan suspend/ban. 

**Tips untuk minimize risk:**
- Jangan spam
- Jangan kirim message massal
- Gunakan delay antar message
- Hanya untuk testing/development
</details>

<details>
<summary><b>💻 Support platform apa saja?</b></summary>

✅ **Support semua platform:**
- Linux
- macOS
- Windows
- Android (via Termux)
</details>

<details>
<summary><b>📦 Berapa ukuran binary?</b></summary>

📊 **Ukuran approximate:**
- Debug build: ~300MB
- Release build: ~50MB (dengan LTO)
</details>

<details>
<summary><b>🔄 Apakah support multi-device?</b></summary>

✅ **Ya**, support hingga 4 perangkat companion (seperti WhatsApp Web linked devices).
</details>

<details>
<summary><b>🤖 Bisa untuk bot WhatsApp?</b></summary>

✅ **Sangat bisa!** Library ini dirancang khusus untuk memudahkan pembuatan bot WhatsApp dengan berbagai fitur lengkap.
</details>

<details>
<summary><b>📚 Apakah ada contoh bot?</b></summary>

✅ Lihat folder `examples/` di repository atau contoh di section [Quick Start](#-quick-start).
</details>

<details>
<summary><b>🐛 Bagaimana cara report bug?</b></summary>

📬 Hubungi developer via kontak di atas atau buat issue di GitHub.
</details>

---

## ⚠️ Disclaimer

> **⚠️ PENTING: Gunakan dengan risiko sendiri!**

### Legal Notice

Library ini adalah **UNOFFICIAL** implementasi WhatsApp Web API. Penggunaan library ini dapat:

- ❌ Melanggar [WhatsApp Terms of Service]https://www.whatsapp.com/legal/terms-of-service
- ❌ Melanggar [WhatsApp Business Policy]https://www.whatsapp.com/legal/business-policy
- ⚠️ Mengakibatkan **suspend** atau **ban** akun WhatsApp Anda

### Recommended Usage

**✅ GUNAKAN HANYA UNTUK:**
- Testing & development
- Educational purposes
- Research
- Personal projects (dengan risiko sendiri)

**❌ JANGAN GUNAKAN UNTUK:**
- Spam atau bulk messaging
- Scam atau fraud
- Aktivitas ilegal
- Pelanggaran privasi orang lain
- Commercial use tanpa izin dari Meta

### No Warranty

Library ini disediakan **"AS IS"** tanpa warranty apapun. Developer tidak bertanggung jawab atas:
- Kerugian yang timbul dari penggunaan
- Suspend/ban akun
- Kehilangan data
- Masalah hukum yang mungkin timbul

---

## 📚 Resources

| Resource | Link |
|----------|------|
| 📖 API Documentation | [docs.rs/ruwa]https://docs.rs/ruwa |
| 💻 Source Code | [github.com/jrevanaldi-ai/ruwa]https://github.com/jrevanaldi-ai/ruwa |
| 📦 Package Registry | [crates.io/crates/ruwa]https://crates.io/crates/ruwa |
| 🐛 Issue Tracker | [GitHub Issues]https://github.com/jrevanaldi-ai/ruwa/issues |
| 💬 Discussions | [GitHub Discussions]https://github.com/jrevanaldi-ai/ruwa/discussions |

---

## 🙏 Acknowledgements

Terima kasih kepada project yang menginspirasi:

- [**whatsmeow**]https://github.com/tulir/whatsmeow - Go WhatsApp library (tulir)
- [**Baileys**]https://github.com/WhiskeySockets/Baileys - TypeScript WhatsApp library
- **WhatsApp Web** - Sebagai referensi protokol

---

<div align="center">

### 📬 Still Have Questions?

[![WhatsApp](https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge&logo=whatsapp&logoColor=white)](https://wa.me/62895416602000)
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/AstraluneSuport)
[![Email](https://img.shields.io/badge/Email-D14836?style=for-the-badge&logo=gmail&logoColor=white)](mailto:support@nathan.christmas)

---

**Copyright © 2026 Nathan**

[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE)

Made with ❤️ using Rust

</div>