[Busy API] Adding support for Expo Notifications
Courtesy of @busy.org and expo.io
Repository
https://github.com/busyorg/busy-api
1. Features Added
I worked on adding support for sending notifications to registered Expo devices. More precisely, the features include -
- Adding endpoints to register/unregister Expo tokens.
- Sending push notifications to devices while streaming the blockchain.
2. The Requirement / Problem Statement
busyorg/busy#1872
bSteem uses its own notification server to process them, while Busy maintains a different one. Since this is all repetitive, the two APIs could be combined to serve notifications from the same source of truth.
3. Implementation Details
3.1. Registering/Unregistering Expo Tokens
expo-server-sdk
is used to handle all the operations related to Expo.
3.1.1. Expo Push Tokens
Expo push tokens (or simply Expo tokens) are strings that are used to uniquely identify Expo devices. This helps in sending push notifications uniquely to the registered devices with ease, irrespective of the platform on which the app is running (Android or iOS).
Expo tokens are typically stored on the server side (Source)
3.1.2. Validating Tokens
busy-api
uses express
as the web framework. In order to verify tokens on the notification related endpoints, a custom middleware is used -
3.1.3. Parsing Request Body as JSON
To parse the request body, body-parser
was added.
This would parse body as JSON whenever the Content-Type
header is set to application/json
.
3.1.3. Authenticating Users
Users are authenticated using the SteemConnect access_token
that is sent with the request in Authorization
header. A custom middleware was again used for this purpose -
Both the middlewares are taken from bsteem-notifications, originally written by @Sekhmet.
3.1.4. Storing Expo tokens on Server
Expo tokens are stored in the Redis datastore on the server. The key namespace looks like tokens:{username}
and its value includes SET
of tokens. Using SET helps in preventing duplicate tokens from getting registered (which would, in turn, result in duplicate notifications).
3.2. Getting Notifications for a User
To get all notifications from a user, the /notifications
endpoint was introduced. This would again use the user authentication middleware and return all the notifications that are stored in the Redis store for the requesting user.
3.3. Sending Pushing Notifications
- Push notifications are sent whenever a Steem block is parsed.
- The message for notification is generated by parsing it. Notifications will be sent for follow, reply, transfer, vote, reblog and mention.
- Tokens to push to are fetched from the Redis store based on the users to notify. One user can have multiple tokens for multiple devices. In this case, all devices will be notified.
Pull Request
https://github.com/busyorg/busy-api/pull/12
Github Account
https://github.com/singhpratyush
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Hi @helo!
Thanks for reviewing. Will surely add more comments next time.
Hey @singhpratyush
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!