use serde_json::Value;
use crate::client::{encode_path_segment, Client};
use crate::error::Error;
use crate::types::{GetMessagesParams, ListConversationsParams, ReplyParams};
#[derive(Debug, Clone, Copy)]
pub struct Inbox<'a> {
pub(crate) client: &'a Client,
}
impl Inbox<'_> {
pub async fn list_conversations(
&self,
params: ListConversationsParams,
) -> Result<Value, Error> {
let mut query = Vec::new();
if let Some(platform) = params.platform {
query.push(("platform", platform));
}
if let Some(r#type) = params.r#type {
query.push(("type", r#type));
}
if let Some(unread) = params.unread {
query.push(("unread", unread.to_string()));
}
if let Some(limit) = params.limit {
query.push(("limit", limit.to_string()));
}
if let Some(cursor) = params.cursor {
query.push(("cursor", cursor));
}
self.client.get("/inbox/conversations", query).await
}
pub async fn get_messages(
&self,
conversation_id: &str,
params: GetMessagesParams,
) -> Result<Value, Error> {
let mut query = Vec::new();
if let Some(limit) = params.limit {
query.push(("limit", limit.to_string()));
}
if let Some(cursor) = params.cursor {
query.push(("cursor", cursor));
}
self.client
.get(
&format!(
"/inbox/conversations/{}/messages",
encode_path_segment(conversation_id)
),
query,
)
.await
}
pub async fn mark_read(&self, conversation_id: &str) -> Result<Value, Error> {
self.client
.post_empty(&format!(
"/inbox/conversations/{}/read",
encode_path_segment(conversation_id)
))
.await
}
pub async fn reply(
&self,
conversation_id: &str,
params: ReplyParams,
) -> Result<Value, Error> {
self.client
.post_json(
&format!(
"/inbox/conversations/{}/reply",
encode_path_segment(conversation_id)
),
¶ms,
)
.await
}
}