{"action":"created","issue":{"url":"https://api.github.com/repos/j3k0/ganomede-notifications/issues/24","labels_url":"https://api.github.com/repos/j3k0/ganomede-notifications/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/j3k0/ganomede-notifications/issues/24/comments","events_url":"https://api.github.com/repos/j3k0/ganomede-notifications/issues/24/events","html_url":"https://github.com/j3k0/ganomede-notifications/pull/24","id":113808796,"number":24,"title":"[WIP] GCM Sender","user":{"login":"elmigranto","id":886388,"avatar_url":"https://avatars.githubusercontent.com/u/886388?v=3","gravatar_id":"","url":"https://api.github.com/users/elmigranto","html_url":"https://github.com/elmigranto","followers_url":"https://api.github.com/users/elmigranto/followers","following_url":"https://api.github.com/users/elmigranto/following{/other_user}","gists_url":"https://api.github.com/users/elmigranto/gists{/gist_id}","starred_url":"https://api.github.com/users/elmigranto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elmigranto/subscriptions","organizations_url":"https://api.github.com/users/elmigranto/orgs","repos_url":"https://api.github.com/users/elmigranto/repos","events_url":"https://api.github.com/users/elmigranto/events{/privacy}","received_events_url":"https://api.github.com/users/elmigranto/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-28T12:22:59Z","updated_at":"2015-11-05T10:58:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/j3k0/ganomede-notifications/pulls/24","html_url":"https://github.com/j3k0/ganomede-notifications/pull/24","diff_url":"https://github.com/j3k0/ganomede-notifications/pull/24.diff","patch_url":"https://github.com/j3k0/ganomede-notifications/pull/24.patch"},"body":"Implemented sender for Android notifications. Works, but with some limitations due to GCM API.\r\n\r\n# Issues\r\n\r\n### The main issue…\r\n\r\n…is that we can not send arbitrary payload alongside with notification, [Google only allows](https://developers.google.com/cloud-messaging/http-server-ref#downstream) (see specs under \"**Payload** `data`\"):\r\n* key/value pairs;\r\n* set of keys is restricted;\r\n* it's strongly advised for values to be strings.\r\n\r\nSo for now I send the following:\r\n\r\n``` coffee\r\ndata:\r\n  json: JSON.stringify(notification) # ganomede's notification\r\n\r\nnotification:\r\n  icon: config.pushApi.gcm.icon  # String with icon's name from Android App resoures\r\n  # if notification.push has title[] and message[]\r\n  title_loc_key: ''\r\n  title_loc_args ''\r\n  body_loc_key: ''\r\n  body_loc_args: ''\r\n  # otherwise\r\n  title: config.pushApi.gcm.defaultNotification.title\r\n```\r\n\r\n****\r\n\r\n### Appearance\r\n\r\nWhen user clicks on notification, nothing happens for now, we need to specify stuff (`click_action`).\r\n\r\nNotifications are not grouped. So if we send 20, there will be 20 cards in phone's notification tray. That is solvable by specifying `tag`.\r\n\r\nThese 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.\r\n\r\n# How to set things up\r\n\r\nThis part is pretty straight-forward:\r\n\r\n1. get GCM API Key (from somewhere around [here](https://developers.google.com/cloud-messaging/));\r\n2. set that as `process.env.GCM_API_KEY`."},"comment":{"url":"https://api.github.com/repos/j3k0/ganomede-notifications/issues/comments/154030091","html_url":"https://github.com/j3k0/ganomede-notifications/pull/24#issuecomment-154030091","issue_url":"https://api.github.com/repos/j3k0/ganomede-notifications/issues/24","id":154030091,"user":{"login":"elmigranto","id":886388,"avatar_url":"https://avatars.githubusercontent.com/u/886388?v=3","gravatar_id":"","url":"https://api.github.com/users/elmigranto","html_url":"https://github.com/elmigranto","followers_url":"https://api.github.com/users/elmigranto/followers","following_url":"https://api.github.com/users/elmigranto/following{/other_user}","gists_url":"https://api.github.com/users/elmigranto/gists{/gist_id}","starred_url":"https://api.github.com/users/elmigranto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elmigranto/subscriptions","organizations_url":"https://api.github.com/users/elmigranto/orgs","repos_url":"https://api.github.com/users/elmigranto/repos","events_url":"https://api.github.com/users/elmigranto/events{/privacy}","received_events_url":"https://api.github.com/users/elmigranto/received_events","type":"User","site_admin":false},"created_at":"2015-11-05T10:58:07Z","updated_at":"2015-11-05T10:58:07Z","body":"There's a simple test for GCM sender much like APN one:\r\n\r\n``` bash\r\nGCM_API_KEY=key GCM_TEST_TOKEN=token mocha tests/test-sender.coffee\r\n```\r\nThis 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`."}}