Send your first message
Use the trusted TypeScript server client to create the minimum safe messaging flow.
1. Install the SDK
npm install @vchatsdk/sdk-typescript2. Create a trusted client
import { AppServerClient } from '@vchatsdk/sdk-typescript';
const vchatConfig = readValidatedVChatConfig();
const chat = new AppServerClient({
baseUrl: 'https://api.example.com',
tenantId: vchatConfig.tenantId,
appId: vchatConfig.appId,
environment: 'production',
credential: async () => vchatConfig.applicationCredential,
});3. Create the messaging resources
await chat.appUsers.upsert('user-123', {
displayName: 'Ada Lovelace',
custom: { plan: 'pro' },
});
await chat.channels.create('messaging', 'support-123', {
displayName: 'Customer support',
custom: { topic: 'Onboarding' },
});
await chat.channelMemberships.add(
'messaging',
'support-123',
'user-123',
{ custom: { role: 'customer' } },
);Channel type and channel IDs are fixed identities. Treat foreign or denied resources as not found, and do not infer authorization from cached rows.
4. Send a message and issue a token
const sent = await chat.messages.send(
'messaging',
'support-123',
{ text: 'Hello from V Chat' },
{ messageId: crypto.randomUUID() },
);
const session = await chat.appUsers.issueToken({
userId: 'user-123',
lifetimeSeconds: 3600,
});
return {
message: sent.data.message,
token: session.data.token,
expiresAt: session.data.expiresAt,
};