Jump to content
McKay Development

How to check trade offer status


Recommended Posts

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('test');
          offer.send((err, status) => {
           
 
            if (err) {
              console.log("Error sending trade offer:", err);
            } else if (status === 'pending') {
              this.community.acceptConfirmationForObject('secret', offer.id, (err) => {
                if (err) {
                  console.log("Error accepting confirmation:", err);
                } else {
                  console.log("[INFO] TradeOffer confirmed with TradeOfferID: #" + offer.id);
                }
              });
            } else if (status === "accepted") {
              console.log("[INFO] TradeOffer accepted");
            } else {
              console.log("[INFO] TradeOffer #" + offer.id + " sent successfully");
            }
          });
        }
      }
    });
  }
   }

 

If not like this, then how? Please help. 

Link to comment
Share on other sites

Thank you for the response! I'm still struggling. I can't get it working. When I cancel the trade from my non bot account the code doesn't run. 

EDIT: I've enabled polling (pollInterval: 30) but still the event never triggers.

console.log(TradeOfferManager.ETradeOfferState[offer.state]);
        console.log(oldState)

Here is a snippet of more code
 

io.on('connection', (socket) => {
  const clientAddress = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address;
 
  // Check if the client address is localhost or from a permitted IP range
  if (allowedAddresses.includes(clientAddress)) {
    // Connection allowed
    console.log('Client connected from localhost:', clientAddress);
 
    socket.on('startTradeDeposit', (data) => {
      const { assetIDs, steamID } = data;
     
      console.log('Received startTradeDeposit event with NameIDs:', assetIDs);
 
      bot.sendDepositTrade(steamID, assetIDs, (err, success, tradeOffer) => {
        // Log whether the callback is executed
       
        if (err && !success) {
          console.error('Error occurred while sending deposit trade:', err);
          socket.emit('failure', {
            message: 'We could not process your request at this time.'
          });
        } else {
          console.log('Trade offer sent successfully!');
         
        }
      });
 
      bot.manager.on('sentOfferChanged', (offer, oldState) => {
        console.log(TradeOfferManager.ETradeOfferState[offer.state]);
        console.log(oldState)
      });
    });
  }
});
Edited by dawe
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...