title: Node Js Steam Trade Offers Bot Items
body: <p>This bot accept all trades but it need to accept only trade offers which contains [type: 'Consumer Grade SMG',] item in itemsToReceive. I was trying to do something like: If itemsToReceive contains Consumer Grade SMG then accpet offer else cancel offer but i failed. Im newby and i dont have any idea how to do that.
  Sorry for my bad english.</p>
  
  <p>My output console:</p>
  
  <pre><code>New offer #644673626 from [U:1:205839253]
      [ { appid: 730,
          contextid: { low: 2, high: 0, unsigned: true },
          assetid: '3142560367',
          classid: '310777708',
          instanceid: '302028390',
          amount: 1,
          missing: true,
          id: '3142560367',
          icon_url: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHL
      bXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FBRw7ODYYzxb08-3moS0m_7zO6-fxzNQ65J03L2Vo
      9-sigzj_kU6Mmr6LIKVdwNvZVHTqVTqxri8jZS4tYOJlyVoTeLjug',
          icon_url_large: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4o
      FJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FBRw7ODYYzxb08-3moS0m_7zO6_ummpD78A
      _27HA9tvw3gDg_UBlMWH0IYDDIwU3aVzQ_1Tvxefs1pPou8uawXBnsz5iuyjoOPjz8g',
          icon_drag_url: '',
          name: 'P90 | Sand Spray',
          market_hash_name: 'P90 | Sand Spray (Minimal Wear)',
          market_name: 'P90 | Sand Spray (Minimal Wear)',
          name_color: 'D2D2D2',
          background_color: '',
          type: 'Consumer Grade SMG',
          tradable: true,
          marketable: true,
          commodity: false,
          market_tradable_restriction: 7,
          fraudwarnings: '',
          descriptions:
           { '0': [Object],
             '1': [Object],
             '2': [Object],
             '3': [Object],
             '4': [Object],
             '5': [Object] },
          owner_descriptions: '',
          actions: { '0': [Object] },
          market_actions: { '0': [Object] },
          tags:
           { '0': [Object],
             '1': [Object],
             '2': [Object],
             '3': [Object],
             '4': [Object],
             '5': [Object] } } ]
      Offer accepted
      Offer #644673626 changed: Active -Accepted
      Received: P90 | Sand Spray
  </code></pre>
  
  <p>And bot code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>/**
   * STOREHOUSE - node-steam
   * 
   * Uses node-steam-user for notifications and accepts all incoming trade offers
   */
  
  var SteamUser = require('steam-user');
  var TradeOfferManager = require('../lib/index.js'); // use require('steam-tradeoffer-manager') in production
  var fs = require('fs');
  
  var client = new SteamUser();
  var 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
  });
  
  // Steam logon options
  var logOnOptions = {
   "accountName": "xxxxx",
   "password": "xxxxx"
  };
  
  if(fs.existsSync('polldata.json')) {
   manager.pollData = JSON.parse(fs.readFileSync('polldata.json'));
  }
  
  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(err);
     process.exit(1); // Fatal error since we couldn't get our API key
     return;
    }
  
    console.log("Got API key: " + manager.apiKey);
   });
  });
  manager.on('newOffer', function(offer) {
   console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
   console.log(offer.itemsToReceive);
   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) + " -&gt; " + 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));
  });</code></pre>
  </div>
  </div>
  </p>