What a User is
A User is a person in your application who sends and receives messages through Surge’s embeddable UI components. You create Users through the Surge API or the dashboard, and each one belongs to a specific account. They are separate from people who log in tohq.surge.app.
If you’re building a SaaS platform where your customers interact with Surge-powered messaging, Users are typically your customers’ employees, not your customers’ own customers.
Users are used in two ways:
- Embedded UI: the inbox and conversation components authenticate as a specific User, showing that user’s conversations and sending messages on their behalf
- Attribution: messages and calls can be tied to a User, so you can trace activity back to the individual
Provision a User
Create a User via the API before you mount any components for them:id alongside the user’s record in your database. You’ll use it to generate component tokens and attribute messages.
Create a User in the dashboard
You can also create Users without writing code. In the Surge dashboard athq.surge.app, open the account and select Embed users in the sidebar, then click New embed user. Enter a first name and an optional last name. Click Add metadata for each key-value pair you want to store, then click Create user. Copy the User ID from the user’s details page to use with the token endpoint.
Generate a component token
Your server generates a short-lived JWT for each user session. The JWT scopes the embedded component to that specific user’s data. The simplest path is the token endpoint:Typical vertical SaaS flow
- When one of your customer’s employees is added to your SaaS product, create a Surge User via
POST /accounts/{account_id}/users. Store theid. - When that employee loads a page in your app that includes embedded messaging, your server calls
POST /users/{user_id}/tokensto get a fresh JWT. - Your frontend receives the JWT and mounts the Surge Inbox or Conversation component with it.
- The component shows only that user’s conversations and sends messages attributed to them.
List and manage Users
Next steps
Inbox component
Mount a conversation list for the current User.
Conversation component
Mount a single threaded conversation view.
Unread Count component
Show a live unread badge in your navigation.