(Non-official) Strapi plugins to send Expo notifications
This plugin allow you to draft & publish Expo notification
- Strapi >= 3.4.*
- NodeJS >= 12.x <= 14
- NPM >= 6.x
- With
npm
npm install strapi-plugin-notification-expo
- or
yarn
yarn add strapi-plugin-notification-expo
This plugin will add 3 tables into your project :
expotokens
: list of all Expo tokens (platform, "Expo push token", user)exponotifications
: list of all Notification with a stateexponotifications_users
: list of all users than will received the notification
- Admin panel to manage notification
- Build with Buffetjs.io
- Used
Draft and Publish
Strapi feature to send notification - Send notification to a group of users via the Admin panel
- Automatic publish with a dedicated cron as middleware call
cronExpo
- Set notification
read-only
if the notification has been sent
- Send notification to one user programmatically (from API services/controllers)
This project launch a Cron Task to check every 10 minutes if notification need to be send, so you need to enabled cron
in config/server.js
:
cron: {
enabled: true,
},
If you want disable cron task on staging or development environment, edit config/env/development/server.js
and disabled cron
.
strapi build --clean
strapi dev
Method POST
- /notification-expo/expotokens
{
token, // ExponentPushToken[XXXaaaBBBCCCdddEEEfff]
platform // 'ios' | 'android'
}
Put this code anywhere in API controllers / services
const notification = {
user: ctx.state.user.id, // id of the user, for this example I used id of the current connected user
title: '👍 Good job', // Notification title
body: 'You are awesome', // Message display in the notification
data: {
// additionnal data, JSON formatted, put what you need (their data are managed after into your Expo application)
// I use often the "url" data, when use click on the notification, this is open the good screen into the app
url: 'https://github.com/Lith/strapi-plugin-notification-expo',
}
};
await strapi.plugins['notification-expo'].services.expo.send(ctx, notification);
In your app, add some code to register the token linked to the user account on Strapi API :
Permissions
.askAsync(Permissions.NOTIFICATIONS)
.then(({status}) => {
if (status === 'granted') {
return Notifications.getExpoPushTokenAsync();
}
return Promise.reject();
})
.then((token) => {
return api
.post('/notification-expo/expotokens', {
token,
platform: Platform.OS
})
.catch((err) => {
if (err && err.statusCode === 409) {
return Promise.resolve();
} else {
return Promise.reject(err);
}
})
.then(() => dispatch(registerNotificationsTokenSuccess(
Notifications.addListener((notification) => {
dispatch(notify(notification))
})
)))
})
.catch((err) => dispatch(registerNotificationsTokenFail(err)))
- Manage
data
JSON object to send additional data into the notification - Manage redirect URL onclick on the notification
- Save anonymous expo token
- Remove a draft notification
- Duplicate an existing notification
- Change the status of a notification (when an error occurs)
- Schedule circle notification (sent every hour/day/week/month)
- Add Tests with Cypress
- Strapi website
- Strapi forum - ping @Lith
- Strapi community on Slack - ping @Lith
- Strapi news on Twitter