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
//! Typing Indicators API
use crate::client::Client;
use crate::error::Result;
use crate::types::SuccessResponse;
use serde::Serialize;
/// Typing Indicators API client
pub struct TypingApi {
client: Client,
}
impl TypingApi {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
/// Show typing indicator to a user
///
/// The typing indicator will be shown for approximately 25 seconds
/// or until a message is sent, whichever comes first.
///
/// # Arguments
///
/// * `to` - Recipient's phone number
///
/// # Example
///
/// ```rust,no_run
/// # use whatsapp_cloud_api::Client;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("token", "phone_id");
///
/// // Show typing indicator
/// client.typing().show("628123456789").await?;
///
/// // Do some processing...
///
/// // Send message (this will clear the typing indicator)
/// client.messages().send_text("628123456789", "Hello!").await?;
/// # Ok(())
/// # }
/// ```
pub async fn show(&self, to: &str) -> Result<SuccessResponse> {
let body = TypingIndicatorRequest {
messaging_product: "whatsapp".to_string(),
recipient_type: "individual".to_string(),
to: to.to_string(),
status: "typing".to_string(),
};
let url = format!("{}/messages", self.client.base_url());
self.client.post(&url, &body).await
}
}
#[derive(Debug, Serialize)]
struct TypingIndicatorRequest {
messaging_product: String,
recipient_type: String,
to: String,
status: String,
}