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.
| Property | Type | Description |
|---|---|---|
roomName | string | Resolved room name |
channelId | string | Channel ID |
streamKey | string | Stream key |
roomChat.join
Joins or creates a named room chat channel. Returns a handle for sending/receiving messages.
const chat = await gametegra.roomChat.join('lobby', { persistence: true, hidden: false })
chat.on('message', (msg) => console.log(msg))
chat.send('Hello!')var chat = await gametegra.joinRoomChat("lobby", true, false);
chat.OnMessage += (msg) => Debug.Log(msg);var chat = await gametegra.joinRoomChat('lobby', true, false)
chat.on('message', func(msg): print(msg))Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
roomName | string | No | Name of the chat room to join. Defaults to the current match room. |
persistence | boolean | No | Whether messages should be persisted on the server. |
hidden | boolean | No | Whether the user joining should be hidden from presence events. |
Response:
{
"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().
await chat.send("Hello!")
// or object
await chat.send({ type: "game_action", action: "attack", target: "player2" })await chat.SendAsync("Hello!");
// or object
await chat.SendAsync(new Dictionary<string, object> { { "type", "game_action" } });await chat.send("Hello!")
# or object
await chat.send({ "type": "game_action", "action": "attack" })Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
content | `string | object` | Yes |
Response:
{
"success": true
}roomChat.getHistory
Retrieves past messages from the chat room. Called on the handle returned by roomChat.join().
const history = await chat.getHistory(20)
// with pagination
const history = await chat.getHistory(20, "cursor-token", true)var history = await chat.GetHistoryAsync(limit: 20);
// with pagination
var history = await chat.GetHistoryAsync(limit: 20, cursor: "cursor-token", forward: true);var history = await chat.get_history(20)Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
limit | number | No | Number of messages to retrieve. Defaults to 50. |
cursor | string | No | Pagination cursor from a previous response. |
forward | boolean | No | Paginate forward if true, backward if false. Defaults to false. |
Response:
{
"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().
const unsub = chat.on("message", (msg) => {
console.log(msg.sender, msg.content)
})
// stop listening
unsub()Action unsub = chat.On("message", (data) => {
Debug.Log(data);
});
unsub();var unsub = chat.on("message", func(msg):
print(msg.sender, msg.content)
)Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
event | `string ("message" | "presence" | "error" |
handler | function | Yes | Callback function receiving the event data. |
Response:
{
"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().
await chat.leave()await chat.LeaveAsync();await chat.leave()Response:
{
"success": true
}