Join a room
Joining a room is how a user becomes an active participant: it registers their presence, returns the room’s current state, and hands you the cursor you’ll use to stream new events.
You need an authenticated user first — see authentication models. The join call itself is the same regardless of which model minted the session.
import { ChatClient } from 'sportstalk-sdk';
// Public app id only. userToken comes from whichever auth model you chose.const client = ChatClient.init({ appId: APP_ID });client.setUserToken(userToken);
// Tell the SDK who's joining — the server rejects an end-user token whose// asserted identity doesn't match the userid in the join request.client.setUser({ userid: 'u-8842', handle: 'dave_m', displayname: 'Dave' });
// live-event-chat is a custom ID chosen by your application.const { room } = await client.joinRoomByCustomId('live-event-chat');
console.log('TalkLabs room ID:', room.id);POST /api/v3/{appid}/chat/roomsbycustomid/{customid}/join — the body describes
the user; the Authorization header carries their token.
using System.Net.Http.Headers;using System.Text;using System.Text.Json;
using var http = new HttpClient();http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userToken);
var payload = new { userid = "u-8842", handle = "dave_m", displayname = "Dave" };
var res = await http.PostAsync( $"https://api.sportstalk247.com/api/v3/{appId}/chat/roomsbycustomid/live-event-chat/join", new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json"));
res.EnsureSuccessStatusCode();Console.WriteLine(await res.Content.ReadAsStringAsync());const res = await fetch( `https://api.sportstalk247.com/api/v3/${appId}/chat/roomsbycustomid/live-event-chat/join`, { method: 'POST', headers: { 'Authorization': `Bearer ${userToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ userid: 'u-8842', handle: 'dave_m', displayname: 'Dave', }), },);
if (!res.ok) throw new Error(`join failed: ${res.status}`);const { data } = await res.json();console.log('cursor:', data.eventscursor); // save for listeningconsole.log('TalkLabs room ID:', data.room.id); // use for room operationspayload, _ := json.Marshal(map[string]string{ "userid": "u-8842", "handle": "dave_m", "displayname": "Dave",})
url := fmt.Sprintf( "https://api.sportstalk247.com/api/v3/%s/chat/roomsbycustomid/live-event-chat/join", appID)
req, _ := http.NewRequest("POST", url, bytes.NewReader(payload))req.Header.Set("Authorization", "Bearer "+userToken)req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)if err != nil { panic(err)}defer res.Body.Close()fmt.Println("status:", res.Status)curl -X POST \ "https://api.sportstalk247.com/api/v3/$APP_ID/chat/roomsbycustomid/live-event-chat/join" \ -H "Authorization: Bearer $USER_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "userid": "u-8842", "handle": "dave_m", "displayname": "Dave" }'The response includes the room, the participant count, and an events cursor. Hold onto that cursor — it’s the starting point for listening for events.