Amplify-js: Pinpoint - PushNotification: How to register userId/endpointId as a custom attribute?

Created on 12 Jul 2018  路  4Comments  路  Source: aws-amplify/amplify-js

Hi All, I am trying to use AWS pinpoint for mobile push notifications. I want to use pinpoint DB to store users token and I would like to have a custom userId field to identify in my backend and send the notification on required
can anyone help me to configure push notification manually?

I am trying the following in App.js

// Register in App
PushNotification.configure({
    PushNotification: {
        appId: 鈥渪xxxxxxxxxxxxxxabf418c6484d01ad",
        endpointId: "abf418c6484d01ad",
        region: "us-east-1",
    },
});

// Send message using aws-sdk in backend server

const params = {
    ApplicationId: 'xxxxxxxxxxxxxxxabf418c6484d01ad',
    SendUsersMessageRequest: {
        MessageConfiguration: {
            DefaultMessage: {
                Body: 'DefaultMessage - dev',
            },
            DefaultPushNotificationMessage: {
                Action: 'OPEN_APP',
                Body: 'DefaultPushNotificationMessage - dev',
                SilentPush: false,
                Title: 'Title - Dev'
            },
            GCMMessage: {
                Action: 'OPEN_APP',
                Body: 'GCMMessage - dev',
                SilentPush: false,
                TimeToLive: 0,
                Title: ' Dev',
            }
        },
        Users: {
            'abf418c6484d01ad': {
                BodyOverride: 'BodyOverride - dev',
                TitleOverride: ' Dev Title'
            }
        }
    }
};

function sendNotification() {
    pinpoint.sendUsersMessages(params, function (err, data) {
        if (err) console.log(err, err.stack);
        else console.log(JSON.stringify(data));
    });
}

// Sample response:

"Result":{"abf418c6484d01ad":{"":{"Address":"","DeliveryStatus":"PERMANENT_FAILURE","StatusCode":400,"StatusMessage":"No endpoints found for userId."}}}}

can anyone help me on this?

question

Most helpful comment

Thank you so much @powerful123. After register the PushNotification token, it requires an endpoint update with custom attribute (UserId) and OptOut, which is default to "ALL". The sample code snippet,

// get the registration token
PushNotification.onRegister((token) => {
    console.log("in app registration", token);
    Analytics.updateEndpoint({
        UserId: "Z1Y2X3W4ABC12345A",
        OptOut: "NONE",
    });
});

Thanks Again.

All 4 comments

Hi, as I know you need to update your endpoint with your userid/endpointid. Can you check this doc? https://aws.github.io/aws-amplify/media/analytics_guide#manual-setup

In fact Push notification is based on the analytics module to configure your endpoint

Thank you so much @powerful123. After register the PushNotification token, it requires an endpoint update with custom attribute (UserId) and OptOut, which is default to "ALL". The sample code snippet,

// get the registration token
PushNotification.onRegister((token) => {
    console.log("in app registration", token);
    Analytics.updateEndpoint({
        UserId: "Z1Y2X3W4ABC12345A",
        OptOut: "NONE",
    });
});

Thanks Again.

In my case address was also necessary for the update to work:

Analytics.updateEndpoint({
        address: notificationToken,
        optOut: 'NONE',
        userId: userId
      })
Was this page helpful?
0 / 5 - 0 ratings