use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
#[derive(Debug, Clone, Deserialize)]
pub struct SessionStatus {
pub connected: bool,
pub phone: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct QRCode {
pub qr: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct PairPhoneResult {
pub pair_code: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct MessageResponse {
#[serde(rename = "messageId")]
pub message_id: String,
pub id: String,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendTextParams {
pub to: String,
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub quoted: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mentions: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendImageParams {
pub to: String,
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quoted: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendAudioParams {
pub to: String,
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub ptt: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendVideoParams {
pub to: String,
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quoted: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendDocumentParams {
pub to: String,
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub filename: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendLocationParams {
pub to: String,
pub latitude: f64,
pub longitude: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub address: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendContactParams {
pub to: String,
pub contact_name: String,
pub contact_number: String,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendStickerParams {
pub to: String,
pub url: String,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendPollParams {
pub to: String,
pub question: String,
pub options: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub multiple_answers: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct SendReactionParams {
pub to: String,
pub message_id: String,
pub emoji: String,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct MarkReadParams {
pub chat_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_message_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct PresenceParams {
pub chat_id: String,
pub presence: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Event {
pub event: String,
pub session_id: String,
#[serde(default)]
pub session_metadata: std::collections::HashMap<String, String>,
pub data: Box<RawValue>,
pub timestamp: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct IncomingMessage {
pub id: String,
pub chat: String,
pub from: String,
pub from_me: bool,
#[serde(rename = "type")]
pub msg_type: String,
pub text: Option<String>,
pub caption: Option<String>,
pub media_url: Option<String>,
pub mimetype: Option<String>,
pub filename: Option<String>,
pub latitude: Option<f64>,
pub longitude: Option<f64>,
pub timestamp: i64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DisconnectReason {
Transient,
Manual,
Paused,
LoggedOut,
Replaced,
TemporaryBan,
ClientOutdated,
ConnectFailure,
Unknown(String),
}
impl DisconnectReason {
pub const KNOWN: [DisconnectReason; 8] = [
DisconnectReason::Transient,
DisconnectReason::Manual,
DisconnectReason::Paused,
DisconnectReason::LoggedOut,
DisconnectReason::Replaced,
DisconnectReason::TemporaryBan,
DisconnectReason::ClientOutdated,
DisconnectReason::ConnectFailure,
];
pub fn as_str(&self) -> &str {
match self {
Self::Transient => "transient",
Self::Manual => "manual",
Self::Paused => "paused",
Self::LoggedOut => "logged_out",
Self::Replaced => "replaced",
Self::TemporaryBan => "temporary_ban",
Self::ClientOutdated => "client_outdated",
Self::ConnectFailure => "connect_failure",
Self::Unknown(other) => other,
}
}
pub fn is_known(&self) -> bool {
!matches!(self, Self::Unknown(_))
}
}
impl<'de> Deserialize<'de> for DisconnectReason {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let raw = String::deserialize(d)?;
Ok(match raw.as_str() {
"transient" => Self::Transient,
"manual" => Self::Manual,
"paused" => Self::Paused,
"logged_out" => Self::LoggedOut,
"replaced" => Self::Replaced,
"temporary_ban" => Self::TemporaryBan,
"client_outdated" => Self::ClientOutdated,
"connect_failure" => Self::ConnectFailure,
_ => Self::Unknown(raw),
})
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct Disconnected {
pub reason: DisconnectReason,
#[serde(rename = "willReconnect")]
pub will_reconnect: bool,
pub resume: Option<String>,
pub code: Option<i64>,
pub detail: Option<String>,
#[serde(rename = "expireSeconds")]
pub expire_seconds: Option<i64>,
#[serde(rename = "retryAfterSeconds")]
pub retry_after_seconds: Option<i64>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PairingMethod {
Qr,
Code,
Unknown(String),
}
impl PairingMethod {
pub fn as_str(&self) -> &str {
match self {
Self::Qr => "qr",
Self::Code => "code",
Self::Unknown(other) => other,
}
}
}
impl<'de> Deserialize<'de> for PairingMethod {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let raw = String::deserialize(d)?;
Ok(match raw.as_str() {
"qr" => Self::Qr,
"code" => Self::Code,
_ => Self::Unknown(raw),
})
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PairingFailureReason {
Timeout,
Rejected,
Cancelled,
ClientOutdated,
Error,
Unknown(String),
}
impl PairingFailureReason {
pub const KNOWN: [PairingFailureReason; 5] = [
PairingFailureReason::Timeout,
PairingFailureReason::Rejected,
PairingFailureReason::Cancelled,
PairingFailureReason::ClientOutdated,
PairingFailureReason::Error,
];
pub fn as_str(&self) -> &str {
match self {
Self::Timeout => "timeout",
Self::Rejected => "rejected",
Self::Cancelled => "cancelled",
Self::ClientOutdated => "client_outdated",
Self::Error => "error",
Self::Unknown(other) => other,
}
}
pub fn is_known(&self) -> bool {
!matches!(self, Self::Unknown(_))
}
}
impl<'de> Deserialize<'de> for PairingFailureReason {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let raw = String::deserialize(d)?;
Ok(match raw.as_str() {
"timeout" => Self::Timeout,
"rejected" => Self::Rejected,
"cancelled" => Self::Cancelled,
"client_outdated" => Self::ClientOutdated,
"error" => Self::Error,
_ => Self::Unknown(raw),
})
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct PairingFailed {
pub method: PairingMethod,
pub reason: PairingFailureReason,
pub at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct PairingSucceeded {
pub method: PairingMethod,
pub at: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ReceiptStatus {
Delivered,
Read,
Played,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Receipt {
pub status: Option<ReceiptStatus>,
#[serde(rename = "rawType")]
pub raw_type: String,
#[serde(rename = "type")]
pub receipt_type: String,
pub chat: String,
pub sender: String,
#[serde(rename = "messageIds")]
pub message_ids: Vec<String>,
pub timestamp: i64,
#[serde(rename = "isFromMe")]
pub is_from_me: bool,
#[serde(rename = "messageFromMe")]
pub message_from_me: bool,
#[serde(rename = "messageSender")]
pub message_sender: Option<String>,
}