Lets you interface with Steam without running an actual Steam client
This is a node port of SteamKit2. It lets you interface with Steam without running an actual Steam client. Could be used to run an autonomous chat/trade bot.
npm install steam
Note: when installing from git, you have to additionally run
npm install inside the project directory to run the
prepublish script (see npm/npm#3055). It pulls Steam resources (Protobufs and SteamLanguage) from SteamKit2 and requires
Note: only Node.js v0.12 and io.js v1.4 are supported.
require this module.
var Steam = require'steam';
Steam is now a namespace (implemented as an object) containing the SteamClient class,
servers property, and a huge collection of enums (implemented as objects). More on those below.
Then you'll want to create an instance of SteamClient, call its logOn method and assign event listeners.
var bot = ;botlogOnaccountName: 'username'password: 'password';boton'loggedOn' /* ... */;
See example.js for the usage of some of the available API.
Steam.servers contains the list of CM servers node-steam will attempt to connect to. The bootstrapped list (see servers.js) is not always up-to-date and might contain dead servers. To avoid timeouts, replace it with your own list before logging in if you have one (see 'servers' event).
Chat-related methods automatically convert ClanIDs (group's SteamID) to ChatIDs. Conversely, ChatIDs are converted to ClanIDs in chat-related events if it's a group chat (i.e. not an "ad hoc" chat), otherwise left alone. In the following docs, chat SteamID always refers to ClanID for group chats and ChatID otherwise.
Whenever a method accepts (or an event provides) an
ESomething, it's a Number that represents some enum value. See enums.steamd and eresult.steamd for the whole list of them. For each enum, there is an equivalently named property on
Steam. The property is an object; for each of the enum's members, there is an equivalently named property on the object with an equivalent value.
Note that you can't easily get the string value from the number, but you probably don't need to. You can still use them in conditions (e.g.
if (type == Steam.EChatEntryType.Emote) ...) or switch statements.
A boolean that indicates whether you are currently logged on. 'loggedOn' is emitted when it changes to
true, and 'loggedOff' or 'error' when it changes to
false, unless you called logOff. Accessing any other properties or calling any methods other than logOn or logOff is only allowed while logged on.
Your own SteamID.
Information about users you have encountered. It's an object whose keys are SteamIDs and values are objects with the same structure as in the 'user' event.
Information about chat rooms you have joined. It's an object with the following structure:
"steamID of the chat":"steamID of one of the chat's current members":rank: "EClanPermission"permissions: "a bitset of values from EChatPermission"// other members// other chats
Object.keys(steamClient.chatRooms[chatID]) will return an array of the chat's current members, and
steamClient.chatRooms[chatID][memberID].permissions & Steam.EChatPermission.Kick will evaluate to a nonzero value if the specified user is allowed to kick from the specified chat.
Connects to Steam and logs you on upon connecting.
logOnDetails is an object with the following properties:
authCode- Steam Guard code. Must be valid if provided, otherwise the logon will fail. Note that Steam Guard codes expire after a short while.
shaSentryfile- sentry hash. If not provided, you'll receive one through the 'sentry' event (if the logon succeeds). If no Steam Guard code is provided, the hash must be already registered with this account, otherwise it's ignored.
If you provide neither a Steam Guard code nor a sentry hash registered with this account, the logon will fail and you'll receive an email with the code.
If you provide both a sentry hash and a valid Steam Guard code, the hash will be registered with this account. This allows you to reuse the same hash for multiple accounts.
You can call this method at any time. If you are already logged on, logs you off first. If there is an ongoing connection attempt, cancels it.
Logs into Steam Community. You only need this if you know you do.
callback will be called with an array of your new cookies (as strings).
Do not call this before the first 'webSessionID' event, or you'll get a broken cookie. Feel free to call this whenever you need to refresh your web session - for example, if you log into the same account from a browser on another computer.
Tells Steam you are playing game(s).
appIDs is an array of AppIDs, for example
. Multiple AppIDs can (used to?) be used for multi-game idling.
Changes your Steam profile name.
You'll want to call this with
EPersonaState.Online upon logon, otherwise you'll show up as offline.
Last parameter defaults to
EChatEntryType.ChatMsg. Another type you might want to use is
Sends a friend request.
Removes a friend.
Attempts to join the specified chat room. The result should arrive in the 'chatEnter' event.
Leaves the specified chat room. Will silently fail if you are not currently in it. Removes the chat from
Locks and unlocks a chat room respectively.
Enables and disables officers-only chat respectively.
Invites the specified user to the specified chat.
Requests the Steam level of a number of specified accounts. The
steamids argument should be an array of SteamIDs.
The single object parameter of the
callback has the requested SteamIDs as properties and the level as their values. Example:
"76561198006409530": 62"76561197960287930": 7
Requests friend data.
steamIDs must be an array.
requestedData is optional – if falsy, defaults to
EClientPersonaStateFlag.PlayerName | EClientPersonaStateFlag.Presence | EClientPersonaStateFlag.SourceID | EClientPersonaStateFlag.GameExtraInfo. The response, if any, should arrive in the 'user' event.
Sends a trade request to the specified user.
tradeID as the one passed through the 'tradeProposed' event.
acceptTrade should be
Cancels your proposed trade to the specified user.
Sends a message to Game Coordinator.
body must be a serialized message without the header (it will be added by node-steam).
type must be masked accordingly if it's a protobuf message. If any extra arguments are provided and this message receives a response (JobID-based), they will be passed to the 'fromGC' event handler.
Something preventing continued operation of node-steam has occurred.
e.cause is a string containing one of these values:
EResult, the logon response. Some values you might want to handle are
AccountLogonDenied(Steam Guard code required).
EResult, most likely
You can now safely use all API.
If you are using Steam Community (including trading), you should call webLogOn again, since your current cookie is no longer valid.
If you didn't provide a hash when logging in, Steam will send you one through this event. If you have Steam Guard enabled, you should save this and use it for your further logons. It will not expire unlike the code.
node-steam will use this new list when reconnecting, but it will be lost when your application restarts. You might want to save it to a file or a database and assign it to
Steam.servers before logging in next time.
Steam.servers will be automatically updated after this event is emitted. This will be useful if you want to compare the old list with the new one for some reason - otherwise it shouldn't matter.
Someone has gone offline/online, started a game, changed their nickname or something else. The provided object has a property for each set field in CMsgClientPersonaState.Friend with the name converted to camelCase. The values have the following types:
gameServerIp: String (e.g. '18.104.22.168')
lastLogon: Date objects
bytesfields: Buffer objects
Note that the
users property is not yet updated when this event is fired, so you can compare the new state with the old one to see what changed.
This API is unstable.
Game-specific information about a user. Only received when you're in the same game.
groups properties now contain data (unless your friend/group list is empty). Listen for this if you want to accept/decline friend requests that came while you were offline, for example.
Some activity in your friend list. For example,
EFriendRelationship.PendingInvitee means you got a friend invite,
EFriendRelationship.None means you got removed. The
friends property is updated after this event is emitted.
Some activity in your group list. For example,
EClanRelationship.Invited means you got invited to a group,
EClanRelationship.Kicked means you got kicked. The
groups property is updated after this event is emitted.
Same arguments as the above two, captures both events. In case of a friend message, the fourth argument will be undefined.
The result of attempting to join a chat. If successful, the list of chat members is available in
Something happened in a chat you are in. For example, if the first argument equals
Steam.EChatMemberStateChange.Kicked, then someone got kicked.
Your number of pending incoming trade offers has changed.
You were offered a trade.
Listen for this event if you are the one sending a trade request.
Use the group's RSS feed to get the body of the announcement if you want it.
type- masked accordingly for protobuf
A message has been received from GC. The extra arguments are the same as passed to toGC if this message is a JobID-based response to it.