aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

UpdateEndpoint does not create Push Notification subscription #2544

Closed ferdingler closed 5 years ago

ferdingler commented 5 years ago

Describe the bug Running updateEndpoint from a React web application doesn't actually create the endpoint in Pinpoint with the device token associated with it. It will not associate the Cognito user either.

To Reproduce The following code snippet, when run in a React web application (not React Native) succeeds, but does not send the channelType, address or userId to Amazon Pinpoint.

import { Analytics } from 'aws-amplify';

await Analytics.updateEndpoint({
    address: deviceToken,
    channelType: 'GCM',
    userId: this.props.user.username, // i.e. ferdingler
    userAttributes: {
        ...this.props.user // i.e. attributes like email and full name
    }
});

Expected behavior The previous code should update or create an endpoint in Amazon Pinpoint with the device token specified and linked to the userId provided. The following code snippet works correctly (this is not using Amplify):

const pinpoint = new AWS.Pinpoint({
    region: 'us-west-2',
    credentials: Auth.essentialCredentials(credentials),
});

const response = await pinpoint.updateEndpoint({
    ApplicationId: '4289.......f0d',
    EndpointId: uuid(),
    EndpointRequest: {
        Address: deviceToken,
        ChannelType: 'GCM',
        User: {
            UserId: this.props.user.username,
        },
    },
}).promise();

Desktop (please complete the following information):

Additional context The use case is about sending Web Push Notifications with Amazon Pinpoint -> Firebase Cloud Messaging and receiving them in a React web app using Amplify.

Taking a quick glance at the Amplify internal code, it seems that this is by design and not actually a bug. But it does feel like one. The documentation doesn't warn that this cannot be run from a web app, and the fact that the call succeeds but ignores the data provided is misleading.

Any guidance will be very much appreciated.

dylan-westbury commented 5 years ago

I am having similar issues with updating endpoints too, for react native application.

I update an endpoint as a user registers for push notifications.

PushNotification.onRegister(async (token) => {
  await Analytics.updateEndpoint({
    optOut: 'NONE',
    address: token
  });
});

I can manually send a push notification to the device using the token generated with pinpoint.

Throughout the app, I update userId once user is authenticated (e.g. login, signup, even tried other places)

const user = await Auth.currentAuthenticatedUser();
  Analytics.updateEndpoint({
  userId: user.attributes.sub
});

I use a lambda function that sends push notifications, by using the userId to get the endpoints info then send push notifications. But it is returning no endpoints for the userId.

var userEndpointsParams = {
  ApplicationId: process.env.PINPOINT_APP_ID,
  UserId: userId
};

pinpoint.getUserEndpoints(userEndpointsParams, function (userEndpointsErr, userEndpointsData) ...

The odd thing is, I used to get push notifications. But now they have stopped and I can't figure out why because the code has not changed for this.

I have tried deleting and installing the app many times, it's a release build with iOS adhoc distribution.

Is there an issue with updating endpoints at the moment? Any suggestions to debug / fix?

Amplify.Logger.LOG_LEVEL = 'DEBUG'; doesn't show anything out of the ordinary.

kevinsperrine commented 5 years ago

I can confirm this is also happening for me on Android since v1.0.18. ~The moving of the emit token event from initialize to being fired when the context is ready is causing the token to be emitted before the onRegister handlers are added and it's never picked up by the JS.~ If I revert back to 1.0.17 it works as expected.

EDIT: It works as expected if I also bump the other amplify modules, but having pushnotifications@1.0.18 while having aws-amplify@1.1.9 does not work.

Screenshot 2019-03-09 13 21 27

dylan-westbury commented 5 years ago

I have debugged on device and have found optOut is not being updated when calling Analytics.updateEndpoint. (setting optOut to 'NONE' as well as passing address - the device token from onRegister).

"@aws-amplify/pushnotification": "^1.0.23",
  "amazon-cognito-identity-js": "^3.0.9",
  "aws-amplify": "^1.1.22",
  "aws-amplify-react-native": "^2.1.8"

In app.js I have updateEndpoint setting optOut to 'NONE'

await AsyncStorage.setItem('push_token', token).then(() => Alert.alert(`stored push token ${token}`));
await Analytics.updateEndpoint({
  optOut: 'NONE',
  address: token
});
});

Even tried to do so after successful log in (the alert shows the correct device token)


Alert.alert(`pushToken ${pushToken}`);
if (pushToken) {
  endpointConfigure = {
    optOut: 'NONE',
    address: pushToken,
    userId: user.attributes.sub
  };
} else {
  endpointConfigure = {
    userId: user.attributes.sub
  };
}

await Analytics.updateEndpoint(endpointConfigure);

