ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.31k stars 206 forks source link

Android: JSON shown instead of notification body and title #135

Closed plato-cambrian closed 9 years ago

plato-cambrian commented 9 years ago

I'm trying to deliver chat messages to my mobile app. Here is the generated message, right before I call sender.send():

{ collapseKey: undefined,
  delayWhileIdle: undefined,
  timeToLive: undefined,
  dryRun: undefined,
  data:
   { message:
      { soproModel: 'message',
        authorId: 'identity-jimmy',
        text: 'u work',
        ts: '1435773467.318',
        attachments: [],
        channelId: 'channel-ship-devs',
        _id: '289e3dbc-976d-4311-b2f3-4c32136c4ce0',
        _rev: '1-710404eeaf81565bed1ed33891d61a57' } },
  notification:
   { title: 'Message from #ship-devs',
     body: 'u work',
     icon: 'myicon.png',
     sound: 'https://ship.hn/web/audio/cuak.mp3' } }

The message is delivered to the phone, and if the app is in the background, a notification pops up in my drawer.

The problem is the notification has no title, and the body string is the json representation of my message field.

I'm handling the notification with AppGyver/push-notifications. I'm calling pushNotification.onMessageInBackground(messageInBackgroundHandler,errorHandler); and logging the notification object that these functions get, it looks like this:

"{
  "timestamp": "2015-07-01T17:57Z",
  "message": "{\"_rev\":\"1-710404eeaf81565bed1ed33891d61a57\",\"soproModel\":\"message\",\"text\":\"u work\",\"_id\":\"289e3dbc-976d-4311-b2f3-4c32136c4ce0\",\"ts\":\"1435773467.318\",\"channelId\":\"channel-ship-devs\",\"attachments\":[],\"authorId\":\"identity-jimmy\"}",
  "collapse_key": "do_not_collapse",
  "coldstart": false,
  "payload": {
    "message": {
      "_rev": "1-710404eeaf81565bed1ed33891d61a57",
      "soproModel": "message",
      "text": "u work",
      "ts": "1435773467.318",
      "_id": "289e3dbc-976d-4311-b2f3-4c32136c4ce0",
      "channelId": "channel-ship-devs",
      "attachments": [],
      "authorId": "identity-jimmy",
      "$$hashKey": "object:64"
    },
    "gcm.notification.title": "Message from #ship-devs",
    "gcm.notification.icon": "myicon.png",
    "gcm.notification.sound": "https://ship.hn/web/audio/cuak.mp3",
    "gcm.notification.body": "u work"
  },
  "uuid": "0be45002-dbb3-4ece-9755-e4a89ab6bc4f",
  "from": "156632312728",
  "foreground": false
}"

What must I do to configure my notification?

plato-cambrian commented 9 years ago

Possibly relevant https://github.com/ToothlessGear/node-gcm/issues/131

hypesystem commented 9 years ago

The functionality in #131 was added in version 0.10 (PR #127). I assume this is the code you are using.

I have no idea about AppGyver, etc., so I am at a bit of a loss here.

plato-cambrian commented 9 years ago

Thanks @hypesystem. I am using 0.10.
So, assuming a correct reference implementation on the phone, what I'm sending should automatically show up in the notification drawer with body and title, right?

hypesystem commented 9 years ago

Yes.