Embed a customizable in-app notification center in your web app. Courier Inbox seamlessly integrates with email, SMS, push, and more.
This is the latest version of the Courier Web Components SDK, recommended for new and existing apps.Coming from an earlier version? We recommend upgrading — check out the
migration guide for the React SDK, which
is a thin wrapper around Inbox Web Components and exposes a similar API.
To use the SDK, you need to generate a JWT (JSON Web Token) for your user. This JWT should always be generated by your backend server, never in client-side code.
When your app needs to authenticate a user, your client
should make a request to your own backend (ex. GET https://your-awesome-app.com/api/generate-courier-jwt).
Importing the Courier SDK registers Courier’s Web Components (<courier-inbox>, <courier-inbox-popup-menu>).
Copy
Ask AI
<body> <courier-inbox id="inbox"></courier-inbox> <script type="module"> import { Courier } from '@trycourier/courier-ui-inbox'; // Generate a JWT for your user on your backend server const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Authenticate the user with the inbox Courier.shared.signIn({ userId: $YOUR_USER_ID, jwt: jwt }); </script></body>
Importing the Courier SDK registers Courier’s Web Components (<courier-inbox>, <courier-inbox-popup-menu>).
Copy
Ask AI
<body> <div style="padding: 24px;"> <courier-inbox-popup-menu id="inbox"></courier-inbox-popup-menu> </div> <script type="module"> import { Courier } from '@trycourier/courier-ui-inbox'; // Generate a JWT for your user on your backend server const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Authenticate the user with the inbox Courier.shared.signIn({ userId: $YOUR_USER_ID, jwt: jwt }); </script></body>
<body> <courier-inbox id="inbox"></courier-inbox> <!-- Uncomment the line below to use the popup menu instead --> <!-- <courier-inbox-popup-menu id="inbox"></courier-inbox-popup-menu> --> <script type="module"> import { Courier } from '@trycourier/courier-ui-inbox'; // Generate a JWT for your user on your backend server const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Authenticate the user with the inbox Courier.shared.signIn({ userId: $YOUR_USER_ID, jwt: jwt }); const inbox = document.getElementById('inbox'); // Handle message clicks inbox.onMessageClick(({ message, index }) => { alert("Message clicked at index " + index + ":\n" + JSON.stringify(message, null, 2)); }); // Handle message action clicks (these are buttons on individual messages) inbox.onMessageActionClick(({ message, action, index }) => { alert( "Message action clicked at index " + index + ":\n" + "Action: " + JSON.stringify(action, null, 2) + "\n" + "Message: " + JSON.stringify(message, null, 2) ); }); // Handle message long presses (useful for mobile web) inbox.onMessageLongPress(({ message, index }) => { alert("Message long pressed at index " + index + ":\n" + JSON.stringify(message, null, 2)); }); </script></body>
<courier-inbox> has a default height of auto, meaning it will set its height based on its children.
Give the inbox a fixed height by setting the height attribute.
Customize the inbox header by passing an HTML element to the setHeader method
on the <courier-inbox> component.Call removeHeader to remove the header entirely.In the default header, the feed type is selectable. Call setFeedType to
programmatically change the feed type between 'inbox' and 'archive'.
Custom inbox header
Copy
Ask AI
<body> <courier-inbox id="inbox"></courier-inbox> <script type="module"> // Reference the courier-inbox element const inbox = document.getElementById('inbox'); // Set a custom header inbox.setHeader(({ feedType, unreadCount, messageCount }) => { const headerDiv = document.createElement('div'); headerDiv.style.background = 'red'; headerDiv.style.fontSize = '24px'; headerDiv.style.padding = '24px'; headerDiv.style.width = '100%'; headerDiv.textContent = feedType; return headerDiv; }); // Uncomment the line below to remove the header // inbox.removeHeader(); // Uncomment the line below to set the feed type to 'archive' // inbox.setFeedType('archive'); </script></body>
Loading, Empty, Error States and Custom Pagination
Customize the inbox loading, empty, error states and pagination item by passing an
HTML element to the setLoadingState, setEmptyState, setErrorState, and
setPaginationItem methods.
Subsequent pages of messages are loaded automatically when the user scrolls to the bottom of the inbox,
so the pagination component may only be visible briefly.
Custom pagination state
Copy
Ask AI
<body> <courier-inbox id="inbox"></courier-inbox> <script type="module"> // Reference the courier-inbox element const inbox = document.getElementById('inbox'); // Set a custom loading state inbox.setLoadingState(props => { const loading = document.createElement('div'); loading.style.padding = '24px'; loading.style.background = 'red'; loading.textContent = 'Custom Loading State'; return loading; }); // Set a custom empty state inbox.setEmptyState(props => { const empty = document.createElement('div'); empty.style.padding = '24px'; empty.style.background = 'green'; empty.textContent = 'Custom Empty State'; return empty; }); // Set a custom error state inbox.setErrorState(props => { const error = document.createElement('div'); error.style.padding = '24px'; error.style.background = 'blue'; error.textContent = 'Custom Error State'; return error; }); // Set a custom pagination state inbox.setPaginationItem(props => { const pagination = document.createElement('div'); pagination.style.padding = '24px'; pagination.style.background = '#f0f0f0'; pagination.style.textAlign = 'center'; pagination.textContent = '🔄 Loading the next page of messages'; return pagination; }); </script></body>