Jump to content


Photo

Create trade offers

node.js node-steam-tradeoffer-manager

  • Please log in to reply
5 replies to this topic

#1 TextDynasty

TextDynasty

    Advanced Member

  • Member
  • PipPipPip
  • 139 posts

Posted 05 February 2019 - 08:58 PM

C:\Users\lokin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:255
                throw new Error("Missing appid, contextid, or assetid parameter");
                ^

Error: Missing appid, contextid, or assetid parameter
    at addItem (C:\Users\lokin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:255:9)
    at TradeOffer.addMyItem (C:\Users\lokin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:167:9)
    at C:\Users\lokin\OneDrive\New folder\bot.js:48:23
    at SteamCommunity.<anonymous> (C:\Users\lokin\node_modules\steamcommunity\components\users.js:384:5)
    at Request._callback (C:\Users\lokin\node_modules\steamcommunity\components\http.js:67:15)
    at Request.self.callback (C:\Users\lokin\node_modules\request\request.js:185:22)
    at Request.emit (events.js:182:13)
    at Request.<anonymous> (C:\Users\lokin\node_modules\request\request.js:1161:10)
    at Request.emit (events.js:182:13)
    at Gunzip.<anonymous> (C:\Users\lokin\node_modules\request\request.js:1083:12) 

Error ^^

 

I found some examples of creating trade offers on steam but I don't quite understand how to do it.

 

I would like to first differentiate the refined metal from the TF2 inventory and send a certain number (eg 5 refined metal) to the owner when it has more than 5 in its backpack.

const SteamUser = require('steam-user');
const SteamCommunity = require('steamcommunity');
const SteamTotp = require('steam-totp');
const TradeOfferManager = require('steam-tradeoffer-manager');
const config = require('./config');

let client = new SteamUser();
let manager = new TradeOfferManager({
	"steam": client, // Polling every 30 seconds is fine since we get notifications from Steam
	"domain": "example.com", // Our domain is example.com
	"language": "en" // We want English item descriptions
});
let community = new SteamCommunity();

// Steam logon options
let logOnOptions = {
	"accountName": config.accountName,
	"password": config.password,
	"twoFactorCode": SteamTotp.getAuthCode(config.shared_secret)
};

client.logOn(logOnOptions);

client.on('loggedOn', function() {
	console.log("Logged into Steam");
});

client.on('webSession', function(sessionID, cookies) {
	manager.setCookies(cookies, function() {
		manager.loadInventory(440, 2, true, function(err, inventory) {
			if (err) {
				console.log(err);
				return;
            }
            console.log("Found " + inventory.length + " Team Fortress 2 items");
            console.log(inventory);
            var ref = 0;
            for (var i = 0; i < inventory.length; i++){
                if(inventory[i].market_hash_name == 'Refined Metal'){
                    ref++
                    var metal = inventory[i].assetid;
                }
            }
            console.log(metal);
            if(ref >= 5){ //I want to send 5 metal when the bot backpack has enough metal in its backpack
                console.log('We have enough refined metal. Sending the trade');
                let offer = manager.createOffer(config.bossID);
                offer.addMyItem(metal);
                offer.send(function(err, status) {
                    if (err) {
                        console.log(err);
                        return;
                    }

                    if (status == 'pending') {
                        console.log(`Offer #${offer.id} sent, but requires confirmation`);
                        community.acceptConfirmationForObject(config.identity_secret, offer.id, function(err) {
                            if (err) {
                                console.log(err);
                            } else {
                                console.log("Offer confirmed");
                            }
                        });
                    } else {
                        console.log(`Offer #${offer.id} sent successfully`);
                    }
                });
            }
		});
	});
	community.setCookies(cookies);
});

  • Charlie-81 likes this

#2 Charlie-81

Charlie-81

    Newbie

  • Member
  • Pip
  • 3 posts

Posted 05 February 2019 - 09:03 PM

nice


Edited by Charlie-81, 05 February 2019 - 09:04 PM.


#3 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,944 posts

Posted 05 February 2019 - 11:37 PM

You should call addMyItem on the entire item object from the inventory, not just on the assetid. Otherwise, Steam has no idea what game you want to trade items from.



#4 TextDynasty

TextDynasty

    Advanced Member

  • Member
  • PipPipPip
  • 139 posts

Posted 07 February 2019 - 07:00 PM

