Skip to content

Steam Chat

Alex Corn edited this page Feb 13, 2019 · 8 revisions

As of v2.2.0, node-steamcommunity allows you to use Steam Chat via Steam's web chat service. Chat is accessed through properties, methods, and events on your SteamCommunity object.

WEBCHAT VIA NODE-STEAMCOMMUNITY IS DEPRECATED AND WILL BE REMOVED IN A FUTURE RELEASE. Steam's new webchat goes through the CM servers, so you should use node-steam-user instead.

Properties

chatState

The current state of our chat connection. One of the following values:

SteamCommunity.ChatState = {
	"Offline": 0,
	"LoggingOn": 1,
	"LogOnFailed": 2,
	"LoggedOn": 3
};

You can only send and receive chat messages if this value is LoggedOn.

Methods

chatLogon([interval][, uiMode])

  • interval - The interval in milliseconds between polling requests (default 500)
  • uiMode - web to get a globe icon next to your name, mobile to get a phone icon (default web)

v2.4.0 or later is required to use the uiMode argument

Starts logging you into web chat. Steam web chat uses long polling so a short interval value should be safe. Default is 500.

Listen for the chatLoggedOn event to know when you're successfully logged on. Listen for the chatLogOnFailed as there may be a fatal error while logging on.

chatMessage(recipient, text[, type][, callback])

  • recipient - The recipient of our message, as a SteamID object or something that can parse into a SteamID object (STEAM_0:0:23071901, [U:1:46143802], or 76561198006409530 formats)
  • text - The message text
  • type - Optional. The type of message you're sending. Default is saytext. Another possible value is typing.
  • callback - Optional. Called when the message is successfully sent or an error occurs.
    • err - An Error object on failure, null on success

Sends a chat message to a recipient. A saytext message is a regular chat message. If you send a typing message, text is ignored and the recipient's chat window will say that you're typing for 20 seconds.

chatLogoff()

Logs you off of chat.

Events

chatLogOnFailed

  • err - An Error object
  • fatal - true if this is a fatal error, false if not (will keep trying to connect if not fatal)

v3.19.10 or later is required to use this event

Emitted when there's a problem while logging into webchat.

chatLoggedOn

Emitted in response to a call to chatLogon() when we successfully logged on.

chatPersonaState

  • steamID - The SteamID of the user for whom we just got persona data, as a SteamID object
  • persona - The user's persona data

Emitted when we receive new persona state data for a friend. Properties of persona are as follows:

  • steamID - A SteamID object
  • personaName - A string containing their (new) name
  • personaState - A value from the PersonaState enum (see below)
  • personaStateFlags - An integer containing zero or more flags from the PersonaStateFlag enum (see below)
  • avatarHash - The user's avatar hash (see below)
  • inGame - true if the user is currently in-game, false if not
  • inGameAppID - An integer containing the AppID of the app the user is currently playing/using, or 0 if not in-game
  • inGameName - The name of the app the user is currently playing/using, or null if not in-game
SteamCommunity.PersonaState = {
	"Offline": 0,
	"Online": 1,
	"Busy": 2,
	"Away": 3,
	"Snooze": 4,
	"LookingToTrade": 5,
	"LookingToPlay": 6,
	"Max": 7
};

SteamCommunity.PersonaStateFlag = {
	"HasRichPresence": 1,
	"InJoinableGame": 2,
	
	"OnlineUsingWeb": 256,
	"OnlineUsingMobile": 512,
	"OnlineUsingBigPicture": 1024
};

To get a URL from an avatar hash, use SteamCommunity.CSteamUser.getAvatarURL(hash[, size][, protocol]), where size is one of full, medium, icon (default icon) and protocol is one of http://, https://, // (default http://).

chatMessage

  • sender - The sender's SteamID, as a SteamID object
  • text - The message text

Emitted when we receive a new chat message.

chatTyping

  • sender - The sender's SteamID, as a SteamID object

Emitted when we receive a notification that someone is typing a message.

chatLoggedOff

Emitted in response to a chatLogoff() call when we successfully logged off.