I am using aws mobileHub for my react-native project. I am using aws-amplify library to use aws features in my app and i follow all the steps of aws-Pinpoint and aws-amplify for push notifications in android . When app open I get the token from 'aws-amplify-react-native' but when I start campaign it sometimes deliver few messages sometimes none but I received none of it and when I try direct messages then it says successfully send push notification from pinpoint console but I received nothing in app. Here is the image of success message
Would you mind testing sending a test message using the AWS CLI. The reason is that the CLI would be able to give you a more detailed error message. It would look something like this.
aws pinpoint send-messages --application-id {appid} --message-request '{
"Addresses": {
"{token}": {
"ChannelType": "GCM"
}
},
"MessageConfiguration": {
"GCMMessage": {
"Body": "Test Body",
"Title": "Test Title"
}
}
}
Hopefully the response you get from this will tell you the reason why your requests are failing. My guess of what is wrong is that you somehow have an invalid token.
Related
I created an AWS Lambda function with the following default (Hello world example) code.
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
I also added an API gateway as a trigger and when tested with curl, I can successfully retrieve the 'Hello from Lambda Message'
curl https://xxxxxxxxxxxxx.execute-api.us-east-1.amazonaws.com/default/test
"Hello from Lambda!"
Then, as I want to build a slackbot, I enable events and tested the api-gateway url in slack
slack app event
I'm failing to understand why there is no challenge nor token being sent in slack post to the api gateway URL
Besides the fact that I should be able to catch the challenge and return it to complete de verification process, there nothing being sent from slack challenge POST message (I should at least see the code:200 and the "Hello from Lambda!" message in the body anyway)
Following this article, I was expecting to see something like this, but mine has an empty response
Slack Enable events from article
Any clues? This is a new workspace and a new slack app, so it is possible that I forgot to set it correctly.
Thanks
I was having the same problem as you. I followed this example and got it to work: https://medium.com/analytics-vidhya/create-and-distribute-a-slack-bot-with-python-and-aws-in-1-hour-41c4a6c0f99d
The issue with my API was that initially I created an API in API Gateway of type REST. When I made an API of type HTTP, everything worked.
I'm trying to get some basic analytics for a Cognito user pool. It seemed simple enough to do, I created a project in Pinpoint, then I went to my user pool, went to General settings > Analytics, clicked the Add Analytics button, choose the Amazon Cognito app client that my app uses, pointed to the Pinpoint project I just created, checked the "Share user profile data" checkbox (though I assume that's not absolutely necessary), and it had the message telling me if would use the IAM role and so on. Clicked Save, got no error, I assumed at this point I would start seeing Analytics in Pinpoint, but there's absolutely nothing showing up.I do have a message saying I haven't enabled any features yet, but I don't see any features I'd need to enable. I don't care about the campaigns as of now, and then under Application analytics it seems geared to you manually updating your mobile or web app to send something, but I thought that was if you need to customize something. Am I mistaken? Will this integration only work if you change your web app to explicitly send things to Pinpoint? I just assumed if I connected Cognito and Pinpoint the analytics would show since Cognito obviously knows people are logging in without you needing to manually make some extra request.
From my research, I found out that since you are using a Web Application without using AWS Amplify framework, you need to add additional lines of code to your application in order to send Cognito authentication analytics data to your Amazon Pinpoint project.
If you are using the Javascript SDK you may add the initate-Auth property code snippet to your front-end application:
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
var params = {
AuthFlow: "USER_PASSWORD_AUTH",
ClientId: 'STRING_VALUE', /* the client ID attached to the Pinpoint project */
AuthParameters: {
'USERNAME': 'STRING_VALUE',
'PASSWORD': 'STRING_VALUE'
},
AnalyticsMetadata: {
AnalyticsEndpointId: 'STRING_VALUE' /* the Pinpoint project ID */
},
};
cognitoidentityserviceprovider.initiateAuth(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
In the above code snippet, the Pinpoint project/application ID is added as part of the "AnalyticsMetadata" parameter when the client makes the API calls (e.g. sign-in, sign-up, etc.) to the Cognito user pool. Therefore, the API calls will have the pinpoint project ID attached to them and Cognito can use that information to send the data to your Pinpoint project. Without this crucial step, analytics data will not be sent to Pinpoint and will result in the behavior you have described.
If using CLI (for verification/testing purpose), you may execute the following AWS CLI initiate-auth command below :
$ aws cognito-idp initiate-auth --auth-flow USER_PASSWORD_AUTH --auth-parameters USERNAME=STRING_VALUE,PASSWORD=STRING_VALUE --client-id STRING_VALUE --analytics-metadata AnalyticsEndpointId=STRING_VALUE
The take away point is that :
Amazon Cognito integration with Amazon Pinpoint only works for apps (clients) that are using Cognito SDK for Mobile Apps (AWS Mobile SDKs or JavaScript - AWS Amplify JavaScript library).
Just a note to syumaK's response, yes you need to update your code's initAuth call to include the AnalyticsMetadat property. However, I found out that the AnalyticsEndpointId should NOT be the Pinpoint project ID.
I believe that since you've configured Cognito already to integrate with the pinpoint project, it knows which pinpoint project you are sending metrics to already. The AnalyticsEndpointId should be a uniquely identifier for the login.
The documentation is definitely flaky here. The cli one from syumaK's seems to describe it differently than Cognito API Reference
What happened to me was that I used the pinpoint project id, and when I log in with multiple users, it thinks it's the same one. The daily active users remains at one. AWS Support clarified that it should be a unique identifier for each user. So after changing the id to be the user's email, I am starting to get accurate numbers for the daily active users.
It also seems like this is just about as useful as it is going to be for not using the Cognito SDK for Mobile Apps or Amplify. You can only get information like daily/monthly active users, authentication metrics. You don't have the ability to further break down by segments, etc.
I am creating an Expo app that will use push notifications. I do not want to use Expo's server for that and instead I want to use AWS SNS. This is what I have done:
Created the app in Firebase and obtained the API Key.
Created the platform application on SNS using the API key obtained in step 1.
Used expo to obtained the device token.
Created an endpoint on SNS in the application created in step 2.
When I try to send a push notification, it doesn't work. I tried:
I made sure that use .getDevicePushTokenAsync() instead of getExpoPushTokenAsync() to get the device token that can be used with SNS.
When I test the app on my Android device I am able to console.log the device token (which is what I use to add the endpoint mentioned in step 4 above. Still nothing :(
I built a stand alone app, downloaded the .apk file, installed it on my device, BUT NOW THE PUSH TOKEN IS NOT BEING RETRIEVED. I really do not know why after building the app and installing it on my device this doesn't work anymore. It returns
I am thinking that if I am able to build the app and obtain the device token I may be able to make it work, but no luck. Any idea on what I am doing wrong or what I am supposed to be doing?
After 2 days of fighting to get this to work I finally did it. I am going to provide all the steps I followed in hopes that this can help other people:
Create a Firebase Project.
Click on "Add Project"
Provide a name. Click on "Continue"
Click on "Create Project"
Once the project is ready, click on "Continue"
Click on the gear icon right next to where it says "Project Overview"
Click on Project Settings.
In the page that shows up click on Cloud Messaging
Copy the value for "Server key". You will use it later when creating an application platform in SNS.
In that same "settings" page click on the "General" tab.
At the bottom of the page you are going to see a section that says "Your Apps". It should say: "There are no apps in your project". Click on the icon for Android.
This is an important step. You need to provide the "Android package name". Go to your Expo app and find the value for android.package. Copy it and put it where it asks for the Android package name on Firebase.
Click on "Register App".
Important step. Click on the button that says "Download google-services.json".
Save the file AT THE ROOT OF YOUR EXPO PROJECT.
Go back to your app.json file in your Expo project. Where it has the android value make sure this is what you have at least:
"android": {
"googleServicesFile": "./google-services.json",
"package": "com.astest.mypackage",
"useNextNotificationsApi": true
},
Follow the instructions here on how to set up your client app. Make sure you do not include the sendPushNotification() function since you will actually be using SNS instead.
In the registerForPushNotificationsAsync() function make sure you use .getDevicePushTokenAsync() instead of .getExpoPushTokenAsync()
Create a platform application in SNS
Push notification platform: Choose FCM
In your code, make sure you create an application endpoint in SNS. Or do it through the console.
Test the set up by sending a test message using the console in SNS. Select your endpoint and then click on "Publish message".
Click on "custom payload for each delivery".
use this code:
{
"GCM": "{ \"notification\": {\"title\": \"Title of notification\", \"body\": \"It works\" } }"
}
Click on publish message.
To publish a message programmatically you can do:
var sns = new AWS.SNS({ apiVersion: '2010-03-31', region: 'us-east-1'})
let notification = JSON.stringify({
'notification': {
'title': "title of notification",
'body': "Your message goes here",
'data': {}
}
});
var params = {
Message: JSON.stringify({
GCM: notification
}),
MessageStructure: "json",
TargetArn: "###Your Target ARN##"
};
sns.publish(params, function(err, data) {
if (err) {
console.log("There was an error sending the push notification----> ", err)
} // an error occurred
else{
console.log("Push notification sent successfully!!!! ", data);
} // successful response
});
Now, this is only for Android of course. But it works! Adapting it to APN shouldn't be too difficult.
EDIT 1
If you want your Expo, managed flow, app to respond to the notification you are sending you need to make a couple of changes. I spent the last 3 days trying to figure this out and I finally did.
According to the Expo documentation there are 2 types of push notifications you can send, "notification" and "data". In the example I provided in the steps above I was using "notification". The problem with that is that Expo "is not made aware that the notification is being received" when you use notifications, which means you can't respond to notifications. Therefore, if you need to respond or parse the response received in the notification you need to use a push notification of type "data".
Therefore, in the code example I gave above you need to change the word "notification" for "data".
In addition to sending "data" push notification instead of just "notifications", you must include the "experienceId in your payload, which you can get from your app
Defaults to Constants.manifest.id exposed by expo-constants. In the bare workflow, you must provide a value which takes the shape #username/projectSlug, where username is the Expo account that the project is associated with, and projectSlug is your slug from app.json.
The other change you need to make is the part where the content of your push notification goes. In the code I gave above I included it in a property called "body". With the "data" type of notification it needs to be changed to "message"
Also, the part where you add your key-value pairs also need to change. In the example I gave above the propertyis called "data", but this time we need to change it to "body"
An this is the resulting code:
let dataNotification = JSON.stringify({
'data': {
'title': title,
'message': message,
'body': { your key-value-pairs},
'experienceId': "#yourExpoUsername/Your-Project-Slug"
}
});
I am having trouble testing Facebook API's Instagram webhooks
Here is what I've done :
My Facebook application is validated with manage_pages, instagram_manage_insights and instagram_basic permissions
My Facebook application is "Live"
I have subscribed my app to my Facebook page POSTing on subscribed_apps endpoint (explained here: https://developers.facebook.com/docs/instagram-api/guides/webhooks/#install-app ). I already use the "feed" field. GETing subscribed_apps endpoint give the following result:
# v6.0/{my-page-id}/subscribed_apps?fields=subscribed_fields
{
"data": [
{
"id": "{my-app-id}",
"subscribed_fields": [
"feed" // the missing "instagram" here seems normal as it is not handled by API
]
}
]
}
Using ngrok I am trying to test the webhook on my local machine. I correctly receive the "test" data (using app dashboard button) but nothing happen when I subscribe to the webhook
I don't understand what I am missing here. The feed webhook I also subscribed too, works perfectly.
UPDATE
I managed to recieve the "story_insights" hooks, so I guess my configuration is OK. But I still don’t get any incoming comment or mention. Are thesi features still available in new graph api versions ?
We have registered FCM server key on Pinpoint. We were able to successfully receive messages on our emulator when tested with Cloud Messaging on Firebase console. However, when we are trying to send push notification using GCM channel of 'sendUsersMessages' API - we receive below error for endpoint
"DeliveryStatus": "PERMANENT_FAILURE",
"StatusCode": 404,
"StatusMessage": "{\"errorMessage\":\"Unregistered Application\",\"channelType\":\"GCM\",\"pushProviderStatusCode\":\"0\",\"pushProviderError\":\"a153cc45babasomepinpointid67073b-gcm#Pinpoint is not registered in PNS.\"}"
What does this error mean? Does it mean our Pinpoint application is not registered on Firebase? Or our device doesn't have token? or something else. Couldn't find any answers. Please help
After some play around - figured out that I was using RestrictedPackageName matching my application's FCM console package name (like com.xyz.app.abc) - I removed that and push notification went through successfully.