16 unstable releases (3 breaking)

0.5.1 Nov 4, 2024
0.4.1 Aug 11, 2024
0.3.5 Jun 17, 2024
0.3.1 Mar 31, 2024
0.1.0 Dec 25, 2023

#353 in Web programming

Download history 7/week @ 2024-08-17 18/week @ 2024-08-31 22/week @ 2024-09-07 22/week @ 2024-09-14 63/week @ 2024-09-21 24/week @ 2024-09-28 15/week @ 2024-10-05 196/week @ 2024-10-12 46/week @ 2024-10-19 38/week @ 2024-10-26 205/week @ 2024-11-02 127/week @ 2024-11-09 110/week @ 2024-11-16 45/week @ 2024-11-23 86/week @ 2024-11-30

387 downloads per month

MIT/Apache

56KB
1.5K SLoC

Expo Push Notification Client for Rust

This is an official Expo Push Notification Client for Rust.

ci crates.io docs.rs license

Client (ReactNative with Expo)

You need to get Expo Push Token from Expo SDK and send it to Expo server first. See docs for more details.

Server (Rust)

Install

cargo add expo_push_notification_client

Usage

use expo_push_notification_client::{Expo, ExpoClientOptions, ExpoPushMessage};

// Initialize Expo client
let expo = Expo::new(ExpoClientOptions {
    access_token: Some(access_token),
});

// Define Expo Push Tokens to send notifications to
let expo_push_tokens = ["ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"];

// Build Expo Push Message with specified tokens
let expo_push_message = ExpoPushMessage::builder(expo_push_tokens).build()?;

// Send push notifications using Expo client
let tickets = expo.send_push_notifications(expo_push_message).await;

// Extract push notification IDs from tickets
let mut expo_push_ids = vec![];
for ticket in tickets {
    match ticket {
        ExpoPushTicket::Ok(ticket) => {
            expo_push_ids.push(ticket.id);
        }
        ExpoPushTicket::Error(e) => {
            // Handle error
        }
    }
}

// Retrieve push notification receipts using Expo client
expo.get_push_notification_receipts(expo_push_ids).await;

Additionally, you can further customize the ExpoPushMessage by adding more options. Refer to the docs for more details.

// Build Expo Push Message with detailed configurations
#[derive(Serialize)]
struct Data {
    data: String,
}

let expo_push_message = ExpoPushMessage::builder(["ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"])
    .body("body")
    .data(&Data { data: "data".to_string()})?
    .ttl(100)
    .expiration(100)
    .priority("high")
    .subtitle("subtitle")
    .sound("default")
    .badge(1)
    .channel_id("channel_id")
    .category_id("category_id")
    .mutable_content(true)
    .title("title")
    .build()?;

Changing TLS Backend

This crate uses Reqwest with its default features. However, you can change tls backend by disabling the default features and enabling the rustls-tls feature, which uses a Rust implementation of TLS. This approach may offer better compatibility across different environments.

expo_push_notification_client = { version = "0.5.0", default-features = false, features = ["rustls-tls"] }

Dependencies

~9–24MB
~349K SLoC