#![allow(clippy::print_stdout)]
use std::env;
use blooio::{Client, Error};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(env::var("BLOOIO_API_KEY").unwrap_or_else(|_| "sk_demo_key".into()))?;
let chat = client.chat(env::var("CHAT_ID").unwrap_or_else(|_| "chat_demo".into()));
match chat.send_text("hello").await {
Ok(resp) => println!("delivered: {:?}", resp.ids()),
Err(Error::Api {
status,
code,
message,
..
}) => match code.as_deref() {
Some("outbound_limit_reached") => {
println!("rate limited — back off and retry later");
}
Some("invalid_chat") => println!("that chat id doesn't exist"),
_ => println!("api error {status}: {message}"),
},
Err(Error::Transport(e)) => println!("transport failure (retryable): {e}"),
Err(Error::Decode(e)) => println!("could not decode response: {e}"),
Err(other) => println!("unexpected error: {other}"),
}
if let Err(e) = client.account().get().await {
println!("status={:?} code={:?}", e.status(), e.code());
}
Ok(())
}