You should call addMyItem on the entire item object from the inventory, not just on the assetid. Otherwise, Steam has no idea what game you want to trade items from.

 

I modified the code a bit but it always sends me all its refined metal. How can I prevent this and only send a certain amount of metal?

function sendref() {
    manager.loadInventory(440, 2, true, function (err, inventory){
        if (err) {
            console.log(err);
        } else {
            // I need to send 5 ref
            var volume = 5;
            // Filter out all the ref
            var ref = inventory.filter(function (item) {
                return item.market_hash_name.match('Refined Metal')
            });

            // Let the user know we don't have enough ref
            if (ref.length < volume) {
                console.log('Not enough ref');
                return true; // Give up
            }            
            
            // Start a new trade offer
            var offer = manager.createOffer(config.bossID);
 
            // Add what we should to the current trade
            console.log('Adding '+ref.length+' metal');
            offer.addMyItems(ref);
 
            // Send the offer
            offer.send(function (err, status){
                if (err) {
                    console.log(err);
                } else if (status == 'pending'){
                    community.acceptConfirmationForObject(config.identity_secret, offer.id, function(err) {
                        if (err) {
                            console.log(err);
                        } else {
                            console.log("Offer confirmed");
                        }
                    });
                } else {
                    console.log('Trade offer sent successfully');
                }
            });
        }
    });
}


#5 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,944 posts

Posted 07 February 2019 - 07:50 PM

inventory.filter is always going to return every item that matches the filter. If you only want to send some specific amount of metal, you should use slice, for example offer.addMyItems(ref.slice(0, 3)) to send 3.



#6 TextDynasty

TextDynasty

    Advanced Member

  • Member
  • PipPipPip
  • 139 posts

Posted 07 February 2019 - 08:07 PM

inventory.filter is always going to return every item that matches the filter. If you only want to send some specific amount of metal, you should use slice, for example offer.addMyItems(ref.slice(0, 3)) to send 3.

Thanks that solved it

const SteamUser = require('steam-user');
const SteamCommunity = require('steamcommunity');
const SteamTotp = require('steam-totp');
const TradeOfferManager = require('steam-tradeoffer-manager');
const config = require('./config');

let client = new SteamUser();
let manager = new TradeOfferManager({
	"steam": client, // Polling every 30 seconds is fine since we get notifications from Steam
	"domain": "example.com", // Our domain is example.com
	"language": "en" // We want English item descriptions
});
let community = new SteamCommunity();

// Steam logon options
let logOnOptions = {
	"accountName": config.accountName,
	"password": config.password,
	"twoFactorCode": SteamTotp.getAuthCode(config.shared_secret)
};

client.logOn(logOnOptions);

client.on('loggedOn', function() {
	console.log("Logged into Steam");
});

client.on('webSession', function(sessionID, cookies) {
	manager.setCookies(cookies, function (err){
        if (err) {
            console.log('Unable to set trade offer cookies: '+err);
            process.exit(1); // No point in staying up if we can't use trade offers
        }
        console.log('Trade offer cookies set.');
    });
    sendref();
	community.setCookies(cookies);
});


function sendref() {
    manager.loadInventory(440, 2, true, function (err, inventory){
        if (err) {
            console.log(err);
        } else {
            // I need to send X ref
            var volume = ; //put whatever amount
            // Filter out all the ref
            var ref = inventory.filter(function (item) {
                return item.market_hash_name.match('Refined Metal')
            });

            // Let the user know we don't have enough ref
            if (ref.length < volume) {
                console.log('Not enough ref');
                return true; // Give up
            }            
            
            // Start a new trade offer
            var offer = manager.createOffer(config.bossID);
 
            // Add what we should to the current trade
            console.log('Adding '+volume+' metal');
            offer.addMyItems(ref.slice(0, volume))
 
            // Send the offer
            offer.send(function (err, status){
                if (err) {
                    console.log(err);
                } else if (status == 'pending'){
                    community.acceptConfirmationForObject(config.identity_secret, offer.id, function(err) {
                        if (err) {
                            console.log(err);
                        } else {
                            console.log("Offer confirmed");
                        }
                    });
                } else {
                    console.log('Trade offer sent successfully');
                }
            });
        }
    });
}






Also tagged with one or more of these keywords: node.js, node-steam-tradeoffer-manager

2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users