Skip to content

Room Chat

Real-time room-based chat — join rooms, send messages, and listen to events.

RoomChatHandle

roomChat.join() returns a RoomChatHandle object. The methods below (send, getHistory, on, leave) are called on that handle.

PropertyTypeDescription
roomNamestringResolved room name
channelIdstringChannel ID
streamKeystringStream key

roomChat.join

Joins or creates a named room chat channel. Returns a handle for sending/receiving messages.

js
const chat = await gametegra.roomChat.join('lobby', { persistence: true, hidden: false })
chat.on('message', (msg) => console.log(msg))
chat.send('Hello!')
csharp
var chat = await gametegra.joinRoomChat("lobby", true, false);
chat.OnMessage += (msg) => Debug.Log(msg);
gdscript
var chat = await gametegra.joinRoomChat('lobby', true, false)
chat.on('message', func(msg): print(msg))

Parameters:

NameTypeRequiredDescription
roomNamestringNoName of the chat room to join. Defaults to the current match room.
persistencebooleanNoWhether messages should be persisted on the server.
hiddenbooleanNoWhether the user joining should be hidden from presence events.

Response:

json
{
  "roomName": "lobby",
  "channelId": "2...2038553363867504640_lobby",
  "streamKey": "room-chat-lobby"
}

roomChat.send

Sends a message to the chat room. Called on the handle returned by roomChat.join().

js
await chat.send("Hello!")
// or object
await chat.send({ type: "game_action", action: "attack", target: "player2" })
csharp
await chat.SendAsync("Hello!");
// or object
await chat.SendAsync(new Dictionary<string, object> { { "type", "game_action" } });
gdscript
await chat.send("Hello!")
# or object
await chat.send({ "type": "game_action", "action": "attack" })

Parameters:

NameTypeRequiredDescription
content`stringobject`Yes

Response:

json
{
  "success": true
}

roomChat.getHistory

Retrieves past messages from the chat room. Called on the handle returned by roomChat.join().

js
const history = await chat.getHistory(20)
// with pagination
const history = await chat.getHistory(20, "cursor-token", true)
csharp
var history = await chat.GetHistoryAsync(limit: 20);
// with pagination
var history = await chat.GetHistoryAsync(limit: 20, cursor: "cursor-token", forward: true);
gdscript
var history = await chat.get_history(20)

Parameters:

NameTypeRequiredDescription
limitnumberNoNumber of messages to retrieve. Defaults to 50.
cursorstringNoPagination cursor from a previous response.
forwardbooleanNoPaginate forward if true, backward if false. Defaults to false.

Response:

json
{
  "messages": [
    {
      "sender": "player1",
      "content": "Hello!",
      "createTime": "2026-04-01T10:00:00Z"
    },
    {
      "sender": "player2",
      "content": "GG!",
      "createTime": "2026-04-01T10:00:05Z"
    }
  ],
  "nextCursor": null,
  "prevCursor": null
}

roomChat.on

Registers an event listener on the chat handle. Supported events: message, presence, error, end. Called on the handle returned by roomChat.join().

js
const unsub = chat.on("message", (msg) => {
  console.log(msg.sender, msg.content)
})
// stop listening
unsub()
csharp
Action unsub = chat.On("message", (data) => {
    Debug.Log(data);
});
unsub();
gdscript
var unsub = chat.on("message", func(msg):
    print(msg.sender, msg.content)
)

Parameters:

NameTypeRequiredDescription
event`string ("message""presence""error"
handlerfunctionYesCallback function receiving the event data.

Response:

json
{
  "sender": "player2",
  "content": "Ready!",
  "createTime": "2026-04-01T10:00:10Z"
}

roomChat.leave

Leaves the chat room and cleans up all event listeners. Called on the handle returned by roomChat.join().

js
await chat.leave()
csharp
await chat.LeaveAsync();
gdscript
await chat.leave()

Response:

json
{
  "success": true
}