I print the endpoint in a aws lambda function, you can see optOut is still set to 'ALL'. instead of 'NONE' (for all endpoints tied to the userID - about 5 so far...)

  "Attributes": {},
"CohortId": "3",
  "CreationDate": "2019-03-19T00:24:42.578Z",
  "Demographic": {
  "AppVersion": "ios/12.1.4",
    "Make": "iPhone",
    "Model": "iPhone X",
    "ModelVersion": "12.1.4",
    "Platform": "ios"
},
"EffectiveDate": "2019-03-19T00:39:23.765Z",
  "EndpointStatus": "ACTIVE",
  "Id": "4e2246a0-49dd-11e9-8667-f9617c28a152",
  "Location": {},
"Metrics": {},
"OptOut": "ALL",
  "RequestId": "71615772-49df-11e9-a6c6-81ba47298f9f",
  "User": {
  "UserAttributes": {},
  "UserId": "ff32a7c4-8498-4e42-9487-78162a4dff0e"
}
},

I have even tried just calling Analytics.configure within the code after log in

await Analytics.configure({
          AWSPinpoint: {
            endpoint: {
              appId: 'xxxxxx',
              // OPTIONAL -  Amazon service region
              region: 'us-east-1',
              userId: user.attributes.sub,
              optOut: 'NONE',
              address: pushToken
            }
          }
        });

Something I am missing here? Just need optOut to be NONE...

robynnason commented 5 years ago

@dylan-westbury I am dealing with a similar issue. We are setting up Pinpoint push notifications with Cognito UserPool users. This has recently stopped working, where optOut always defaults to ALL regardless of what the user selects. pushnotification 1.0.20 and aws-amplify 1.1.16

We are running Auth.configure, on complete of that we run Analytics.configure before PushNotification.configure

dylan-westbury commented 5 years ago

@robynnason yes, same set up as our app. Have you managed to get it working for different versions of amplify / pushnotification?

We have not released the app yet, so we can't back date to a working version and this is the last feature for us to do before we can release :S

robynnason commented 5 years ago

@dylan-westbury What I have right now is I added PushNotification.onRegister(token => { ... }) right after PushNotification.configure. Within onRegister I call Analytics.updateEndpoint and assign the address to the token with an explicit optOut: NONE.

It works, but I don't love this method, because it makes several calls to updateEndpoint (you have it in Analytics.configure, PushNotification.configure, and now here). But I guess if you wanted something quick and dirty this would work. I have seen some posts about AsyncStorage not working as expected, and am thinking that may be part of the problem. I'm going to do some more research and see if that really is the problem and if there is a workaround. I'll try to get back if I figure it out!

Let me know if you find anything as well đź‘Ť

dylan-westbury commented 5 years ago

After hours and hours of investigation, I have found out the reason why optOut doesn't update to 'NONE'. - for my case anyway.

For my applications, it doesn't support unauthenticated identities. Because the push notification permission prompt appears before a user is logged in, the updateEndpoint to analytics fails. Unless of course the user is already logged in (for me, I was logged in on some users on different devices and when I implemented push notifications, the correct address and optOut would update).

For now, I have enabled unauthenticated access to the application (not ideal at all, not sure if there is anything else I can do).

A resolution would be to be able to trigger the iOS permission prompt when a user is authenticated, not automatically when the app fires up. There is an issue / PR request open for that https://github.com/aws-amplify/amplify-js/issues/1781.

I also noticed this issue while debugging too, looks like it will be fixed in an upcoming release.

Screen Shot 2019-03-28 at 3 05 38 pm

(edit, uploaded wrong image)

To debug push notification issues, I recommend:

  1. comment out any amplify.configure / push.configure / etc touch points
  2. run a debug build on device
  3. enable remote debug and live reload
  4. uncomment out the amplify.configure
  5. accept push notification permission prompt and see if any errors
naveenkonduru commented 5 years ago

is there any method to check android notification permissions?

bernhardt1 commented 5 years ago

@dylan-westbury bit off topic here, but would you mind sharing some of your lambda code that triggers the push notification?

I can't detect where it is going wrong through cloudwatch or cloudtrail. based on my console logs, the function never returns data or an error...

EDIT: I'm a novice with lambda... I just had to include a callback to escape the function properly. The below code sends messages successfully

var AWS = require('aws-sdk');

exports.handler = (event, context, callback) => {
    console.log('executing push notification');
    const pinpoint = new AWS.Pinpoint({ apiVersion: '2016-12-01', region: process.env.PINPOINT_REGION });

    const sendMessagesParams = {
        ApplicationId: process.env.PINPOINT_APP_ID,
        SendUsersMessageRequest: {
            Users: {
                [process.env.USER_ID]: {}
            },
            MessageConfiguration: {
                APNSMessage: {
                    Action: 'OPEN_APP',
                    Title: 'Message received',
                    SilentPush: false,
                    Body: `You have a new message`
                },
                GCMMessage: {
                    Action: 'OPEN_APP',
                    Title: 'Message received',
                    SilentPush: false,
                    Body: `You have a new message`
                }
            }
        }
    };

    console.log('sendMessagesParams', sendMessagesParams);

    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')
        }
    });
};
davidweica commented 5 years ago

