j3k0 / ganomede-notifications

Long-pull notification service for Ganomede
0 stars 0 forks source link

[WIP] GCM Sender #24

Closed elmigranto closed 9 years ago

elmigranto commented 9 years ago

Implemented sender for Android notifications. Works, but with some limitations due to GCM API.

Issues

The main issue…

…is that we can not send arbitrary payload alongside with notification, Google only allows (see specs under "Payload data"):

So for now I send the following:

data:
  json: JSON.stringify(notification) # ganomede's notification

notification:
  icon: config.pushApi.gcm.icon  # String with icon's name from Android App resoures
  # if notification.push has title[] and message[]
  title_loc_key: ''
  title_loc_args ''
  body_loc_key: ''
  body_loc_args: ''
  # otherwise
  title: config.pushApi.gcm.defaultNotification.title

Appearance

When user clicks on notification, nothing happens for now, we need to specify stuff (click_action).

Notifications are not grouped. So if we send 20, there will be 20 cards in phone's notification tray. That is solvable by specifying tag.

These two (and maybe some others) should probably be responsibility of service who sent the notification in the first place. But that varies from APN, and same APN functionality is missing (unless it has default behaviour, let me know, if we need to work on these). Also, GCM allows to send iOS notifications as well, maybe that can be useful.

How to set things up

This part is pretty straight-forward:

  1. get GCM API Key (from somewhere around here);
  2. set that as process.env.GCM_API_KEY.
elmigranto commented 9 years ago

Okay, I think I need to redo sender-cli, thought it'll be easier to incorporate, but there are some issues.

j3k0 commented 9 years ago

No problems, the client side isn't ready as well.

j3k0 commented 9 years ago

Any progress? I was hoping to finalize that quickly, our client has been waiting for GCM since the android launching...

For the custom payload, sending it as stringified JSON is fine.

For the tag, it can be set using the body.push.app field, this will make enough sense.

elmigranto commented 9 years ago

Finishing up today or tomorrow.

elmigranto commented 9 years ago

This is ready. Please test it with real GCM and Apple APIs, though.

I have hard time getting notifications through GCM, and can not test tag part for now. It takes like 15 minutes for notification to appear, if at all.

j3k0 commented 9 years ago

Okay, can this be tested independently of anything else? (How?)

elmigranto commented 9 years ago

There's a simple test for GCM sender much like APN one:

GCM_API_KEY=key GCM_TEST_TOKEN=token mocha tests/test-sender.coffee

This will send one notification to the device. To test sending multiple notifications, you can modify tokens inserted by populateRedis within sender-cli.coffee so they are of type gcm.

elmigranto commented 9 years ago

There is a test app that is able to receive notifications here and the guide to set it up here