Skip to main content

steam_user/services/
notifications.rs

1//! Notification services.
2
3use crate::{
4    client::SteamUser,
5    endpoint::steam_endpoint,
6    error::SteamUserError,
7    types::{Notifications, notifications::NotificationCountsEnvelope},
8};
9
10impl SteamUser {
11    /// Retrieves the current counts for various Steam notifications.
12    ///
13    /// This includes unread messages, trade offers, new items, and more.
14    ///
15    /// # Returns
16    ///
17    /// Returns a [`Notifications`] struct containing the counts for each type
18    /// of notification.
19    #[steam_endpoint(GET, host = Community, path = "/actions/GetNotificationCounts", kind = Read)]
20    pub async fn get_notifications(&self) -> Result<Notifications, SteamUserError> {
21        // Steam returns `{ "notifications": { "1": n, "2": n, ... } }`.
22        // Deserialize directly into a typed envelope; missing keys default to 0.
23        let envelope: NotificationCountsEnvelope = self.get_path("/actions/GetNotificationCounts").send().await?.json().await?;
24
25        Ok(envelope.notifications.into())
26    }
27}