CirclesUBI / circles-mobile

Circles react-native mobile client
GNU Affero General Public License v3.0
7 stars 2 forks source link

push notifications #12

Open edzillion opened 5 years ago

edzillion commented 5 years ago

Amazon offers a push notif service that should do the job. Some thinking about what users should be notified needs to be done before we can implement this fully

related to: https://github.com/CirclesUBI/circles-api/issues/32

edzillion commented 5 years ago

Looked into the various options and settled on Amazon SNS; which gives us fairly straightforward implementation of push messages to android / ios.

SNS requires that each client be registered with a deviceId. For the moment I am using Expo.Constants.deviceId but this will be changed to a native implementation later. I originally built a very basic express server to test this device registration, but then realised it could be done in the confirmUser lambda with a bit of work.

var sns = new AWS.SNS({apiVersion: '2010-03-31'})
exports.handler = (event, context, callback) => {
  var snsParams = {
    PlatformApplicationArn: process.env.ANDROID_ARN,
    Token: event.request.userAttributes.deviceId
  }

  sns.createPlatformEndpoint(snsParams, function (err, data) {
    if (err) console.log(err, err.stack)
    else console.log(data)
  })
}

This is as far as I have gotten, obviously we need a db table to associate userNames with these endpoints.

edzillion commented 5 years ago

The previous sns registration stuff was moved from the FE to the circles-api. We need to extend this somewhat and need a full notification api to simplify messaging to the various platforms etc, and on the frontend we will need a way to interpret these messages.

we could either go for this popular package https://github.com/zo0r/react-native-push-notification

tutorial here: https://medium.com/@thexap/show-push-notifications-on-react-native-app-a613a5a2c159

Or we could use amplify (perhaps with a redux saga to queue events etc):

https://aws-amplify.github.io/docs/js/push-notifications

related to: https://github.com/CirclesUBI/circles-api/issues/32