I encountered the same issue when build a sample react native app to test push notification in pinpoint.

my code in App.js:

import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View, PushNotificationIOS} from 'react-native';

import Analytics from '@aws-amplify/analytics'; import PushNotification from '@aws-amplify/pushnotification'; import aws_exports from './aws-exports';

// PushNotification need to work with Analytics Analytics.configure(aws_exports);

PushNotification.configure(aws_exports);

// get the notification data when notification is received PushNotification.onNotification((notification) => { // Note that the notification object structure is different from Android and IOS console.log('in app notification', notification);

// required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
notification.finish(PushNotificationIOS.FetchResult.NoData);

});

// get the registration token PushNotification.onRegister((token) => { console.log('in app registration', token);

Analytics.updateEndpoint({
    address:token,
    channelType: 'APNS', 
    UserId: "Z1Y2X3W4ABC12345A",
    OptOut: "NONE",
    });

});

I can see the token in the log "in app registration ..." however, when I try to create segment in pinpoint, no endpoint there. but I was able to add endpoint via aws cli aws pinpoint update-endpoint --application-id 0114b9e3c6054048af48bbe4acfa0846 --endpoint-id d8329f7bc8f0442c9a710527d39eff76 --endpoint-request file://endpoint-request-file.json

bernhardt1 commented 5 years ago

@davidweica

I don't set the channelType. I'm not sure if that would make any difference for you. You could also check if anything is being returned.

Analytics.updateEndpoint({
        address: deviceToken,
        optOut: 'NONE',
        userId: 'userIdHere'
      })
        .then(data => {
          console.log('endpoint updated', JSON.stringify(data));
        })
        .catch(error => {
          console.log('error updating endpoint', error);
        });
davidweica commented 5 years ago

@baharev Analytics.updateEndpoint({ address: token, optOut: 'NONE', userId: 'Z1Y2X3W4ABC12345A' }) .then(data => { console.log('endpoint updated', JSON.stringify(data)); }) .catch(error => { console.log('error updating endpoint', error); });

got log:

'endpoint updated', undefined

baharev commented 5 years ago

@davidweica Sorry, I don't follow. How did I get into this discussion?

davidweica commented 5 years ago

@baharev sorry, wrong mention. :). was for @bernhardt1

baharev commented 5 years ago

@davidweica OK, no problem. Weird though that GitHub offered it.

bernhardt1 commented 5 years ago

@davidweica

My first advice wasn't great. I just checked my logs. I also get 'endpoint updated', undefined in my code too, but it is successfully updating the endpoint.

One other thing you might try is moving the updateEndpoint call out of onRegister. I save my token to asyncStorage and then update the endpoint later.

you can also turn on debug logging which should help you track what's happening with your calls to AWS analytics.

just add window.LOG_LEVEL = 'DEBUG'; at the top of your hierarchy, like so:

window.LOG_LEVEL = 'DEBUG';

class App extends Component {
  render() {...
robynnason commented 5 years ago

Hey everyone, I haven't read through this entire comment chain, but I reached out to AWS for help on this. For my case, they suggested that in the Analytics.configure({ PushNotificatoin: ... to specify the endpoint as OptOut: NONE and then after the Analytics.configure add this line: Analytics.updateEndpoint({ immediate: true }); This has been working mostly successfully for me. As they explained it to me, if the user specifies they want to be opted out, their device settings handle not letting the push notification through. They didn't really explain what the immediate: true does, and I haven't found much in their docs/code about it though...

davidweica commented 5 years ago

Hi folks, I tried all the suggestions above, added immediate: true in updateEndpoint, also, tried to call updateEndpoint after saving in storage, still cannot get through.

I pasted my app.js and logs below, thanks for helping.

App.js:

import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View, PushNotificationIOS} from 'react-native';

import Analytics from '@aws-amplify/analytics'; import PushNotification from '@aws-amplify/pushnotification'; import aws_exports from './aws-exports'; import AsyncStorage from '@react-native-community/async-storage';

window.LOG_LEVEL = 'DEBUG';

// PushNotification need to work with Analytics Analytics.configure(aws_exports);

PushNotification.configure(aws_exports); Analytics.updateEndpoint({ immediate: true });

// get the notification data when notification is received PushNotification.onNotification((notification) => { // Note that the notification object structure is different from Android and IOS console.log('in app notification', notification);

// required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
notification.finish(PushNotificationIOS.FetchResult.NoData);

});

