Giter Club home page Giter Club logo

node-steam-tradeoffer-manager's Introduction

Steam Trade Offer Manager for Node.js

npm version npm downloads license sponsors

This module is designed to be a completely self-contained manager for Steam trade offers.

Instead of being just a simple API wrapper, it's designed to take most of the work out of implementing trade offers in your application.

You absolutely need Node.js v4.0.0 or later or this won't work.

Install it from npm or check out the wiki for documentation.

Have a question about the module or coding in general? Do not create a GitHub issue. GitHub issues are for feature requests and bug reports. Instead, post in the dedicated forum. Such issues may be ignored!

Support

Report bugs on the issue tracker or ask questions on the dedicated forum.

node-steam-tradeoffer-manager's People

Contributors

aareksio avatar andrewda avatar arik123 avatar ashesh3 avatar cohedrin avatar destro avatar doctormckay avatar eblanshey avatar ertomentis avatar gespispace avatar hhanuska avatar jankuss avatar kaikash avatar kinsi55 avatar kryogenic avatar lincsanders avatar makcc666 avatar matheustav avatar noobgam avatar ryantology avatar sadzurami avatar serge1peshcoff avatar stuffa1991 avatar welwood08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-steam-tradeoffer-manager's Issues

Crashing by items from Spiral Knights

So, i have a lottery site, which used node-steam-tradeoffer-manager and i found problem, when someone send me offer with items from game Spiral Knights like this my bot crash by library error:
Offer
With this error:

/var/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:124
        item.assetid = item.id = (item.assetid || item.id).toString();
                                                          ^
TypeError: Cannot read property 'toString' of undefined
    at /var/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:124:53
    at Array.map (native)
    at processItems (/var/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:123:15)
    at createOfferFromData (/var/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:106:25)
    at /var/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:92:12
    at Array.map (native)
    at /var/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:91:63
    at TradeOfferManager.<anonymous> (/var/bot/node_modules/steam-tradeoffer-manager/lib/assets.js:128:3)
    at /var/bot/node_modules/steam-tradeoffer-manager/node_modules/async/lib/async.js:52:16
    at /var/bot/node_modules/steam-tradeoffer-manager/node_modules/async/lib/async.js:363:13

So, how i fix this?
File node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js
in function checkNeededDescriptions
instead of

if(!manager._hasDescription(item))

i write

if(!manager._hasDescription(item) || (typeof item.id == 'undefined' && typeof item.assetid == 'undefined'))

I think, it must be fixed. Sorry for my bad english, i just tried to help

API Key is wrong

Hello. I'm using node-steam-user and this libraries. After some period of the time developing my server I started to recieve such messages: 'Error: No API-Key set (yet)' on pollFailture.

In your wiki there's an apiKey option for the constructor, but it's not used anywhere in the code. And I didnt found any code that sets apiKey, just and _checkApikey method, which isnt fired in the constructor. I dont know what I'm doing wrong. I've set sentry like this:

client.setSentry(new Buffer(fs.readFileSync(config.bot.ssfn), 'binary'));

and successfuly logged into the account. I've set up an api key for my IP, which works perfectly on other my servers/sites/raw queries from me. Just wtf.

Offer state "undefined". What to do?

So, i've created small bot which should accept trades. Scenario is well known.

Some small part of code.

manager.on('newOffer', function(offer) {
  /* SOME FUNCTIONS & CHECKS */
  // Try to accept the offer
  offer.accept(function(err, status) {
    console.log('ACCEPTED OFFER STATE: ' + status);

    if(status == 'accepted') {

      /* DO MYSQL STUFF & MORE */

    }
  });
});

I check if trade status was accepted and let the server do the stuff. But...
Sometimes trade status is "unknown" and trade offer is accepted anyway. No error, just unknown.
Will simple if(status != accepted) { return; } skip the acceptation until next check? Or its better just to .decline() the offer?

Poll Failure problem

I'm constantly getting poll failure errors and my bot can't work.
The error is: { [Error: socket hang up] code: 'ECONNRESET' }
This happened after the recent updates on most of the scripts I use few days ago. I've updated everything, but it seems like I'm missing something.

node-steam-totp - UPDATED

node-steam-tradeoffer-manager - UPDATED

Any ideas on the fix?

Get escrow duration before making a offer.

Nice work McKay!

But how come we can't get the escrow duration before making a offer? Have you not yet fixed this or is it going to stay the way it is now? The
var g_daysMyEscrow = x; var g_daysTheirEscrow = y;
Still works even if we have not done a trade already.

Implement "unknownOfferSent" event

Sometimes when you send an offer Steam will return an Error, thus the .send method failed, and did not return any tradeofferid (for further processing). It would be great if, when polling, any "unknown" offers like these ones, and ones that were sent outside of the tradeoffer manager could get piped trough to an unknownOfferSent event where you could cancel the trades, or do further stuff with them.

