Open edzillion opened 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.
infrastructure-provisioning/circles-sns
repo holds the terraform build for the SNS resources, as well as a test server (which I will remove now).circles-sns
repo holds the code for this test server. This is now redundant as I have moved things to lambda but could be used for an sns microservice in future if that was the route we take.circles-lambdas
contains the confirmUser()
function which calls the sns function to register a device endpoint (so that we can message this user later):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.
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
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