// get the registration token PushNotification.onRegister((token) => { console.log('in app registration', token);

const storeData = async () => {
    try {
      console.log('saving device token')
      await AsyncStorage.setItem('@devicetoken', token)
      console.log('device token saved')
      getData();
    } catch (e) {
      console.log('error on saving device token', e)
    }
}

const getData = async () => {
    try {
      const token = await AsyncStorage.getItem('@devicetoken')
      if(token !== null) {
        try{
            Analytics.updateEndpoint({
                address: token,
                optOut: 'NONE',
                userId: 'Z1Y2X3W4ABC12345A',
                immediate: true
              })
                .then(data => {
                  console.log('endpoint updated', JSON.stringify(data));
                })
                .catch(error => {
                  console.log('error updating endpoint', error);
                });
        }catch(ex){
            console.log('error in updateEndpoint:',ex);
        }
        console.log('update endpoint from storage')
      }else{
        console.log('error on getting token from storage')
      }
    } catch(e) {
        console.log('error on updating endpoint from storage')
    }
}

storeData();

});

// get the notification data when notification is opened PushNotification.onNotificationOpened((notification) => { console.log('the notification is opened', notification); });

const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', });

type Props = {};

export default class App extends Component {

render() { return (

Welcome to React Native! To get started, edit App.js {instructions}
);

} }

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, });


aws-exports.js:

const awsmobile = { "aws_project_region": "us-east-1", "aws_cognito_identity_pool_id": "us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140", "aws_cognito_region": "us-east-1", "oauth": {}, "aws_mobile_analytics_app_id": "0114b9e3c6054048af48bbe4acfa0846", "aws_mobile_analytics_app_region": "us-east-1" }; export default awsmobile;


package.json: { "name": "pushapp", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "@aws-amplify/analytics": "^1.2.16", "@aws-amplify/auth": "^1.2.24", "@aws-amplify/pushnotification": "^1.0.27", "@react-native-community/async-storage": "^1.4.2", "aws-amplify": "^1.1.28", "react": "16.8.3", "react-native": "0.59.8" }, "devDependencies": { "@babel/core": "^7.4.5", "@babel/runtime": "^7.4.5", "babel-jest": "^24.8.0", "jest": "^24.8.0", "metro-react-native-babel-preset": "^0.54.1", "react-test-renderer": "16.8.3" }, "jest": { "preset": "react-native" } }