Error in the tradeoffer manager module?

When my bot recives a trade offer it crashes because of the following error:
e413579314247faa45e7cc58f9071d3a

This is the code section:

client.on('tradeOffers', function(number) {
  if (number > 0) {
    offers.getOffers({
      get_received_offers: 1,
      active_only: 1,
      time_historical_cutoff: Math.round(Date.now() / 1000)
    }, function(error, body) {
        console.log(body); //outputs undefined
      if(body.response.trade_offers_received){
        body.response.trade_offers_received.forEach(function(offer) {
          if (offer.trade_offer_state == 2){
            if(offer.steamid_other == admin) {
              offers.acceptOffer({tradeOfferId: offer.tradeofferid});
            } else {
              offers.declineOffer({tradeOfferId: offer.tradeofferid});
            }
          }
        });
      }
    });
  }
});

ETradeOfferState.CreatedNeedsConfirmation to polling?

Hello, as the escrow is coming soon and it seems that the mobile confirmations are still sometimes acting up, maybe polling should also cancel trades that haven't been confirmed in the cancel time span.

I'm talking about changing polling.js line 63 from:

if(offer.state == ETradeOfferState.Active) {

to:

if(offer.state == ETradeOfferState.Active || offer.state == ETradeOfferState.CreatedNeedsConfirmation) {

Cant send offer

Hello.
I cant send trade offer.

                            create = manager.createOffer('steam64');
                            itemx = {
                                appid: 730,
                                contextid: 2,
                                amount: 1,
                                assetid: '2550388675'
                            }
                            create.addMyItem(itemx);

                            create.send('test', 'token', function(err, status) {
                                if(err)
                                    console.log(err);
                                else
                                {   
                                    console.log('Success');
                                }
                            });

When i try this:
[Error: There was an error sending your trade offer. Please try again later. (25)]

I dont know why.

Language ru

manager = new TradeOfferManager
'language': 'ru' // if there was 'en' it would work
'pollInterval': 5000
And it is not working, I can't setCookies, but when it is 'en' it works.

Creating a trade offer returns Error 400.

I've created a functioning trade bot using node-steam-tradeoffers, and afterwards have switched over to using node-steam-tradeoffer-manager.

I've already been using my account, and sentry file, successfully sending trades for days.

The structure of my bot matches how ParentBot is set up, switching out node-steam-tradeoffers however.

When I make the trade request using node-steam-tradeoffers, returns tradeid fine.

When I make the trade request using node-steam-tradeoffer-manager, I receive a 400 error.


Any guidance on how I can try to debug this? Been trying to log the request headers to compare between the two - to see what the difference is.

Kind of stuck, thought I'd make a post~

Use `partnerinventory` endpoint when loading partner's inventory

It looks like manager is currently using the "regular" (inventory/json/:appid/:contextid) inventory endpoint for partner inventory retrieval.

https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/blob/master/lib/classes/TradeOffer.js#L227
https://github.com/DoctorMcKay/node-steamcommunity/blob/master/components/users.js#L241

However, Steam uses different endpoint for partner inventories - tradeoffer/new/partnerinventory. This endpoint provides 2 advantages:

  • tradable items only
  • works for private inventories (provides subset of items necessary to "decode" the offer)

Get the new id then of accepting the trade.

I am currently doing a bot that records items received in a MySQL database. But I’ve noticed that once accepted the trade objects ID (assetid) changes. So then it is impossible to identify you when you send these objects to another user.

Would there be a way to get the actual object id received within the event ‘receivedOfferChanged’?

Offer without trade id.

[Error: Offer #721136877 is accepted, but does not have a trade ID]

Error returned when calling offer.getReceivedItems(function(err, items) { ... }

Results in items being undefined.

Items, returned by getRecivedItems are undefined

Hello, im using this code :

offer.accept(function (err) {
                        if (err) {
                            debug("Unable to accept offer: ", err.message);
                        }
                        else {
                            offer.getReceivedItems(function(err, items) {
                                items.forEach(function(item){
                                 // Handle recived items
                                })

                            })
//and so on...

but I got error "Cannot read property 'forEach' of undefined" while offer was accepted and contains receiving items.
It work's fine before and after this error.
If it's important, item to recive was m4a1-s | Cyrex (Minmal wear) and there are no items to give.

Accepting a trade offer doesn't change anything, leaves offer in pending state

Here's my issue - I accept an offer like this:

offer.accept(function(err){ //where offer is a TradeOffer
    if (err) {
        console.log(err)
    } else {
        console.log("Offer accepted")
}

Console outputs "Offer Accepted" but offer is left in pending state on both ends (both account the offer is sent from and the account receiving the offer see pending). Confirmations are enabled for both and I am polling for confirmations.

API Key Woes

I was wondering where the api key is stored. I revoked the one I was using but it is now saved and I was wondering how to remove it, and if you could add it to the wiki for future reference.

Thanks

Detecting invalid cookies

Tradeoffer manager is currently detecting certain cases, when the trade offer simply cannot be sent/accepted, e.g. NewDevice. However, it's still not detecting invalid cookies.

If cookies become invalid, it's impossible to accept or send any trade offer without "refreshing" the cookies.

Manager currently does this:

  • when accepting trade offer, manager will return error "HTTP error 403". If auto-retry is enabled, manager will attempt to repeatedly accept the trade offer even though it's impossible
  • when sending trade offer, manager will emit error "HTTP error 401"

It's possible to detect invalid cookies by checking the response from request module. In both cases, the cookie header will no longer contain steamLogin nor steamLoginSecure cookies.

It would be great if manager detected these cases and provided appropriate error.cause.

Here's my testing script.

send offer gives error

I'm also getting: [Error: Malformed response]

I'm getting the callback from setCookies with the apiKey, and only later calling the createOffer call below.

BTW, I try to print out the body that's malformed in lib/index.js but nothing get printed. It's strange. It's as if it's coming from somewhere else.

I started from the example code in which login works, as does trade discovery/accept.

// EXAMPLE FILE USE OF COOKIES

client.on('webSession', function(sessionID, cookies) {
    manager.setCookies(cookies, function(err) {
        if(err) {
            console.log(err);
            process.exit(1); // Fatal error since we couldn't get our API key
            return;
        }
        console.log("Got API key: " + manager.apiKey);
    });
});

// HERE IS YOUR CODE I AM TRYING TO USE
        var offer = manager.createOffer(partnerSteamId);
        manager.loadInventory(440, 2, true, function(err, myItems) {
            if(err) {
                console.error(err);
                return;
            }

            offer.loadPartnerInventory(440, 2, function(err, theirItems) {
                if(err) {
                    console.error(err);
                    return;
                }

                offer.addMyItem(myItems[0]);
                offer.addTheirItem(theirItems[0]);
                offer.send("");
            });
        });

THANKS!

Steam Escrow

Hi, are you trying something with mobile authentication to work with bots on nodejs?

Allow API key to be passed in via options

Registering API key is a one time thing. It doesn't expire, ever.

I'd be cool if it was possible to set the key via options so I can skip the HTTP call.
Even slight optimization like this can be useful, considering how unstable Steam is.

newOffer return; will stop from firing it again

Hello. One more issue:
When newOffer is fired and I do

return;

this trade offer will never be fired again. And this is very bad. For example this code:

offers.on('newOffer', function(offer) {
    logger.info('called1');
    if(pause) return;
    logger.info('called2');
});

If my server was on the pause (for example when steam is down etc) then this trade will never be fired again. What can I do then?

Get Items Id after partner accepts a trade offer.

Situation:
Bot creates tradeoffer where bot is giving nothing and partner is giving some items. Partner accepts the tradeoffer, and items are transfered to bot.

Now, how can i determine new items id? Because the bot didnt accept nothing i cant call getreceiveditems (cos i dont have tradeId).

Should i turn something on?
Should i fetch bot inventory and do any magic recognising by hashname, instanceid, classid, etc?
What way do you use?

Thx

It didn't works.

So i required the lib. and set it up with
var manager = new TradeOfferManager({
"steam": client, // Polling every 30 seconds is fine since we get notifications from Steam
"domain": "crackbook.de", // Our domain is example.com
"language": "en" // We want English item descriptions
});
When i pasted the following in
// TRADEOFFER
// If a user sends a trade request...
manager.on('newOffer', function(offer) {
console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
offer.accept(function(err) {
if(err) {
console.log("Unable to accept offer: " + err.message);
} else {
console.log("Offer accepted");
}
});
});

manager.on('receivedOfferChanged', function(offer, oldState) {
console.log("Offer #" + offer.id + " changed: " + TradeOfferManager.getStateName(oldState) + " -> " + TradeOfferManager.getStateName(offer.state));

if(offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
    offer.getReceivedItems(function(err, items) {
        if(err) {
            console.log("Couldn't get received items: " + err);
        } else {
            var names = items.map(function(item) {
                return item.name;
            });

            console.log("Received: " + names.join(', '));
        }
    });
}

});

manager.on('pollData', function(pollData) {
fs.writeFile('polldata.json', JSON.stringify(pollData));
});

But it didnt works. I get no log on new tradeoffers

getOffer using

Could You help me?
How can I use getOffer method?

I try this but it not working:

var offer;
manager.getOffer(568651808, offer);

it return error: undefined is not a function
(tradeoffer.js line 39)

How to get sent offer id?

Is there actually a way to get a ID of a sent offer?!
That might be important if you want to track sent offers via database.

Multiple bots

Its possible to create multiple bots in one file?

TypeError thrown due to apparently missing callback

Hi, I've been using this nifty module for a bit and noticed that it sometimes throws this:

/home/anthony/botte/node_modules/steam-tradeoffer-manager/node_modules/steamcommunity/index.js:323
                callback(error);
                ^

TypeError: callback is not a function
    at SteamCommunity._checkHttpError (/home/anthony/botte/node_modules/steam-tradeoffer-manager/node_modules/steamcommunity/index.js:323:3)
    at Request._callback (/home/anthony/botte/node_modules/steam-tradeoffer-manager/node_modules/steamcommunity/components/users.js:260:12)
    at Request.self.callback (/home/anthony/botte/node_modules/steam-tradeoffer-manager/node_modules/steamcommunity/node_modules/request/request.js:198:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/home/anthony/botte/node_modules/steam-tradeoffer-manager/node_modules/steamcommunity/node_modules/request/request.js:1035:10)
    at emitOne (events.js:82:20)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/home/anthony/botte/node_modules/steam-tradeoffer-manager/node_modules/steamcommunity/node_modules/request/request.js:962:12)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)

I'm guessing this occurs when the cookies expire and steam returns 401 or whatever it decides to in that particular moment, and since the manager doesn't do community.login there's no callback ever passed. Am I just being dumb and missing the obvious place I should be setting the callback myself or?

Error: Access Denied

Hello,
when I try to set the cookies I get an error saying Access Denied. Any idea what's causing this?

Error with loadInventory

Hello, I have an error that I have hard time to fix.

It happens when I try to use offers.loadInventory(); where

var offers = new TradeOfferManager({
    steam:        client,
    language:     "en", // English item descriptions
    pollInterval: 10000, // (Poll every 10 seconds (10,000 ms)
    cancelTime:   300000 // Expire any outgoing trade offers that have been up for 5+ minutes (300,000 ms)
});

I have this error :

bash# : ./node bot.js 
/root/bot/node_modules/steam-tradeoffer-manager/node_modules/steamcommunity/components/users.js:248
    var endpoint = "/profiles/" + userID.getSteamID64();
                                        ^
TypeError: Cannot read property 'getSteamID64' of undefined

Thank you for your help :)

EAI_AGAIN error

Sorry if i post here, but i have this error every time :( how to fix?
sad

Trade escrowEnds ist null

So i was just testing, with my own account. Items gone definitely to escrow, since i have notifications disabled, but escrowEnds in trade is still null. Is it bug?

Forgot to say, that even so, offer.state is 2.

Callback called twice

The callback in TradeOffer.prototype.cancel can be called twice if err is not null:

this.manager._apiCall('POST', this.isOurOffer ? 'CancelTradeOffer' : 'DeclineTradeOffer', 1, {"tradeofferid": this.id}, function(err, body) {
    if(err) {
        makeAnError(err, callback);
    }

    this.updated = new Date();

    if(callback) {
        callback(null);
    }

    this.manager.doPoll();
}.bind(this));

Offer accept InvalidState (11)

When I decline offer, state no change

manager.on('newOffer', function(offer) {
      offer.decline(function(err){
            console.log('Decline: '+err);
       });

   if(offer.state==2) {
             offer.accept(function(err,status){
                  if(err) {
                       console.log('Accept Error: ' + err);
                  };
             };
     };
 });

I got error:
Error: There was an error accepting this trade offer. Please try again later. (11)

Sentofferchanged sometimes can`t detect state change.

Hi. I have a problem. Sometimes manager cant see a state's change from Active to Accepted, I don`t know where is the reason, but I saw, that manager... That manager is stopping to see this offer. I think, problem is there - offer goes to historical state, but BOT is checking a state only for Active

Verify if an offer will go to escrow after you accept it.

Hello there,
I'm trying to verify that incoming offers wont go to Escrow if accepted. i want to verify this just for received offers.

first, i used

offers.getEscrowDuration(SteamID[,Token],function(err,theirEscrowDays,yourEscrowDays){
...
});

to extract theirEscrowDays & yourEscrowDays vars, but it doesnt work if the sender is not on my friend list, i've noticed that this method(getEscrowDuration) creates a new trade offer.

second, i tried to get escrowEnds property of the offer object

offers.on('newOffer', function (offer) {
...
    var escrow = offer.escrowEnds;
...
});

but it returns null.
the offers var here is the instanciation of

var client = new SteamUser();
var offers = new TradeOfferManager({
    steam:        client,
    domain:       config.domain, 
    language:     "en", 
    pollInterval: 10000, 
});

Thx for helping.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.