How to Implement Courier Inbox
Inbox is an in-app notification center you can use to notify your users. Inbox allows you to build high quality, flexible notification feeds very quickly.
Courier Inbox
The Courier Inbox acts as a convenient in-app notification feed with a clean interface where users can view notifications in real time directly inside your web app. It also lets them view their message history of all past notifications that you’ve sent to them.
Installation
To integrate the Inbox feature, you’ll need a backend to retrieve messages. This functionality is managed through the CourierProvider
and requires an active Courier account.
Steps to Set Up Inbox:
Install the Courier Provider
Navigate to the Integrations page and install the Courier Provider.
Create a JWT
After installation, you’ll need a JWT to authenticate your users.
Configure the CourierProvider
Use JWTs to initialize and configure the CourierProvider in your application.
This setup enables seamless message retrieval for the Inbox.
JWTs
A JWT should be generated on a per-user basis in your backend and be supplied to your frontend. When using JWT authentication, be sure to enable JWT support on the Courier Inbox Provider
Inbox JWT
The recommended way of doing authentication with Courier Inbox is to generate a JWT token for each user using the inbox.
The required scopes are the following:
read:messages
- Courier can fetch the messageswrite:events
- Courier can create events like read/unread/archive
An example payload to the issue-token api looks like :
If you need your tokens to expire periodically you can pass an expires_in
property to the token generation.
CourierProvider
Install the following packages to get started:
@trycourier/react-provider
is a peer dependeny of @trycourier/react-inbox
and must also be installed
In order for the Inbox
component to be placed in the dom you will need to use the CourierProvider
. This will handle context and give us access Courier’s backend API.
The CourierProvider
& Inbox
hierarchy:
Implementation
To implement the Courier Inbox in a React application, you can use the @trycourier/react-inbox
package mentioned previously, which provides components for integrating a notification inbox seamlessly. Here’s a basic example:
Sending Inbox Messages
In your frontend, the Inbox
component will be visible straight away as a bell icon. Clicking this will initially show you an empty inbox until you start sending messages.
Inbox Icon
Send a Notification to Inbox
The fastest way to test this is to send a request to the Courier API.
You should now be able to see your message displayed in the Inbox.
Inbox First Message