logs in xcode: 2019-05-31 13:33:21.894 [warn][tid:com.facebook.react.JavaScript] Require cycle: node_modules/aws-sdk/lib/react-native-loader.js -> node_modules/aws-sdk/lib/credentials/temporary_credentials.js -> node_modules/aws-sdk/clients/sts.js -> node_modules/aws-sdk/lib/react-native-loader.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle. 2019-05-31 13:33:21.894377-0700 pushapp[21642:1345079] Require cycle: node_modules/aws-sdk/lib/react-native-loader.js -> node_modules/aws-sdk/lib/credentials/temporary_credentials.js -> node_modules/aws-sdk/clients/sts.js -> node_modules/aws-sdk/lib/react-native-loader.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle. 2019-05-31 13:33:21.896 [warn][tid:com.facebook.react.JavaScript] Require cycle: node_modules/aws-sdk/lib/react-native-loader.js -> node_modules/aws-sdk/lib/credentials/cognito_identity_credentials.js -> node_modules/aws-sdk/clients/cognitoidentity.js -> node_modules/aws-sdk/lib/react-native-loader.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle. 2019-05-31 13:33:21.895848-0700 pushapp[21642:1345079] Require cycle: node_modules/aws-sdk/lib/react-native-loader.js -> node_modules/aws-sdk/lib/credentials/cognito_identity_credentials.js -> node_modules/aws-sdk/clients/cognitoidentity.js -> node_modules/aws-sdk/lib/react-native-loader.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle. 2019-05-31 13:33:21.922 [warn][tid:com.facebook.react.JavaScript] Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage 2019-05-31 13:33:21.922082-0700 pushapp[21642:1345079] Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage 2019-05-31 13:33:21.933 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:21.932 AnalyticsClass - configure Analytics', { aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1' } 2019-05-31 13:33:21.933521-0700 pushapp[21642:1345079] '[DEBUG] 33:21.932 AnalyticsClass - configure Analytics', { aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1' } 2019-05-31 13:33:21.935 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:21.933 Parser - parse config', [ { aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1' }, 'to amplifyconfig', { Analytics: { AWSPinpoint: { appId: '0114b9e3c6054048af48bbe4acfa0846', region: 'us-east-1' } }, Auth: { userPoolId: undefined, userPoolWebClientId: undefined, region: 'us-east-1', identityPoolId: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', mandatorySignIn: false }, Storage: { aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1' } } ] 2019-05-31 13:33:21.934906-0700 pushapp[21642:1345079] '[DEBUG] 33:21.933 Parser - parse config', [ { aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1' }, 'to amplifyconfig', { Analytics: { AWSPinpoint: { appId: '0114b9e3c6054048af48bbe4acfa0846', region: 'us-east-1' } }, Auth: { userPoolId: undefined, userPoolWebClientId: undefined, region: 'us-east-1', identityPoolId: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', mandatorySignIn: false }, Storage: { aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1' } } ] 2019-05-31 13:33:21.937 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:21.936 DeviceInfo', [ { OS: 'ios', Version: [Getter], isPad: [Getter], isTVOS: [Getter], isTV: [Getter], isTesting: [Getter], select: [Function: select] }, { scale: 2, width: 375, height: 667, fontScale: 0.941 } ] 2019-05-31 13:33:21.936773-0700 pushapp[21642:1345079] '[DEBUG] 33:21.936 DeviceInfo', [ { OS: 'ios', Version: [Getter], isPad: [Getter], isTVOS: [Getter], isTV: [Getter], isTesting: [Getter], select: [Function: select] }, { scale: 2, width: 375, height: 667, fontScale: 0.941 } ] 2019-05-31 13:33:21.937 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:21.937 AWSPinpointProvider - configure Analytics', { disabled: undefined, appId: '0114b9e3c6054048af48bbe4acfa0846', region: 'us-east-1' } 2019-05-31 13:33:21.937541-0700 pushapp[21642:1345079] '[DEBUG] 33:21.937 AWSPinpointProvider - configure Analytics', { disabled: undefined, appId: '0114b9e3c6054048af48bbe4acfa0846', region: 'us-east-1' } 2019-05-31 13:33:21.939 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:21.939 AsyncStorageCache - Get item: key is AWSPinpoint_0114b9e3c6054048af48bbe4acfa0846 with options undefined 2019-05-31 13:33:21.939387-0700 pushapp[21642:1345079] [DEBUG] 33:21.939 AsyncStorageCache - Get item: key is AWSPinpoint_0114b9e3c6054048af48bbe4acfa0846 with options undefined 2019-05-31 13:33:21.940725-0700 pushapp[21642:1345065] [] nw_socket_handle_socket_event [C5:1] Socket SO_ERROR [61: Connection refused] 2019-05-31 13:33:21.942 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:21.942 Hub - Dispatching to analytics with ', { event: 'configured', data: null, message: 'The Analytics category has been configured successfully' } 2019-05-31 13:33:21.942432-0700 pushapp[21642:1345079] '[DEBUG] 33:21.942 Hub - Dispatching to analytics with ', { event: 'configured', data: null, message: 'The Analytics category has been configured successfully' } 2019-05-31 13:33:21.943 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:21.942 Analytics - on hub capsule analytics', { event: 'configured', data: null, message: 'The Analytics category has been configured successfully' } 2019-05-31 13:33:21.942695-0700 pushapp[21642:1345079] '[DEBUG] 33:21.942 Analytics - on hub capsule analytics', { event: 'configured', data: null, message: 'The Analytics category has been configured successfully' } 2019-05-31 13:33:21.943 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:21.942 AnalyticsClass - current configuration', { AWSPinpoint: { appId: '0114b9e3c6054048af48bbe4acfa0846', region: 'us-east-1' }, aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1', autoSessionRecord: true } 2019-05-31 13:33:21.943011-0700 pushapp[21642:1345079] '[DEBUG] 33:21.942 AnalyticsClass - current configuration', { AWSPinpoint: { appId: '0114b9e3c6054048af48bbe4acfa0846', region: 'us-east-1' }, aws_project_region: 'us-east-1', aws_cognito_identity_pool_id: 'us-east-1:3f045557-eeaa-4813-90ad-6cfa284a9140', aws_cognito_region: 'us-east-1', oauth: {}, aws_mobile_analytics_app_id: '0114b9e3c6054048af48bbe4acfa0846', aws_mobile_analytics_app_region: 'us-east-1', autoSessionRecord: true } 2019-05-31 13:33:21.943902-0700 pushapp[21642:1345064] [] nw_connection_get_connected_socket [C5] Client called nw_connection_get_connected_socket on unconnected nw_connection 2019-05-31 13:33:21.943926-0700 pushapp[21642:1345064] TCP Conn 0x2813d83c0 Failed : error 0:61 [61] 2019-05-31 13:33:21.947 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:21.947 Credentials - getting credentials 2019-05-31 13:33:21.947414-0700 pushapp[21642:1345079] [DEBUG] 33:21.947 Credentials - getting credentials 2019-05-31 13:33:21.948 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:21.947 Credentials - picking up credentials 2019-05-31 13:33:21.947611-0700 pushapp[21642:1345079] [DEBUG] 33:21.947 Credentials - picking up credentials 2019-05-31 13:33:21.948 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:21.947 Credentials - getting new cred promise 2019-05-31 13:33:21.947688-0700 pushapp[21642:1345079] [DEBUG] 33:21.947 Credentials - getting new cred promise 2019-05-31 13:33:21.948 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:21.947 Credentials - checking if credentials exists and not expired 2019-05-31 13:33:21.947860-0700 pushapp[21642:1345079] [DEBUG] 33:21.947 Credentials - checking if credentials exists and not expired 2019-05-31 13:33:21.948 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:21.947 Credentials - need to get a new credential or refresh the existing one 2019-05-31 13:33:21.947938-0700 pushapp[21642:1345079] [DEBUG] 33:21.947 Credentials - need to get a new credential or refresh the existing one 2019-05-31 13:33:22.108 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:22.107 AWSPinpointProvider - ensure credentials error', 'No Auth module registered in Amplify' 2019-05-31 13:33:22.107659-0700 pushapp[21642:1345079] '[DEBUG] 33:22.107 AWSPinpointProvider - ensure credentials error', 'No Auth module registered in Amplify' 2019-05-31 13:33:22.109 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:22.108 AWSPinpointProvider - cannot send events without credentials, applicationId or region 2019-05-31 13:33:22.108799-0700 pushapp[21642:1345079] [DEBUG] 33:22.108 AWSPinpointProvider - cannot send events without credentials, applicationId or region 2019-05-31 13:33:22.111 [info][tid:com.facebook.react.JavaScript] Running application "pushapp" with appParams: {"rootTag":1,"initialProps":{}}. DEV === true, development-level warning are ON, performance optimizations are OFF 2019-05-31 13:33:22.110606-0700 pushapp[21642:1345079] Running application "pushapp" with appParams: {"rootTag":1,"initialProps":{}}. DEV === true, development-level warning are ON, performance optimizations are OFF 2019-05-31 13:33:22.171 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:22.171 AWSPinpointProvider - endpointId from cache', [ null, 'type', 'object' ] 2019-05-31 13:33:22.171506-0700 pushapp[21642:1345079] '[DEBUG] 33:22.171 AWSPinpointProvider - endpointId from cache', [ null, 'type', 'object' ] 2019-05-31 13:33:22.173 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:22.172 AsyncStorageCache - Set item: key is AWSPinpoint_0114b9e3c6054048af48bbe4acfa0846, value is 5532acb0-83e3-11e9-a6d0-f3036e34c07b with options: undefined 2019-05-31 13:33:22.172845-0700 pushapp[21642:1345079] [DEBUG] 33:22.172 AsyncStorageCache - Set item: key is AWSPinpoint_0114b9e3c6054048af48bbe4acfa0846, value is 5532acb0-83e3-11e9-a6d0-f3036e34c07b with options: undefined 2019-05-31 13:33:22.175 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:22.175 AWSPinpointProvider - setting endpoint id from the cache', '5532acb0-83e3-11e9-a6d0-f3036e34c07b' 2019-05-31 13:33:22.175366-0700 pushapp[21642:1345079] '[DEBUG] 33:22.175 AWSPinpointProvider - setting endpoint id from the cache', '5532acb0-83e3-11e9-a6d0-f3036e34c07b' 2019-05-31 13:33:22.176 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:22.175 Hub - Dispatching to analytics with ', { event: 'pinpointProvider_configured', data: null } 2019-05-31 13:33:22.175677-0700 pushapp[21642:1345079] '[DEBUG] 33:22.175 Hub - Dispatching to analytics with ', { event: 'pinpointProvider_configured', data: null } 2019-05-31 13:33:22.176 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:22.175 Analytics - on hub capsule analytics', { event: 'pinpointProvider_configured', data: null } 2019-05-31 13:33:22.175850-0700 pushapp[21642:1345079] '[DEBUG] 33:22.175 Analytics - on hub capsule analytics', { event: 'pinpointProvider_configured', data: null } 2019-05-31 13:33:23.652614-0700 pushapp[21642:1345053] [] nw_socket_connect [C6.1:1] connectx(8, [srcif=0, srcaddr=, dstaddr=::1.8081], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [61: Connection refused] 2019-05-31 13:33:23.652696-0700 pushapp[21642:1345053] [] nw_socket_connect [C6.1:1] connectx failed (fd 8) [61: Connection refused] 2019-05-31 13:33:23.652709-0700 pushapp[21642:1345053] [] nw_socket_connect connectx failed (fd 8) [61: Connection refused] 2019-05-31 13:33:23.654172-0700 pushapp[21642:1345053] [] nw_socket_connect [C6.2:1] connectx(8, [srcif=0, srcaddr=, dstaddr=127.0.0.1:8081], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [61: Connection refused] 2019-05-31 13:33:23.654283-0700 pushapp[21642:1345053] [] nw_socket_connect [C6.2:1] connectx failed (fd 8) [61: Connection refused] 2019-05-31 13:33:23.654304-0700 pushapp[21642:1345053] [] nw_socket_connect connectx failed (fd 8) [61: Connection refused] 2019-05-31 13:33:23.654430-0700 pushapp[21642:1345064] [] nw_connection_get_connected_socket [C6] Client called nw_connection_get_connected_socket on unconnected nw_connection 2019-05-31 13:33:23.654450-0700 pushapp[21642:1345064] TCP Conn 0x2813d83c0 Failed : error 0:61 [61] 2019-05-31 13:33:24.641 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:24.641 Notification - update endpoint in push notification', '76482a3318d224c320a171db156508063984f7589b5e92cd2fd595b428850d1c' 2019-05-31 13:33:24.641553-0700 pushapp[21642:1345079] '[DEBUG] 33:24.641 Notification - update endpoint in push notification', '76482a3318d224c320a171db156508063984f7589b5e92cd2fd595b428850d1c' 2019-05-31 13:33:24.642 [info][tid:com.facebook.react.JavaScript] 'in app registration', '76482a3318d224c320a171db156508063984f7589b5e92cd2fd595b428850d1c' 2019-05-31 13:33:24.641976-0700 pushapp[21642:1345079] 'in app registration', '76482a3318d224c320a171db156508063984f7589b5e92cd2fd595b428850d1c' 2019-05-31 13:33:24.643 [info][tid:com.facebook.react.JavaScript] saving device token 2019-05-31 13:33:24.643375-0700 pushapp[21642:1345079] saving device token 2019-05-31 13:33:24.646 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:24.645 Notification - refresh the device token with', '76482a3318d224c320a171db156508063984f7589b5e92cd2fd595b428850d1c' 2019-05-31 13:33:24.645685-0700 pushapp[21642:1345079] '[DEBUG] 33:24.645 Notification - refresh the device token with', '76482a3318d224c320a171db156508063984f7589b5e92cd2fd595b428850d1c' 2019-05-31 13:33:24.646 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.645 Credentials - getting credentials 2019-05-31 13:33:24.645964-0700 pushapp[21642:1345079] [DEBUG] 33:24.645 Credentials - getting credentials 2019-05-31 13:33:24.646 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.646 Credentials - picking up credentials 2019-05-31 13:33:24.646128-0700 pushapp[21642:1345079] [DEBUG] 33:24.646 Credentials - picking up credentials 2019-05-31 13:33:24.646 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.646 Credentials - getting new cred promise 2019-05-31 13:33:24.646335-0700 pushapp[21642:1345079] [DEBUG] 33:24.646 Credentials - getting new cred promise 2019-05-31 13:33:24.646 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.646 Credentials - checking if credentials exists and not expired 2019-05-31 13:33:24.646432-0700 pushapp[21642:1345079] [DEBUG] 33:24.646 Credentials - checking if credentials exists and not expired 2019-05-31 13:33:24.647 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.646 Credentials - need to get a new credential or refresh the existing one 2019-05-31 13:33:24.646535-0700 pushapp[21642:1345079] [DEBUG] 33:24.646 Credentials - need to get a new credential or refresh the existing one 2019-05-31 13:33:24.656 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.656 Notification - update endpoint success, setting token into cache 2019-05-31 13:33:24.656349-0700 pushapp[21642:1345079] [DEBUG] 33:24.656 Notification - update endpoint success, setting token into cache 2019-05-31 13:33:24.659 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:24.658 AWSPinpointProvider - ensure credentials error', 'No Auth module registered in Amplify' 2019-05-31 13:33:24.658879-0700 pushapp[21642:1345079] '[DEBUG] 33:24.658 AWSPinpointProvider - ensure credentials error', 'No Auth module registered in Amplify' 2019-05-31 13:33:24.660 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.659 AWSPinpointProvider - cannot send events without credentials, applicationId or region 2019-05-31 13:33:24.660073-0700 pushapp[21642:1345079] [DEBUG] 33:24.659 AWSPinpointProvider - cannot send events without credentials, applicationId or region 2019-05-31 13:33:24.662 [info][tid:com.facebook.react.JavaScript] device token saved 2019-05-31 13:33:24.661880-0700 pushapp[21642:1345079] device token saved 2019-05-31 13:33:24.667 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.666 Credentials - getting credentials 2019-05-31 13:33:24.667037-0700 pushapp[21642:1345079] [DEBUG] 33:24.666 Credentials - getting credentials 2019-05-31 13:33:24.667 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.667 Credentials - picking up credentials 2019-05-31 13:33:24.667166-0700 pushapp[21642:1345079] [DEBUG] 33:24.667 Credentials - picking up credentials 2019-05-31 13:33:24.667 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.667 Credentials - getting new cred promise 2019-05-31 13:33:24.667257-0700 pushapp[21642:1345079] [DEBUG] 33:24.667 Credentials - getting new cred promise 2019-05-31 13:33:24.667 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.667 Credentials - checking if credentials exists and not expired 2019-05-31 13:33:24.667344-0700 pushapp[21642:1345079] [DEBUG] 33:24.667 Credentials - checking if credentials exists and not expired 2019-05-31 13:33:24.667 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.667 Credentials - need to get a new credential or refresh the existing one 2019-05-31 13:33:24.667423-0700 pushapp[21642:1345079] [DEBUG] 33:24.667 Credentials - need to get a new credential or refresh the existing one 2019-05-31 13:33:24.678 [info][tid:com.facebook.react.JavaScript] update endpoint from storage 2019-05-31 13:33:24.678249-0700 pushapp[21642:1345079] update endpoint from storage 2019-05-31 13:33:24.680 [info][tid:com.facebook.react.JavaScript] 'endpoint updated', undefined 2019-05-31 13:33:24.680456-0700 pushapp[21642:1345079] 'endpoint updated', undefined 2019-05-31 13:33:24.684 [info][tid:com.facebook.react.JavaScript] '[DEBUG] 33:24.683 AWSPinpointProvider - ensure credentials error', 'No Auth module registered in Amplify' 2019-05-31 13:33:24.683880-0700 pushapp[21642:1345079] '[DEBUG] 33:24.683 AWSPinpointProvider - ensure credentials error', 'No Auth module registered in Amplify' 2019-05-31 13:33:24.685 [info][tid:com.facebook.react.JavaScript] [DEBUG] 33:24.684 AWSPinpointProvider - cannot send events without credentials, applicationId or region 2019-05-31 13:33:24.685126-0700 pushapp[21642:1345079] [DEBUG] 33:24.684 AWSPinpointProvider - cannot send events without credentials, applicationId or region


