Skip to content

Room Chat

Room Chat is a real-time, room-based chat system. You can join a room, send/receive messages, and query message history.

roomChat.join

Joins a chat room and returns a RoomChatHandle.

roomName is optional:

  • If provided: The host automatically prefixes it with the miniApp ID (e.g., "lobby""com.example.game_lobby"). This ensures rooms with the same name from different games don't collide.
  • If omitted: Automatically derived from the active match (e.g., "match_abc123"). In this case, persistence is automatically set to false since match chats are temporary.
js
// Optional: with roomName (lobby, waiting-room, etc.)
const chat = await gameTegra.roomChat.join('lobby')

// Optional: with additional parameters
const chat = await gameTegra.roomChat.join('match-room', {
  persistence: true,  // Should messages be persisted
  hidden: false       // Should user appear in presence
})

// Without roomName — auto-derived from active match
const chat = await gameTegra.roomChat.join()
csharp
var chat = await gameTegra.RoomChat.Join("lobby");

// or with additional parameters
var chat = await gameTegra.RoomChat.Join("match-room",
    persistence: true,
    hidden: false
);

// Without roomName
var chat = await gameTegra.RoomChat.Join();
gdscript
var chat = await gameTegra.roomChat.join("lobby")

# or with additional parameters
var chat = await gameTegra.roomChat.join("match-room", true, false)

# Without roomName
var chat = await gameTegra.roomChat.join()

Parameters:

FieldTypeRequiredDefaultDescription
roomNamestringNo-Room name. If omitted, derived from active match. Automatically prefixed with miniAppId by the host.
persistencebooleanNotrueWhether messages should be persisted. Automatically false for match-based rooms.
hiddenbooleanNofalseWhether user is hidden in the presence list

Return Type: RoomChatHandle

Room Name Isolation

Room names are automatically prefixed with the miniApp ID by the host. So just writing "lobby" is enough — different games' lobbies won't collide.

Match Chats

When you call roomChat.join() without a roomName, the active match is automatically detected and a temporary chat room is created (persistence: false). Messages are lost when the match ends.


openMatchChat

Opens a group chat screen for players in the current match. This method shows a native chat UI on the Flutter side.

room_name is optional:

  • If provided: Prefixed with miniApp ID, persistence: true.
  • If omitted: Auto-derived from active match, persistence: false.
js
// Without roomName — auto-derived from active match
await gameTegra.openMatchChat()

// With roomName (e.g., lobby)
await gameTegra.openMatchChat({ room_name: 'lobby' })
csharp
await gameTegra.OpenMatchChat();

// With roomName
await gameTegra.OpenMatchChat(roomName: "lobby");
gdscript
await gameTegra.open_match_chat()

# With roomName
await gameTegra.open_match_chat({ "room_name": "lobby" })

Parameters:

FieldTypeRequiredDefaultDescription
room_namestringNo-Room name. If omitted, derived from active match ID.

Return Type: { success: boolean, room_name: string, player_count: number }


RoomChatHandle

The object returned from roomChat.join(). Used for interacting with the room.

Properties

PropertyTypeDescription
roomNamestringRoom name (resolved, may be empty)
channelIdstringChannel ID
streamKeystringStream key

send

Sends a message to the room.

js
// String message
await chat.send('Hello!')

// Object message
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" },
    { "action", "attack" }
});
gdscript
await chat.send("Hello!")

# or object
await chat.send({
    "type": "game_action",
    "action": "attack"
})

Parameters:

FieldTypeRequiredDescription
contentanyYesMessage content to send

getHistory

Gets message history.

js
const history = await chat.getHistory(50)

// With pagination
const history = await chat.getHistory(20, 'cursor-token', true)
csharp
var history = await chat.GetHistoryAsync(limit: 50);

// With pagination
var history = await chat.GetHistoryAsync(
    limit: 20,
    cursor: "cursor-token",
    forward: true
);
gdscript
var history = await chat.get_history(50)

# With pagination
var history = await chat.get_history(20, "cursor-token", true)

Parameters:

FieldTypeRequiredDefaultDescription
limitnumberNo50Number of messages to retrieve
cursorstringNo""Pagination cursor
forwardbooleanNofalseWhether to paginate forward

Event Listening

message

Triggered when a new message arrives in the room.

js
const unsub = chat.on('message', (data) => {
  console.log('New message:', data)
})

// Stop listening
unsub()
csharp
Action unsub = chat.On("message", (data) => {
    Debug.Log($"New message: {data}");
});

// Stop listening
unsub();
gdscript
var unsub = chat.on("message", func(data):
    print("New message: ", data)
)

# Stop listening: unsub.call()

presence

User join/leave events.

js
chat.on('presence', (data) => {
  console.log('Presence change:', data)
})
csharp
chat.On("presence", (data) => {
    Debug.Log($"Presence: {data}");
});
gdscript
chat.on("presence", func(data):
    print("Presence: ", data)
)

leave

Leaves the chat room and cleans up all listeners.

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

Full Example

js
// Join a room (roomName is optional)
const chat = await gameTegra.roomChat.join('game-lobby')

// Listen for messages
chat.on('message', (msg) => {
  console.log(`[${msg.sender}]: ${msg.content}`)
})

// Listen for presence changes
chat.on('presence', (event) => {
  console.log('Player join/leave:', event)
})

// Get past messages
const history = await chat.getHistory(20)
console.log('Last 20 messages:', history)

// Send a message
await chat.send({ text: 'Let the game begin!' })

// Leave the room
await chat.leave()

Match Chat (Automatic)

js
// Without roomName — active match is auto-detected
const chat = await gameTegra.roomChat.join()

chat.on('message', (msg) => {
  console.log(`[${msg.sender}]: ${msg.content}`)
})

await chat.send({ text: 'GG!' })

// or with native UI
await gameTegra.openMatchChat()