Real-Time Events
DialStack provides real-time event streaming via Server-Sent Events (SSE), enabling your application to receive instant notifications about incoming calls and other account activity.
Real-Time Events is the browser transport for call events. For the backend transport, see Webhook Events. For common patterns built on top, see Screen Pop and Activity Logging.
Overview
Real-time events allow you to:
- Show screen pops when calls arrive (caller ID, customer info)
- Update UI instantly without polling the API
- Build responsive applications that react to call activity in real-time
For backend integrations (CRM sync, analytics, workflow automation), see Receiving Webhooks for HTTP POST delivery with signature verification.
Each event on the stream carries the same fields as the matching webhook's data, flattened, with event in place of the envelope's type. SSE events carry no id, so they cannot be deduplicated by event ID the way webhooks can. See Event Types.
How It Works
DialStack uses Server-Sent Events (SSE), a standard web technology for streaming events from server to client:
- Your client opens a persistent HTTP connection to
/v1/events - DialStack pushes events to your client as they occur
- The connection stays open until your client disconnects
The stream is scoped to one account: it is authenticated with a session token for that account. To narrow it to a single user, authenticate with a user session token instead (see User-scoped streams).
Connecting to the Event Stream
Using the DialStack SDK (Recommended)
The SDK opens the stream for you, authenticates it, refreshes the session and reconnects with exponential backoff. It exposes the call.incoming event through on():
import { loadDialstackAndInitialize } from '@dialstack/sdk-js';
const dialstack = await loadDialstackAndInitialize({
publishableKey: 'pk_test_...',
fetchClientSecret: async () => {
const response = await fetch('/api/dialstack/session');
const { client_secret, expires_at } = await response.json();
return { clientSecret: client_secret, expiresAt: expires_at };
},
});
function onIncomingCall(event) {
console.log('Incoming call from:', event.from_number);
showScreenPop(event);
}
dialstack.on('call.incoming', onIncomingCall);
// Later, unsubscribe when done
dialstack.off('call.incoming', onIncomingCall);
The SDK also exposes call.ringing, which fires once for each user whose phones ring, including through a ring group or dial plan. Its user field tells you whose screen to pop:
dialstack.on('call.ringing', (event) => {
if (event.user === currentUser.dialstackId) {
showScreenPop(event);
}
});
The SDK reference lists the fields of IncomingCallEvent and RingingCallEvent. To receive the other event types below, read the stream directly.
Using fetch with ReadableStream
For direct API access without the SDK, use fetch with a readable stream:
async function connectToEvents(clientSecret) {
const response = await fetch('https://api.dialstack.ai/v1/events', {
headers: {
Authorization: `Bearer ${clientSecret}`,
Accept: 'text/event-stream',
},
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { value, done } = await reader.read();
if (done) break;
const text = decoder.decode(value);
const lines = text.split('\n');
for (const line of lines) {
if (line.startsWith('event: ')) {
const eventType = line.slice(7);
// Handle event type
} else if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
// Handle event data
}
}
}
}
When you read the stream yourself, reconnect when it drops, and fetch a fresh session token when the server answers 401.
User-scoped streams
An account session token gives every client all of the account's events, and your app decides which ones each user should see. If you'd rather have DialStack do that filtering, open the stream with a user session token, minted by your backend with POST /v1/user_sessions. Connect the same way, passing the user session token as the bearer token. With the SDK, return it from fetchClientSecret.
A user-scoped stream carries only the events whose user is that user. That includes call.ringing for each call that rings them, through a ring group or dial plan too, and the other events of calls they place or answer. The Event Reference says what user means on each event.
A call answered by someone else, or one that ends unanswered while others were also being rung, names another user or none, so its later events don't reach this stream. If your screen pop needs to close in those cases, use an account-scoped stream or webhooks.
A user-scoped stream closes when its token expires, or within about 15 minutes of the user's sessions being revoked. Reconnecting with that token is then answered with 401; mint a new one.
Event Types
Each event carries the data listed for it in the Event Reference, flattened, plus:
| Field | Description |
|---|---|
event | The event type, such as "call.ringing". The webhook envelope's type |
account | The account the event belongs to. Also sent under the deprecated account_id key |
timestamp | When the event was sent (ISO 8601) |
For example, a call.ringing event:
{
"event": "call.ringing",
"account": "acct_01h2xcejqtf2nbrexx3vqjhp41",
"account_id": "acct_01h2xcejqtf2nbrexx3vqjhp41",
"call_id": "call_01h2xcejqtf2nbrexx3vqjhp45",
"user": "user_01h2xcejqtf2nbrexx3vqjhp42",
"user_id": "user_01h2xcejqtf2nbrexx3vqjhp42",
"direction": "inbound",
"from_number": "+14155551234",
"from_name": "John Smith",
"to_number": "+14155559876",
"ringing_at": "2026-01-15T14:30:01Z",
"timestamp": "2026-01-15T14:30:01Z"
}
The stream carries these events. Each links to its data in the Event Reference:
| Event | Sent when |
|---|---|
call.incoming | An incoming call arrives for the account |
call.initiated | An outbound call starts dialing |
call.ringing | A user's phones are about to ring |
call.answered | A call is answered |
call.end | A call ends |
call.transfer | A call is transferred |
The stream also sends connected, with an empty object as its data, as soon as the connection is established. Other event types, such as call.emergency, are delivered only as webhooks.
Connection Management
The DialStack SDK reconnects with exponential backoff when the connection drops, and calls your fetchClientSecret again when the session needs refreshing. See Session tokens for session lifetime and refresh.
Best Practices
DO
- Use the DialStack SDK for automatic reconnection and session management
- Subscribe to events when your application loads
- Look up additional customer data when calls arrive for richer screen pops — see Screen Pop
- Call
dialstack.logout()when the user logs out or navigates away
DON'T
- Don't poll the API instead of using events (inefficient and delayed)
- Don't create multiple SDK instances for the same account
- Don't store the client secret long-term (it expires)
Related Resources
- API Reference - Complete API documentation
- Authentication - Authentication guide
- Sessions - Creating account sessions