I noticed that there is an error "AWSPinpointProvider - ensure credentials error', 'No Auth module registered in Amplify', not sure if that's related.

Thanks!

@bernhardt1

bernhardt1 commented 5 years ago

@davidweica

It successfully updates the analytics off the start so I think you project has analytics and auth set up correctly.

I'd go to console with amplify status and look through your resources. You need auth and analytics to use notifications. It seems like you either don't have auth in your amplify project or your notifications aren't connected to your auth module. You can add/remove notifications from the amplify project without much worry. I would update the notifications module in terminal to make sure it is targeting the correct analytics and auth project.

Also, I noticed your aws-exports file doesn't have a user pool. I'm not certain, but I think that's why your getting the no auth module registered in amplify

maybe go through the amplify auth configuration again?

here is mine:

const awsmobile = {
  aws_project_region: 'us-west-2',
  aws_cognito_identity_pool_id: 'us-west-2:xxx',   // from auth
  aws_cognito_region: 'us-west-2', // from auth
  aws_user_pools_id: 'us-west-2_xxx', // from auth
  aws_user_pools_web_client_id: 'xxx', // from auth
  aws_mobile_analytics_app_id: 'xxx', // analytics
  aws_mobile_analytics_app_region: 'us-east-1', // analytics
  aws_user_files_s3_bucket: 'xxx',
  aws_user_files_s3_bucket_region: 'us-west-2'
};

Your project is set up quite differently than mine so it's hard to diagnose your problem. Overall I think you are missing something on your backend that is needed to connect your auth/analytics with the pinpoint service.

davidweica commented 5 years ago

tried to create app following https://aws-amplify.github.io/docs/js/analytics for analytics and make it works. the add push notification, get through.

sammartinez commented 5 years ago

@ferdingler Are you still experiencing this issue with later versions of aws-amplify? Please let us know if this issue is still occurring.

haverchuck commented 5 years ago

Closing due to inactivity.

ferdingler commented 5 years ago

Sorry I am not working on that project anymore. I will reopen if I come across the same issue in the future. Thank you.

kurnal commented 3 years ago

I have been able to successfully call updateEndpoint. However, when I make campaigns the notifications do not get sent to my device EVEN THOUGH there is clearly active users available in the segments. Any hypothesis or things I should look into? thanks

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.