node-steamcommunity

repository·master·Indexed 20 days ago

https://github.com/doctormckay/node-steamcommunity

A Node.js module providing an interface for logging into and interacting with the Steam Community website. It includes capabilities for managing 2FA, accepting trade or market confirmations, retrieving trade URLs, fetching notifications, and managing friends lists. Version 3.50.3.

Tokens
2.3K
Snippets
10
Records
13
Agent score
69%

What's inside steamcommunity

  1. Accept All Trade or Market Confirmations

    master

    If you have the identity secret for a bot account, you can use the accept_all_confirmations.js script to automatically accept all pending trade or market confirmations. This script must be run locally from the examples directory after cloning the repository and installing dependencies.

    git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
    cd node-steamcommunity
    npm install
    cd examples
    node accept_all_confirmations.js
  2. Enable or Disable Two-Factor Authentication (2FA)

    master

    To manage 2FA on a bot account, use the provided example scripts enable_twofactor.js and disable_twofactor.js. These scripts are intended to be run locally after cloning the repository and installing dependencies. This is useful for automating the setup or removal of 2FA on accounts managed by your bot.

    git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
    cd node-steamcommunity
    npm install
    cd examples
    node enable_twofactor.js
  3. Initialize SteamCommunity

    master

    To use the library, instantiate the SteamCommunity class. You can pass an optional options object to configure the instance. If you pass a string instead of an object, it is treated as the localAddress (used for binding to a specific network interface).

    Supported options:

    • userAgent: A custom User-Agent string. Defaults to a Chrome user agent via @doctormckay/user-agents.
    • timeout: Request timeout in milliseconds. Defaults to 50000.
    • gzip: Boolean to enable/disable gzip. Defaults to true.
    • headers: Custom request headers.
    • localAddress: A string representing the local IP address to bind to.
    • request: A custom request instance (e.g., for custom agents or configurations).
    const SteamCommunity = require('node-steamcommunity');
    
    // Basic initialization
    const community = new SteamCommunity();
    
    // Initialization with options
    const communityWithOptions = new SteamCommunity({
        userAgent: 'MyCustomUserAgent/1.0',
        timeout: 30000,
        localAddress: '127.0.0.1'
    });
  4. Get a Client Logon Token for steam-user

    master

    The getClientLogonToken method retrieves a token that can be used to log onto Steam using the steam-user library. This is useful for bridging web-based community actions with a full Steam client session.

    Callback signature: (err, { steamID, accountName, webLogonToken })

    community.getClientLogonToken((err, data) => {
        if (err) return console.error(err);
        console.log('SteamID:', data.steamID.getSteamID64());
        console.log('Account Name:', data.accountName);
        console.log('Web Logon Token:', data.webLogonToken);
    });
  5. Retrieve Steam Notifications

    master

    The getNotifications method fetches the current count of various Steam notifications.

    Returns an object with the following keys:

    • trades: Trade offers
    • gameTurns: Game turns
    • moderatorMessages: Moderator messages
    • comments: Comments
    • items: Items
    • invites: Invites
    • gifts: Gifts
    • chat: Chat messages
    • helpRequestReplies: Help request replies
    • accountAlerts: Account alerts
    community.getNotifications((err, notifications) => {
        if (err) return console.error(err);
        console.log('New trades:', notifications.trades);
        console.log('New chat messages:', notifications.chat);
    });
  6. Manage Trade URLs

    master

    You can retrieve or change your Steam Trade URL using these methods:

    • getTradeURL(callback): Returns the current trade URL and the associated token.
    • changeTradeURL(callback): Generates a new trade URL and returns both the new URL and the new token.

    Callback for getTradeURL: (err, tradeURL, token) Callback for changeTradeURL: (err, newTradeURL, newToken)

    // Get current URL
    community.getTradeURL((err, url, token) => {
        if (err) return console.error(err);
        console.log('Trade URL:', url);
    });
    
    // Change to a new URL
    community.changeTradeURL((err, newUrl, newToken) => {
        if (err) return console.error(err);
        console.log('New Trade URL:', newUrl);
    });
  7. Log in to SteamCommunity

    master

    Use the login method to authenticate your session. This method performs a modern login and handles session cookies and mobile access tokens.

    Parameters:

    • details: An object containing:
      • accountName: Your Steam username.
      • password: Your Steam password.
      • disableMobile: (Optional) Boolean. Defaults to true. If set to false, it attempts to enable mobile features.
    • callback: A function called with (err, sessionID, cookies, steamguard, mobileAccessToken).

    Note: If mobileAccessToken is returned, you should call setMobileAppAccessToken(mobileAccessToken) to maintain mobile functionality.

    community.login({
        accountName: 'your_username',
        password: 'your_password',
        disableMobile: false
    }, (err, sessionID, cookies, steamguard, mobileAccessToken) => {
        if (err) {
            console.error('Login failed:', err);
            return;
        }
        console.log('Logged in! Session ID:', sessionID);
    });
  8. Get Friends List

    master

    The getFriendsList method retrieves a list of friends. The returned object uses 64-bit SteamIDs as keys and the corresponding EFriendRelationship enum value as the value.

    Returns: An object where { [steamID64]: EFriendRelationship }.

    community.getFriendsList((err, friends) => {
        if (err) return console.error(err);
        // friends is an object: { '76561198xxxxxxx': 1, ... }
        for (const [id, relationship] of Object.entries(friends)) {
            console.log(`Friend ${id} has relationship ${relationship}`);
        }
    });
  9. Check if currently logged in

    master

    The loggedIn method checks the current authentication status by attempting to access the user's profile page. It returns whether the user is logged in and whether the response was a 403 (often indicating a specific type of authenticated state).

    community.loggedIn((err, isLoggedIn, isForbidden) => {
        if (err) return console.error(err);
        console.log('Is logged in:', isLoggedIn);
    });