This fork is a rewrite to use Google's HTTP v1 API.
Add the following to your Cargo.toml
file:
[dependencies]
fcm = { git = "https://github.com/rj76/fcm-rust.git" }
Then, you need to add the credentials described in the Credentials to a .env
file at the root of your project.
For a complete usage example, you may check the Examples section.
use fcm;
let client = fcm::Client::new();
let message = fcm::Message {
data: None,
notification: Some(Notification {
title: Some("I'm high".to_string()),
body: Some(format!("it's {}", chrono::Utc::now())),
..Default::default()
}),
target: Target::Token(device_token),
fcm_options: Some(FcmOptions {
analytics_label: "analytics_label".to_string(),
}),
android: Some(AndroidConfig {
priority: Some(fcm::AndroidMessagePriority::High),
notification: Some(AndroidNotification {
title: Some("I'm Android high".to_string()),
body: Some(format!("Hi Android, it's {}", chrono::Utc::now())),
..Default::default()
}),
..Default::default()
}),
apns: Some(ApnsConfig { ..Default::default() }),
webpush: Some(WebpushConfig { ..Default::default() }),
}
let response = client.send(message).await?;
This library expects the Google credentials JSON location to be
defined as GOOGLE_APPLICATION_CREDENTIALS
in the .env
file.
Please follow the instructions in the Firebase Documentation to create a service account.
For a complete usage example, you may check out the simple_sender
example.
To run the example, first of all clone the .env.example
file to .env
and fill in the required values.
You can find info about the required credentials in the Credentials section.
Then run the example with cargo run --example simple_sender -- -t <device_token>