TalkerAdmin

Backend API for managing users, channels, and credentials. Use this class on your server to securely manage Talker resources.

Server-Side Only

TalkerAdmin requires your SDK key and should only be used on your backend server. Never expose your SDK key in client-side code.

Constructor

TypeScript
import { TalkerAdmin } from '@talker-network/talker-sdk';

const admin = new TalkerAdmin({
  sdkKey: string,       // Required: Your SDK key (keep secret!)
  baseUrl?: string,     // Optional: API base URL
});

Parameters

sdkKey Required string

Your Talker SDK key. Store this securely as an environment variable.

baseUrl Optional string

Custom API base URL. Defaults to Talker's production API.

User Management

createUser()

Create a new SDK user.

createUser(config: CreateUserConfig): Promise<UserData>
TypeScript
const user = await admin.createUser({
  name: 'John Doe',           // Required: Display name
  platform: 'WEB',            // Optional: 'WEB' | 'ANDROID' | 'IOS'
  fcmToken: 'token',          // Optional: Firebase token for push notifications
});

// Returns:
// {
//   userId: string,
//   name: string,
//   userAuthToken: string,    // Pass to TalkerClient
//   aUsername: string,        // Pass to TalkerClient
//   aPassword: string,        // Pass to TalkerClient
// }

Parameters

Parameter Type Required Description
name string Yes Display name for the user
platform 'WEB' | 'ANDROID' | 'IOS' No Platform identifier
fcmToken string No Firebase Cloud Messaging token for push notifications

setUser()

Get or switch to an existing user.

setUser(config: SetUserConfig): Promise<UserData>
TypeScript
const user = await admin.setUser({
  userId: 'existing-user-id',  // Required: Existing user ID
  platform: 'WEB',             // Optional
  fcmToken: 'token',           // Optional
});

getAllUsers()

Get all users in the workspace.

getAllUsers(): Promise<UserInfo[]>
TypeScript
const users = await admin.getAllUsers();

// Returns array of:
// {
//   id: string,
//   name: string,
//   platform: string,
// }

Channel Management

createChannel()

Create a new channel.

createChannel(config: CreateChannelConfig): Promise<{ channelId: string, channelName: string }>
TypeScript
const channel = await admin.createChannel({
  name: 'Team Chat',              // Required: Channel name
  participants: ['user1', 'user2'], // Required: User IDs
  workspaceId: 'workspace-id',    // Required: Workspace ID
  type: 'group',                  // Optional: 'group' | 'direct'
});

// Returns:
// {
//   channelId: string,
//   channelName: string,
// }

Parameters

Parameter Type Required Description
name string Yes Name of the channel
participants string[] Yes Array of user IDs to add as participants
workspaceId string Yes Workspace ID
type 'group' | 'direct' No Channel type (defaults to 'group')

updateChannelName()

Rename a channel.

updateChannelName(channelId: string, name: string): Promise<void>
TypeScript
await admin.updateChannelName('channel-id', 'New Channel Name');

Participant Management

Method Description Returns
addParticipant(channelId, userId) Add user to channel Promise<void>
removeParticipant(channelId, userId) Remove user from channel Promise<void>
addAdmin(channelId, userId) Make user a channel admin Promise<void>
removeAdmin(channelId, userId) Remove admin privileges Promise<void>
TypeScript
// Add a participant
await admin.addParticipant('channel-id', 'user-id');

// Remove a participant
await admin.removeParticipant('channel-id', 'user-id');

// Promote to admin
await admin.addAdmin('channel-id', 'user-id');

// Remove admin privileges
await admin.removeAdmin('channel-id', 'user-id');

Credentials

getCredentials()

Get SDK credentials.

getCredentials(): Promise<CredentialsData>

getWebRTCCredentials()

Get WebRTC credentials for a user.

getWebRTCCredentials(aUsername: string, aPassword: string): Promise<WebRTCCredentials>
TypeScript
const credentials = await admin.getCredentials();
const webrtcCreds = await admin.getWebRTCCredentials(aUsername, aPassword);

Complete Example

Here's a complete example of a Next.js API route:

pages/api/auth.ts
import { TalkerAdmin } from '@talker-network/talker-sdk';
import type { NextApiRequest, NextApiResponse } from 'next';

const admin = new TalkerAdmin({
  sdkKey: process.env.TALKER_SDK_KEY!,
});

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  try {
    const { userId, name } = req.body;

    let user;
    if (userId) {
      // Get existing user
      user = await admin.setUser({ userId });
    } else {
      // Create new user
      user = await admin.createUser({ name });
    }

    // Return credentials to frontend
    res.status(200).json({
      userAuthToken: user.userAuthToken,
      userId: user.userId,
      a_username: user.aUsername,
      a_password: user.aPassword,
    });
  } catch (error) {
    console.error('Auth error:', error);
    res.status(500).json({ error: 'Authentication failed' });
  }
}