Subscription Flow
Once Telex Start successfully logs in using the user's credentials, it automatically initiates the subscription process for real-time notifications. This flow is fully managed by the starter app and involves three tightly connected steps:
Step 1: Retrieving User Organizations
After login, the app sends a request to retrieve the organizations the user belongs to.
Endpoint:
GET /api/v1/users/organisations
Headers:
Authorization: Bearer <access_token>
Response Example:
{
"data": [
{ "id": "org_123", "name": "CyberGroup" },
{ "id": "org_456", "name": "MarkTest" }
]
}
Each organization ID is used to construct a channel name in the format:
channel: <org_id>/<user_id>
These channels are used to subscribe to notifications.
Step 2: Requesting Subscription Tokens
For each channel, the app requests a subscription token using the notification token.
Endpoint:
POST /api/v1/centrifugo/subscription
Headers:
X-Notification-Token: <notification_token>
Body:
{
"channel": "org_123/user_789"
}
Response Example:
{
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
These tokens are stored in a map:
std::map<std::string, std::string> subscriptions;
subscriptions[channel] = subscriptionToken;
Step 3: Connecting to WebSocket
Once all subscription tokens are collected, the app connects to Centrifugo via WebSocket.
WebSocket URL:
wss://api.telex.im/centrifugo/connection/websocket
Connection Payload:
{
"connect": {
"token": "<connection_token>",
"subs": {
"org_123/user_789": { "token": "<subscription_token>" },
"org_456/user_789": { "token": "<subscription_token>" }
}
}
}
The app sends this payload immediately after the WebSocket Open event.
Receiving Notifications
Once connected, the app listens for push messages. If a message contains:
{
"notification_type": "unread_thread_change",
"data": {
"name": "General",
"description": "New reply in launch thread"
}
}
It dispatches a wxEVT_SHOW_NOTIFICATION event to the UI:
wxCommandEvent* event = new wxCommandEvent(wxEVT_SHOW_NOTIFICATION);
event->SetString(notification_data["name"]);
event->SetClientData(new wxStringClientData(notification_data["description"]));
wxQueueEvent(m_pParent, event);
This opens up the notification dialog box and displays the notification