Closed bernhardt1 closed 1 year ago
I would like to send a push notification to certain users from a server programmaticaly. I feel like it's not yet supported (see here, push notifs are not listed). Is this being working on ? Thanks a lot!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@vparpoil Are you still looking for a solution to send push notifications programatically?
I've implemented them in my project and could detail my approach if you would like.
@bernhardt1 I'm interested in how you did. I ended up using Google Firebase Cloud Messaging system, I would be happy to know other approaches
I did something close to this: @vparpoil
var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
const pinpoint = new AWS.Pinpoint({ apiVersion: '2016-12-01', region: process.env.PINPOINT_REGION });
let whoSent;
let whoReceive;
let content = "tap to view message";
event && event.Records && event.Records.forEach((record) => {
console.log('Stream record: ', JSON.stringify(record, null, 2));
if (record.eventName == 'INSERT') {
whoSent = record.dynamodb.NewImage.senderUserId.S;
whoReceive = record.dynamodb.NewImage.receiverUserId.S;
content = record.dynamodb.NewImage.content.S;
}
});
// console.log(`executing push notification with content: ${content}, & receiver ${whoReceive}`);
const sendMessagesParams = {
ApplicationId: process.env.PINPOINT_APP_ID,
SendUsersMessageRequest: {
Users: {
[whoReceive]: {}
},
MessageConfiguration: {
APNSMessage: {
Action: 'OPEN_APP',
Title: 'You have a new message',
SilentPush: false,
Body: content
},
GCMMessage: {
Action: 'OPEN_APP',
Title: 'You have a new message',
SilentPush: false,
Body: content
}
}
}
};
pinpoint.sendUsersMessages(sendMessagesParams, (err, data) => {
// console.log('sendUsersMessages returned');
if (err) {
// console.log('AN ERROR OCCURED');
console.log(err, err.stack); // an error occurred
callback(null, 'error')
}
else {
// console.log('SEND MESSAGES SUCCEEDED');
// console.log(JSON.stringify(data)); // successful response
callback(null, 'success')
}
});
};
Does that make sense?
Hello! We have launched a new version of https://docs.amplify.aws/lib/push-notifications/getting-started/ for React Native, Swift, Android, and Flutter. You can follow this tutorial to learn more about programatically sending push notifications from your backend.
Is your feature request related to a problem? Please describe. Handling automatic push notifications seems to require somewhat hacky solutions. I have not been able to find a conventional approach to handle these notifications within amplify/ AWS mobile.
Describe the solution you'd like A tutorial or article explaining the conventional solution to automatic push notifications within amplify/AWS mobile suite.
Describe alternatives you've considered Based on tutorials and articles I've pieced together a solution. Something like: track if user is online/offline -> use appsync local resolver to catch desired notification and send to lambda -> use lambda to generate a 1-time pinpoint message.
Thanks in advance.