strapi-plugin-notification-expo
v1.0.0-beta.5
Published
(Non-official) Expo notification for Strapi
Downloads
5
Readme
strapi-plugin-notification-expo
(Non-official) Strapi plugins to send Expo notifications
This plugin allow you to draft & publish Expo notification
Installation
Requirements
- Strapi >= 3.4.*
- NodeJS >= 12.x <= 14
- NPM >= 6.x
Install the package from your app root directory
- With
npm
npm install strapi-plugin-notification-expo
- or
yarn
yarn add strapi-plugin-notification-expo
Database information
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
🚀 Features
- 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)
🤖 Configuration
1. Enable cron - edit config/server.js
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
.
2. Build and re-launch Strapi
strapi build --clean
strapi dev
3. Enjoy the administration panel
List of all notifications (with pagination)
Add / edit notification
👾 Route, controllers, services
Add expo tokens
Method POST
- /notification-expo/expotokens
{
token, // ExponentPushToken[XXXaaaBBBCCCdddEEEfff]
platform // 'ios' | 'android'
}
Send expo notification from an existing service to specific users
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);
❓ FAQ
How to register expo token
from your Expo App to Strapi ?
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)))
🚧 Roadmap
- [ ] 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
🌟 Resources
License
Links
- Strapi website
- Strapi forum - ping @Lith
- Strapi community on Slack - ping @Lith
- Strapi news on Twitter