aboutsummaryrefslogblamecommitdiffstats
path: root/filamento/examples/example.rs
blob: b1ab6ceea38f84b6fa58f40163779947a74f614a (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                    
                                                                        











                                                                                  
                                                      











                                                  
use std::{path::Path, str::FromStr, time::Duration};

use filamento::{Client, db::Db};
use jid::JID;
use tracing::info;

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();
    let db = Db::create_connect_and_migrate(Path::new("./filamento.db"))
        .await
        .unwrap();
    let (client, mut recv) =
        Client::new("test@blos.sm".try_into().unwrap(), "slayed".to_string(), db);

    tokio::spawn(async move {
        while let Some(msg) = recv.recv().await {
            info!("{:#?}", msg)
        }
    });

    client.connect().await.unwrap();
    tokio::time::sleep(Duration::from_secs(15)).await;
    info!("sending message");
    client
        .send_message(
            JID::from_str("cel@blos.sm").unwrap(),
            filamento::chat::Body {
                body: "hallo!!!".to_string(),
            },
        )
        .await
        .unwrap();
    println!("sent message");
}