use sfr_types as st;
pub use st::ChatPostMessageResponse;
use crate::{Client, Request};
#[derive(Debug)]
pub struct ChatPostMessage(st::ChatPostMessageRequest);
const API_CODE: &str = "chat.postMessage";
impl ChatPostMessage {
async fn request_inner(&self, client: &Client) -> Result<ChatPostMessageResponse, st::Error> {
#[allow(clippy::missing_docs_in_private_items)] const URL: &str = "https://slack.com/api/chat.postMessage";
let response = client
.client()
.post(URL)
.bearer_auth(client.token())
.json(&self.0)
.send()
.await
.map_err(|e| st::Error::failed_to_request_by_http(API_CODE, e))?;
tracing::debug!("response = {response:?}");
let body: serde_json::Value = response
.json()
.await
.map_err(|e| st::Error::failed_to_read_json(API_CODE, e))?;
tracing::debug!("body = {body:?}");
body.try_into()
}
}
impl From<st::ChatPostMessageRequest> for ChatPostMessage {
fn from(inner: st::ChatPostMessageRequest) -> Self {
Self(inner)
}
}
impl Request for ChatPostMessage {
type Response = ChatPostMessageResponse;
async fn request(self, client: &Client) -> Result<Self::Response, st::Error> {
self.request_inner(client).await
}
}