Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to: Automatic/programmable push notifications #5061

Closed
bernhardt1 opened this issue Nov 28, 2018 · 6 comments
Closed

How to: Automatic/programmable push notifications #5061

bernhardt1 opened this issue Nov 28, 2018 · 6 comments
Labels
amplify/js Issues tied to JS feature-request Request a new feature transferred This issue was transferred from another Amplify project

Comments

@bernhardt1
Copy link

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.

@manueliglesias manueliglesias added the feature-request Request a new feature label Nov 28, 2018
@vparpoil
Copy link
Contributor

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!

@stale
Copy link

stale bot commented Jun 15, 2019

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.

@bernhardt1
Copy link
Author

@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.

@vparpoil
Copy link
Contributor

@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

@bernhardt1
Copy link
Author

bernhardt1 commented Jun 17, 2019

I did something close to this: @vparpoil

  1. Set up pinpoint notifications in the project + ensure test messaging is working for iOS and android
  2. I use appsync in my project - By attaching a resolver to a field you can send the resulting data from a mutation to lambda.
  3. Once the data is in lambda you can generate the push notifications

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?

@cwomack cwomack added the transferred This issue was transferred from another Amplify project label Jan 26, 2023
@cwomack cwomack transferred this issue from aws-amplify/amplify-js Jan 26, 2023
@katiegoines katiegoines added the amplify/js Issues tied to JS label Feb 10, 2023
@abdallahshaban557 abdallahshaban557 added the p4 guide needed/net new info label Mar 25, 2023
@nadetastic nadetastic removed the p4 guide needed/net new info label Jul 12, 2023
@abdallahshaban557
Copy link
Contributor

abdallahshaban557 commented Jul 29, 2023

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.

https://dev.to/codebeast/take-advantage-of-aws-amplifys-push-notification-feature-in-a-react-native-app-2cd2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify/js Issues tied to JS feature-request Request a new feature transferred This issue was transferred from another Amplify project
Projects
None yet
Development

No branches or pull requests

7 participants