9 releases

0.4.0 Dec 14, 2023
0.3.3 May 2, 2023
0.3.2 Dec 9, 2022
0.3.1 Nov 23, 2022
0.1.2 Nov 10, 2022

#7 in #client-send

Download history 30/week @ 2023-12-13 28/week @ 2023-12-20 64/week @ 2023-12-27 42/week @ 2024-01-03 3/week @ 2024-01-17 23/week @ 2024-01-24 30/week @ 2024-01-31 26/week @ 2024-02-07 51/week @ 2024-02-14 28/week @ 2024-02-21 28/week @ 2024-02-28 33/week @ 2024-03-06 24/week @ 2024-03-13 60/week @ 2024-03-20 10/week @ 2024-03-27

132 downloads per month
Used in cln-ntfy

MIT license

19KB
461 lines

Ntfy SDK

crates.io Documentation MIT

Description

Ntfy client library to send notifications from Rust.

Example

chrono = "0.4"
ntfy = "0.4"
tokio = { version = "1", features = ["full"] }
url = "2"
use chrono::{Duration, Local};
use ntfy::payload::{Action, ActionType};
use ntfy::{Auth, Dispatcher, NtfyError, Payload, Priority};
use url::Url;

#[tokio::main]
async fn main() -> Result<(), NtfyError> {
    let dispatcher = Dispatcher::builder("https://ntfy.sh")
        .credentials(Auth::new("username", "password")) // Add optional credentials
        .proxy("socks5h://127.0.0.1:9050") // Add optional proxy
        .build()?; // Build dispatcher

    let action = Action::new(
        ActionType::Http,
        "Turn down",
        Url::parse("https://api.nest.com")?,
    );

    let payload = Payload::new("mytopic")
        .message("Hello, **World**!") // Add optional message
        .title("Alert") // Add optiona title
        .tags(vec!["warning".into()]) // Add optional tags
        .priority(Priority::High) // Edit priority
        .actions([action]) // Add optional actions
        .click(Url::parse("https://example.com")?) // Add optional clickable url
        .attach(Url::parse("https://example.com/file.jpg")?) // Add optional url attachment
        .delay(Local::now() + Duration::minutes(1)) // Add optional delay
        .markdown(true); // Use markdown

    dispatcher.send(&payload).await.unwrap();

    Ok(())
}

More examples can be found in the examples directory.

Crate Feature Flags

The following crate feature flags are available:

Feature Default Description
blocking No Needed if you want to use this library in not async/await context

License

This project is distributed under the MIT software license - see the LICENSE file for details

Donations

⚡ Tips: https://getalby.com/p/yuki

⚡ Lightning Address: yuki@getalby.com

Dependencies

~5–20MB
~280K SLoC