A Node.js library for the Steam Web API, with wrappers to deal with its methods, like those used on Steam Mobile App.
npm install steam.js
Or get the latest sources...
git clone git://github.com/JulioC/steam.js.git cd steam.js npm link
Making a request for the Steam Web API
var steam = require('steam');
steam.util.getServerInfo(function (e, d) {
console.log('Server time: ' + d.servertimestring);
});
steam.request({
interface: 'ISteamNews',
method: 'GetNewsForApp',
version: '0002',
secure: false,
get: {
appid: 24010,
maxlength: 128,
count: 3
}
}, function (e, d) {
d.appnews.newsitems.forEach(function(news) {
console.log(news);
});
});
Creating a Steam echo bot
var Session = require('steam/Session');
var session = new Session();
session.connect({
username: 'gaben',
password: 'c4ke'
});
session.on('message_saytext', function (m) {
session.message({
steamid: m.steamid_from,
text: m.text
});
});
The plans are to expose most methods of the Web API on the Core in a nice way, like it's done with util
. I don't plan to parse the return value of those methods, but I'll probrably improve error handling.
On the Session module, there are a lot of methods still to implement. It will be done as it's necessary.
I want to create new modules, for TF, Portal, Economy, but it will take longer for that...
Note: since the library is still WIP, the functions are most likely to change, specially the return values and callbacks
The module used for direct requests for the Steam Web API
var steam = require('steam');
Make a request for the Steam API with a method with the given parameters.
If the first argument is a string, it will be threated as the path
option. If it's an object, it should have at least the interf
and method
set. The available options are:
-
interface
: the Steam API interface -
method
: the Steam API method -
version
: version of the method to be called, formatXXXX
, defaults to0001
-
path
: overwrites the interface, method and version options, with formatinterface/method/vXXXX
-
secure
: if the request should be made via https, defaults totrue
-
get
: GET params for the HTTP request -
post
: POST params for the HTTP request
Once the request is finished, the callback
function will be called with 2 arguments, an error object (null if success) and the available data (parsed from json if success).
Shorthand for request(SteamWebAPIUtil/GetServerInfo, callback)
. Get the current time on the server.
Shorthand for request(SteamWebAPIUtil/GetServerInfo, callback)
. Accepts an optional object with the key
to be used on the request. Lists the available methods and their parameters.
Reproduces the behavior expected from the Mobile App, handles authorization, server notifications and client messaging.
var Session = require('steam/Session');
Creates a new Steam Session with the given options (all optional):
-
scope
: array of actions to request access for on authorization, defaults to['read_profile', 'write_profile', 'read_client', 'write_client']
-
client_id
: registered Client ID, Valve hasn't made any public method to get one
Returns true if a valid session id is set
Authenticates with the server and keep connected, querying the server for incoming messages. The (access_token
) or (username
, passwordand
authcode` [optional]) options must be provided:
-
access_token
: pre-obtained access token, can be kept between sessions -
username
: Steam Account username -
password
: Steam Account password -
authcode
: If Steam Guard is active on the Steam Account, try login once without it to receive the code via email
If connected, calls success with object:
-
access_token
: same as above, to be kept for future sessions -
steamid
: 64 bits representation of the Account
Send a message for another user. Available options are:
-
type
: Type of the message. Valid types aresaytext
(default),emote
,typing
-
text
: Text message to send (optional iftype == 'typing'
) -
steamid
: 64 bits Steam ID of the target user
(to be documented)
Error
error
auth_error
Authentication
authenticate
connect
logon
Polling
poll
poll_status
poll_secure
Message
message
message_typing
message_saytext
message_mysaytext
message_emote
message_myemote
message_leftconversation
message_personastate