Crates.io | fcm_rust |
lib.rs | fcm_rust |
version | 0.1.0 |
source | src |
created_at | 2024-06-12 09:29:36.330728 |
updated_at | 2024-06-12 09:29:36.330728 |
description | A Rust crate for easy interaction with Firebase Cloud Messaging API (V1). |
homepage | |
repository | https://github.com/calalalizade/fcm-rs |
max_upload_size | |
id | 1269426 |
size | 10,396 |
This Rust crate provides a convenient way to send notifications using Firebase Cloud Messaging (FCM) API v1. It leverages async/await for asynchronous operations and supports loading service account credentials from a JSON file.
Add this crate to your Cargo.toml
:
[dependencies]
fcm_rust = "0.1.0"
Below is an example of how to use this crate to send a notification:
use fcm_rust::{ client::FcmClient, models::{ Message, Notification } };
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let service_account_path = "path/to/service_account";
let project_id = "your_project_id".to_string();
// Create a new FCM client
let client = FcmClient::new(service_account_path, project_id).await?;
// Define the message with the target device token and notification details
let message = Message {
token: Some("your_device_token".to_string()),
notification: Some(Notification {
title: Some("Hello from Rust!".to_string()),
body: Some("This is a test notification.".to_string()),
}),
data: None,
};
// Send the message and handle the response
let response = client.send(message).await?;
println!("FCM response: {:?}", response);
Ok(())
}
Contributions are welcome! Feel free to submit issues or pull requests.
For any queries or suggestions, please open an issue on the GitHub repository.