<center>  *Courtesy of @busy.org and [expo.io](https://expo.io/)* </center> #### Repository https://github.com/busyorg/busy-api --- # 1. Features Added I worked on adding support for sending notifications to registered [Expo](https://expo.io) devices. More precisely, the features include - 1. Adding endpoints to register/unregister Expo tokens. 2. Sending push notifications to devices while streaming the blockchain. --- # 2. The Requirement / Problem Statement <center>  [busyorg/busy#1872](https://github.com/busyorg/busy/issues/1872) </center> [bSteem](https://play.google.com/store/apps/details?id=com.bsteem.bsteemapp) uses its own [notification server](https://github.com/Sekhmet/bsteem-notifications/) to process them, while Busy maintains [a different one](https://github.com/busyorg/busy-api). 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`](https://github.com/expo/exponent-server-sdk-node) 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). <center> https://docs.expo.io/static/images/generated/v28.0.0/guides/saving-token.png Expo tokens are typically stored on the server side [(Source)](https://docs.expo.io/versions/latest/guides/push-notifications) </center> ### 3.1.2. Validating Tokens `busy-api` uses [`express`](https://expressjs.com/) 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](https://github.com/Sekhmet/bsteem-notifications/tree/master/src/middlewares), originally written by @Sekhmet. ### 3.1.4. Storing Expo tokens on Server Expo tokens are stored in the [Redis](https://redis.io/) datastore on the server. The key namespace looks like `tokens:{username}` and its value includes [`SET`](https://redis.io/commands/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 --- > Thanks to @fabien and @Sekhmet for helping with this patch.
author | singhpratyush |
---|---|
permlink | busy-api-adding-support-for-expo-notifications |
category | utopian-io |
json_metadata | {"community":"busy","app":"busy/2.5.2","format":"markdown","tags":["utopian-io","development","busy","bsteem","steem"],"users":["busy.org","Sekhmet.","fabien","Sekhmet"],"links":["/@busy.org","https://expo.io/","https://github.com/busyorg/busy-api","https://expo.io","https://github.com/busyorg/busy/issues/1872","https://play.google.com/store/apps/details?id=com.bsteem.bsteemapp","https://github.com/Sekhmet/bsteem-notifications/","https://github.com/busyorg/busy-api","https://github.com/expo/exponent-server-sdk-node","https://docs.expo.io/versions/latest/guides/push-notifications"],"image":["https://ipfs.busy.org/ipfs/QmXe3UFtX7BtBcZwHJ66i5wNrK2wRB6VAia6wJJ22g3np7","https://ipfs.busy.org/ipfs/QmfFhk6TiqWbt2j6GixAfNk7L6Bq2UJELLvXqnodCiTnNM","https://docs.expo.io/static/images/generated/v28.0.0/guides/saving-token.png","https://ipfs.busy.org/ipfs/QmW3rtbPfUn3FtCLcH5g5iaNnXjXZnvKKuKaEV7qetAzVC","https://ipfs.busy.org/ipfs/QmRu4mc8NMaPu3cZpYdAuWkrXrWnWShR8PQa6DfiCxedn4","https://ipfs.busy.org/ipfs/QmZWUKKjaF61TcwR1p6d3UQKma8vzTGQGjou4QFqv7omXn","https://ipfs.busy.org/ipfs/QmcQLbGF6VxAsdshGsA6KzmyBEpbsFHdAUouDxrEEraCZi"]} |
created | 2018-07-12 10:00:09 |
last_update | 2018-07-12 10:07:12 |
depth | 0 |
children | 3 |
last_payout | 2018-07-19 10:00:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 119.617 HBD |
curator_payout_value | 39.566 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 4,277 |
author_reputation | 7,035,648,262,478 |
root_title | "[Busy API] Adding support for Expo Notifications" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,390,802 |
net_rshares | 72,256,148,135,976 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
fabien | 0 | 2,298,285,691,010 | 100% | ||
yuxi | 0 | 2,982,159,241 | 10% | ||
achiron | 0 | 16,516,325,657 | 100% | ||
busy.org | 0 | 3,905,279,050 | 0.15% | ||
miniature-tiger | 0 | 97,358,708,806 | 100% | ||
sekhmet | 0 | 142,116,581,901 | 100% | ||
helo | 0 | 11,451,999,718 | 100% | ||
doughtaker | 0 | 18,476,111,917 | 100% | ||
bachuslib | 0 | 17,643,574,862 | 100% | ||
dreamarif | 0 | 460,732,651 | 50% | ||
alexzicky | 0 | 6,856,505,002 | 15% | ||
leir | 0 | 699,744,201 | 20% | ||
buckydurddle | 0 | 20,488,470,019 | 100% | ||
utopian-io | 0 | 69,496,143,510,599 | 45.51% | ||
steemtaker | 0 | 20,881,825,902 | 50% | ||
the-dragon | 0 | 2,217,682,685 | 100% | ||
shreya26 | 0 | 0 | 100% | ||
singhpratyush | 0 | 3,718,501,770 | 100% | ||
folly-pandy | 0 | 433,495,381 | 1% | ||
rajatdangi | 0 | 608,647,236 | 100% | ||
nileshchaturvedi | 0 | 0 | 100% | ||
amosbastian | 0 | 56,882,966,213 | 100% | ||
tdre | 0 | 5,566,581,316 | 100% | ||
ansarimofid | 0 | 611,243,358 | 100% | ||
charisman | 0 | 213,975,731 | 50% | ||
magpielover | 0 | 141,490,862 | 100% | ||
crypto-mammoth | 0 | 9,528,639,807 | 100% | ||
liberviarum | 0 | 3,594,827,360 | 25% | ||
mirkosche | 0 | 517,320,212 | 100% | ||
reazuliqbal | 0 | 13,318,289,215 | 50% | ||
hackerzizon | 0 | 102,306,281 | 1% | ||
statsexpert | 0 | 831,568,460 | 20% | ||
mhossain | 0 | 295,241,981 | 50% | ||
javicuesta | 0 | 1,330,846,515 | 50% | ||
unittestaccount | 0 | 575,648,762 | 100% | ||
tanzil2020 | 0 | 82,589,161 | 25% | ||
fuzzythumb | 0 | 327,532,618 | 100% | ||
boomtube | 0 | 295,719,293 | 50% | ||
bdcommunity2 | 0 | 454,756,911 | 100% | ||
gamerbd | 0 | 462,740,925 | 100% | ||
jetenculeprofond | 0 | -231,696,613 | -100% |
* Very beautiful post, I love the images frames. * Great coding as well, lets add more comments next time. Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/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](https://review.utopian.io/result/3/1211114). ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | helo |
---|---|
permlink | re-singhpratyush-busy-api-adding-support-for-expo-notifications-20180713t164750625z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/3/1211114","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-07-13 16:47:51 |
last_update | 2018-07-13 16:47:51 |
depth | 1 |
children | 1 |
last_payout | 2018-07-20 16:47:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.016 HBD |
curator_payout_value | 0.003 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 598 |
author_reputation | 121,547,934,535,311 |
root_title | "[Busy API] Adding support for Expo Notifications" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,556,745 |
net_rshares | 9,339,870,729 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 5,254,553,552 | 5% | ||
cheneats | 0 | 150,394,669 | 1% | ||
singhpratyush | 0 | 3,934,922,508 | 100% |
Hi @helo! Thanks for reviewing. Will surely add more comments next time.
author | singhpratyush |
---|---|
permlink | re-helo-re-singhpratyush-busy-api-adding-support-for-expo-notifications-20180713t185756393z |
category | utopian-io |
json_metadata | {"community":"busy","app":"busy/2.5.2","format":"markdown","tags":["utopian-io"],"users":["helo"],"links":["/@helo"],"image":[]} |
created | 2018-07-13 18:58:00 |
last_update | 2018-07-13 18:58:00 |
depth | 2 |
children | 0 |
last_payout | 2018-07-20 18:58:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 73 |
author_reputation | 7,035,648,262,478 |
root_title | "[Busy API] Adding support for Expo Notifications" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,569,981 |
net_rshares | 0 |
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.** <a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
author | utopian-io |
---|---|
permlink | re-busy-api-adding-support-for-expo-notifications-20180714t175008z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-07-14 17:50:09 |
last_update | 2018-07-14 17:50:09 |
depth | 1 |
children | 0 |
last_payout | 2018-07-21 17:50:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 305 |
author_reputation | 152,955,367,999,756 |
root_title | "[Busy API] Adding support for Expo Notifications" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,673,659 |
net_rshares | 5,838,392,836 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 5,838,392,836 | 5% |