snaas icon indicating copy to clipboard operation
snaas copied to clipboard

Making push notifications work

Open thomasorten opened this issue 6 years ago • 8 comments

Hi! I'm trying to make push notifications work on the backend. I see functions PlatformCreate in http/platform.go and core/platform.go, which takes an app, cert and key. But I don't see these being called from anywhere. Would calling PlatformCreate e.g. on app creation create the necessary endpoints for SNS? Upon using terraform to set up the project with aws, I see a topic endpoint-state-change, but no platforms/applications in SNS. Or would there be a manual way of adding a platform and connections through the AWS console (not so familiar with sns)?

thomasorten avatar Feb 21 '18 09:02 thomasorten

Hej!

Ideally the platform creation should be wired up in the SNAAS Console together with the other admin tasks, which is doable but currently not planned due to time constraints. If done tho, it would allow to create platforms per app for android, ios and ios sandbox and it shouldn't require to touch AWS at all besides a successful terraform run.

You have couple of options here:

  • Add platform handling to the Console
  • build a small binary which calls http.PlatformCreate with input from the command line
  • create Applications manually in SNS and insert the appropriate records into Postgres directly

Let me know if I can be of help with going further, or something is still unclear. Of course always happy to welcome contributions in form of PRs or documentation.

xla avatar Feb 21 '18 14:02 xla

Hi again, Thanks for the response. After the terraform run, only one topic is created in SNS. Say I wanted to create a sandbox platform, here I pass the cert and key, and I do get a response back. The code:

handler.PlatformCreate( core.PlatformCreate( platforms, sns.AppCreateAPNS(snsAPI, "arn:aws:sns:eu-central-1:xxxxxx:endpoint-state-change"), sns.AppCreateAPNSSandbox(snsAPI, "arn:aws:sns:eu-central-1:xxxxxx:endpoint-state-change"), sns.AppCreateGCM(snsAPI, "arn:aws:sns:eu-central-1:xxxxxx:endpoint-state-change"), ), ),

Returns:

{"active":false,"arn":"arn:aws:sns:eu-central-1:xxxxxxx:app/APNS/test-1","deleted":false,"ecosystem":2,"id":"131350915914400267","name":"test-1","scheme":"http","created_at":"2018-02-22T21:41:06.845299Z","updated_at":"2018-02-22T21:41:06.845299Z"}

Still it seems no messages are delivered. Again, I'm not that familiar with SNS, but I have enabled logging to cloudwatch. Something else I need to be aware of?

Thanks again.

thomasorten avatar Mar 06 '18 13:03 thomasorten

Hej @thomasorten how did go about the cert and private key of the app? Before you can configure SNS properly you need to setup those for your iOS app. The response indicates that the creds you passed to SNS couldn't be used when communicating to APNS (from SNS).

xla avatar Mar 06 '18 14:03 xla

Ah, ok. Basically passed the data from the console like such:

-d '{"name": "test-1", "ecosystem": 2, "scheme": "http", "key": "-----BEGIN PRIVATE KEY-----\xxx\n-----END PRIVATE KEY-----" , "cert": "-----BEGIN CERTIFICATE-----\xxx\n-----END CERTIFICATE-----" }'

What should be the correct response?

thomasorten avatar Mar 06 '18 14:03 thomasorten

The application is created, but there appears no connections to the platform endpoint is made. Devices are registered in the DB.

thomasorten avatar Mar 06 '18 14:03 thomasorten

My answer was confusing. The response indicates that the platform was created, in order for it to be picked up by SIMS it needs to be activated. A bool that can be flipped in the DB.

xla avatar Mar 06 '18 14:03 xla

Ok I'll try that, thanks.

thomasorten avatar Mar 06 '18 14:03 thomasorten

Still trying to figure this out.. Must be something I'm missing..

Applications are set as production=true in DB.

When I publish a post, nothing appears in the SQS queue (object-state-change*). Creating a connection though, does put a message in flight under connection-state-change, then later under connection-state-change-dlq.

I can create applications through PlatformCreate, and they do appear with certificates.

In DB, endpoint_arn under "devices" table of the app is empty. Only one topic in SNS - endpoint-state-change..

thomasorten avatar Apr 05 '18 12:04 thomasorten