-
Posts
22 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
dawe's Achievements
-
Hi, it's still happening. The inventory is public.
-
Thank you. How do I refresh the session as I'm not using an account?
-
dawe started following AccessDenied when trying to get status of a trade , 401 after a while of getting inventory , HTTP error 403 when trying to relog after session expires and 3 others
-
I get this: Error retrieving inventory: Error: HTTP error 401 after a couple of days of running my script. It works for a while then it crashes with that error code. Below is the complete code: Edit: To clarify, it gets the inventory no problem then just stops working. const express = require('express'); const SteamCommunity = require('steamcommunity'); // Assuming you're using steamcommunity package const app = express(); const community = new SteamCommunity(); const axios = require('axios'); // Import axios for making HTTP requests // Define appIDs for different games const APP_IDS = { csgo: 730, // CS:GO rust: 252490 // Rust }; // Route to fetch inventory app.get('/inventory/:steamID/:game', async (req, res) => { const steamID = req.params.steamID; const game = req.params.game.toLowerCase(); // Get the game from the URL parameter const appID = APP_IDS[game]; // Get app ID from the predefined APP_IDS object const contextID = game === 'csgo' ? 2 : 2; // Context ID for CS:GO is 2, Rust is 6 if (!appID) { return res.status(400).json({ error: "Invalid game specified. Please use 'csgo' or 'rust'." }); } try { // Get the inventory for the requested steamID and appID const inventory = await new Promise((resolve, reject) => { community.getUserInventoryContents(steamID, appID, contextID, true, (err, inventory) => { if (err) { return reject(err); // Reject the promise with the error } resolve(inventory); // Resolve the promise with the inventory }); }); // Return the inventory as a JSON response res.json({ steamID, appID, inventory }); } catch (err) { console.error('Error retrieving inventory:', err); res.status(500).json({ error: "Error retrieving inventory", details: err.message }); } }); // Route to fetch sales history from Skinport app.get('/sales-history/:appID/:currency', async (req, res) => { const { appID, currency } = req.params; try { // Make a request to the Skinport API to get sales history const response = await axios.get('https://api.skinport.com/v1/sales/history', { params: { app_id: appID, currency: currency } }); // Return the sales history data from Skinport as JSON res.json(response.data); } catch (err) { console.error('Error retrieving sales history:', err); res.status(500).json({ error: "Error retrieving sales history", details: err.message }); } }); // Start the Express server const PORT = 2001; // Set the port app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });
-
const SteamUser = require('steam-user'); const SteamCommunity = require('steamcommunity'); const TradeOfferManager = require('steam-tradeoffer-manager'); const allowedSteamID = "blabla"; const SteamTotp = require('steam-totp'); // Import the steam-totp package const webhooklink = "link" const https = require('https'); class SteamBot { constructor(logOnOptions) { const self = this; // Store the reference to 'this' this.isLoggingIn = false; // Initialize the flag to indicate log-in status this.client = new SteamUser(); this.community = new SteamCommunity(); this.manager = new TradeOfferManager({ steam: this.client, community: this.community, language: 'en', pollInterval: 30000, useAccessToken: true }); this.client.setOption('autoRelogin', true); if (logOnOptions.sharedSecret) { const twoFactorCode = SteamTotp.getAuthCode(logOnOptions.sharedSecret); logOnOptions.twoFactorCode = twoFactorCode; // Include 2FA code in logOnOptions } this.client.logOn(logOnOptions); this.isLoggingIn = true; // Set the flag to true on first login attempt this.client.on('loggedOn', () => { console.log('Logged into Steam'); this.isLoggingIn = false; // Reset flag after successful login this.client.setPersona(SteamUser.EPersonaState.Online); }); this.client.on('friendRelationship', (steamID, relationship) => { // Check if we received a friend request if (relationship === SteamUser.Steam.EFriendRelationship.RequestRecipient) { console.log(`Accepting friend request from ${steamID.getSteam3RenderedID()}`); client.addFriend(steamID); // Automatically accept the friend request } }); this.client.on('webSession', (sessionID, cookies) => { this.manager.setCookies(cookies, (err) => { if (err) { console.error('Error setting cookies for TradeOfferManager:', err); } else { console.log('Cookies set for TradeOfferManager'); } }); this.community.setCookies(cookies); this.community.startConfirmationChecker(10000, '='); }); this.community.on("sessionExpired", async function (err) { if (err) { console.log('Session Expired: ' + err); } if (!self.isLoggingIn) { self.isLoggingIn = true; // Prevent concurrent logins // Check if the bot is connected to the Steam network if (self.client.steamID) { // Checks if logged on self.client.webLogOn(); console.log('called weblogon'); } else { console.log('Bot is not connected to the Steam network. Cannot call webLogOn.'); const lop = { accountName: "", // Replace with your Steam account name password: "#", // Replace with your Steam password sharedSecret: "=" // Optional: Only if your account has 2FA enabled }; // Check if 2FA is needed, generate the 2FA code if `sharedSecret` is provided if (lop.sharedSecret) { const twoFactorCode = SteamTotp.getAuthCode(lop.sharedSecret); lop.twoFactorCode = twoFactorCode; // Include 2FA code in logOnOptions } // Attempt to log in with the provided credentials self.client.logOn(lop); self.client.once('loggedOn', () => { self.isLoggingIn = false; // Reset flag after successful re-login }); self.client.on('error', (error) => { console.error("Login error:", error.message); // Send POST request to the Discord webhook if login fails const webhookUrl = "link"; const errorMessage = `Steam Bot Login Error: ${error.message}`; // Prepare the message payload for Discord const data = JSON.stringify({ content: errorMessage }); // Parse the webhook URL const url = new URL(webhookUrl); const options = { hostname: url.hostname, path: url.pathname + url.search, method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': data.length } }; // Send HTTPS request to Discord webhook const req = https.request(options, (res) => { console.log(`Discord webhook responded with status: ${res.statusCode}`); }); req.on('error', (e) => { console.error(`Problem with Discord webhook request: ${e.message}`); }); req.write(data); // Write data to request body req.end(); }); } } }); this.client.on('loginKey', (key) => { logOnOptions.loginKey = key; // Store login key for future logins console.log('Login key saved for future logins:', key); }); this.manager.on('newOffer', (offer) => { console.log('Incoming trade offer received'); // Log when a new offer is received if (offer.partner.getSteamID64() === allowedSteamID) { offer.accept((err, status) => { if (err) { console.error(`Unable to accept offer: ${err.message}`); } else { console.log(`Offer accepted: ${status}`); } }); } else { console.log(`Offer from unauthorized Steam ID: ${offer.partner.getSteamID64()}`); } }); } sendDepositTrade(assetIds, unique_code, tradeLink, steamID, callback) { //const { partner, token } = this.manager.getPartnerAndToken(tradeLink); const urlParams = new URLSearchParams(new URL(tradeLink).search); const partner = urlParams.get('partner'); // Extract the partner SteamID from the URL const token = urlParams.get('token'); // Extract the token from the URL const offer = this.manager.createOffer(tradeLink); this.manager.getUserInventoryContents(steamID, 730, 2, true, (err, inv) => { if (err) { console.log('Error fetching user inventory:', err); callback(err, false); // Invoke the callback with the error } else { const itemsToAdd = inv.filter((item) => { const itemAssetId = String(item.assetid); return assetIds && assetIds.includes(itemAssetId); }); if (itemsToAdd.length > 0) { //console.log('Items found in inventory matching assetIds:', itemsToAdd); itemsToAdd.forEach((item) => { offer.addTheirItem(item); //console.log("Added item to trade offer:", item); }); offer.setMessage(`Acceptera för omedelbar utbetalning via Swish. Verifieringskoden är: ${unique_code}`); offer.send((err, status) => { console.log("offer status " + status); if (err) { console.error('Error sending trade offer:', err); callback(err, false, offer); // Invoke the callback with the error } else { callback(null, true, offer.id); // Trade sent successfully } }); } } }); } } module.exports = SteamBot; With this code I get Session Expired: Error: HTTP error 403 upon session expiry
-
Thank you for your help, much appreciated. Would this work: this.community.on("sessionExpired", async function (err) { if (err) { console.log('Session Expired: ' + err); } self.client.webLogOn(); console.log('called weblogon'); });
-
Ok then I may be in the wrong subforum. The symptom is that the Steam bot gets logged out because the session expires and can't send trades anymore after about 15 hours.
-
What happens is the session expires
-
Steam client
-
Logged into steam
-
Hello! How do I keep the bot logged in? It logs out after a while. Do I just use this: this.client.setOption('autoRelogin', true); Appearently you should use webLogOn() in the code, but how?
-
Hello! How do I get the sticker image url from its name programmatically?
-
Edit: The solution was to add "useAccessToken: true" in TradeOfferManager constructor
-
const checkTradeStatus = (socket, tradeOfferId, steamID) => { const CHECK_INTERVAL = 10000; // 10 seconds const TIMEOUT_DURATION = 300000; // 5 minutes in milliseconds const startTime = Date.now(); const interval = setInterval(() => { bot.manager.getOffer(tradeOfferId, (err, tradeOffer) => { if (err) { console.error('Error fetching trade offer:', err.message); socket.emit("failure", `Error: ${err.message}`); clearInterval(interval); // Stop checking on error return; } if (!tradeOffer) { console.error('Trade offer is undefined'); socket.emit("failure", 'Trade offer is undefined'); clearInterval(interval); // Stop checking if trade offer is undefined return; } const tradeOfferState = tradeOffer.state; const itemsToGive = tradeOffer.itemsToGive || []; const assetIdsToGive = itemsToGive.map(item => item.assetid); if (tradeOfferState === TradeOfferManager.ETradeOfferState.Accepted) { console.log("Trade is completed!"); socket.emit("success", assetIdsToGive); clearInterval(interval); // Stop checking once trade is complete fetchTrade(assetIdsToGive, steamID); } else if (tradeOfferState !== TradeOfferManager.ETradeOfferState.Active) { console.log("Trade failed with state:", tradeOfferState); socket.emit('failure', { message: 'Trade failed or is in an unexpected state.', tradeOfferState }); clearInterval(interval); // Stop checking if trade fails } else { console.log(`Trade offer ${tradeOfferId} is still active.`); } // Check if the timeout has been reached if (Date.now() - startTime > TIMEOUT_DURATION) { console.log('Timeout reached while waiting for trade offer to complete.'); socket.emit('failure', 'Timeout reached while waiting for trade offer to complete.'); clearInterval(interval); // Stop checking after timeout } }); }, CHECK_INTERVAL); }; class SteamBot { constructor(logOnOptions) { this.client = new SteamUser(); this.community = new SteamCommunity(); this.manager = new TradeOfferManager({ steam: this.client, community: this.community, language: 'en', pollInterval: 30000 }); this.client.logOn(logOnOptions); this.client.on('loggedOn', () => { console.log('Logged into Steam'); this.client.setPersona(SteamUser.EPersonaState.Online); }); this.client.on('webSession', (sessionID, cookies) => { this.manager.setCookies(cookies, (err) => { if (err) { console.error('Error setting cookies for TradeOfferManager:', err); } else { console.log('Cookies set for TradeOfferManager'); } }); this.community.setCookies(cookies); this.community.startConfirmationChecker(10000, 'placeholder'); }); this.manager.on('newOffer', (offer) => { console.log('Incoming trade offer received'); // Log when a new offer is received if (offer.partner.getSteamID64() === allowedSteamID) { offer.accept((err, status) => { if (err) { console.error(`Unable to accept offer: ${err.message}`); } else { console.log(`Offer accepted: ${status}`); } }); } else { console.log(`Offer from unauthorized Steam ID: ${offer.partner.getSteamID64()}`); } }); } sendDepositTrade(partner, assetIds, callback) { const offer = this.manager.createOffer(partner); this.manager.getUserInventoryContents(partner, 730, 2, true, (err, inv) => { if (err) { console.log('Error fetching user inventory:', err); callback(err, false); // Invoke the callback with the error } else { const itemsToAdd = inv.filter((item) => { const itemAssetId = String(item.assetid); return assetIds && assetIds.includes(itemAssetId); }); if (itemsToAdd.length > 0) { console.log('Items found in inventory matching assetIds:', itemsToAdd); itemsToAdd.forEach((item) => { offer.addTheirItem(item); console.log("Added item to trade offer:", item); }); offer.setMessage('Acceptera för omedelbar utbetalning via Swish'); offer.send((err, status) => { console.log("offer status " + status); if (err) { console.error('Error sending trade offer:', err); callback(err, false, offer); // Invoke the callback with the error } else { callback(null, true, offer.id); // Trade sent successfully } }); } } }); } } module.exports = SteamBot;
-
Hello! The data you get from the endpoint is this: "{ response: {} } " even with correct steam API key and trade offer ID. Is there a new endpoint? How else can I check the status of a trade offer? Help would very much be appreciated.