embed.surge.app.
Available components
- Inbox: a list of all conversations for the current user, sortable and filterable
- Conversation: a single threaded conversation with send capability
- Unread count: a badge showing how many unread conversations the user has
- Phone (dialpad): a voice dialer for outbound calls (voice-enabled accounts)
Authentication
Each component mount requires a signed JWT. The JWT identifies which Surge account and user the component is showing data for.Two ways to get a JWT
Option 1: use the token endpoint (simpler) Call the user token endpoint from your server, then pass the resulting token to the component:Mounting a component
Each component is embedded as an iframe served fromembed.surge.app, with the token passed as a query parameter:
Rotating signed tokens
Because signed tokens are short-lived they may expire while users are still interacting with the embedded UI components authenticated with the expiring tokens. Connections will remain authenticated after their token has expired, but any reconnects will trigger re-authentication. We recommend rotating tokens just before they expire to ensure your components will continue to work.Token expiring warning
When an embedded UI component is authenticated with a token that is about to expire, it will emit an event warning of the pending expiration. This event will have the the type “token_expiring”:Updating a component’s token
Re-rendering the iframe with a new token in the URL could cause the component to lose necessary state, so embedded components also support an “update_token” message back into the iframe.Example
Here’s an example snippet of some JavaScript in your app for rotating tokens before they expire. In this examplerefreshSurgeToken is a made-up function that makes a request to your server for a new
token.
Next steps
Working with Users
How Users are provisioned and attributed to messages.
Inbox component
URL parameters and events for the conversation list.
Conversation component
Mounting a single thread inside your own page.
Unread Count component
Badge integration for navigation chrome.