RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.65k stars 10.65k forks source link

[ERROR] Push notification error #10365

Closed ghost closed 5 years ago

ghost commented 6 years ago

Description:

During push notification error occurs and we do not get any notifications. More info below.

Server Setup Information:

Steps to Reproduce:

  1. Send any message.

Expected behavior:

We get notification on android.

Actual behavior:

We get an error without any notification on android.

Relevant logs:

[34mI20180406-13:35:01.984(0) rocketchat_logger rocketchat_logger.js:278 [34mMeteor ➔ method push_test -> userId: aRXp8EKHARyQ2pSr8 , arguments:  {} 
[34mI20180406-13:35:02.421(0) Push: Send message "@my_name" via query { userId: 'aRXp8EKHARyQ2pSr8' } 
[34mI20180406-13:35:02.434(0) send to token { gcm: 'gcm_token' } 
[34mI20180406-13:35:02.437(0) sendGCM [ 'gcm_token' ] { _id: 'c6s8QcCNDuEpwMqE5',   createdAt: 2018-04-06T13:35:01.995Z,   createdBy: '<SERVER>',   from: 'push',   title: '@my_name',   text: 'This is a push test message',   sound: 'default',   apn: { text: '@my_name:<br>This is a push test message' },   query: { userId: 'aRXp8EKHARyQ2pSr8' },   sent: false,   sending: 0 } 
[34mI20180406-13:35:02.445(0) Create GCM Sender using "XXX" 
[34mI20180406-13:35:02.446(0) A:Send message to: gcm_token 
[34mI20180406-13:35:02.447(0) Push: Sent message "@my_name" to 0 ios apps 1 android apps 
[34mI20180406-13:35:02.458(0) Push, GUIDE: The "Push.appCollection" - No APN clients have registred on the server yet... 
[34mI20180406-13:35:02.498(0) ANDROID ERROR: result of sender: undefined 
ghost commented 6 years ago

Same issue here. Was working a few days ago but suddenly isn't.

geekgonecrazy commented 6 years ago

If you restart the server does it start working again?

ghost commented 6 years ago

@geekgonecrazy it does not work

aramix commented 6 years ago

Anything new on this issue? I am also experiencing this on v0.65.1

geekgonecrazy commented 6 years ago

Are you using our push gateway or did you add your own GCM/APN information in the push section?

Also are you using with our mobile apps from the stores?

magicbelette commented 6 years ago

Edit : found the solution here https://github.com/RocketChat/Rocket.Chat/issues/4909#issuecomment-279866436 Experiencing the same "issue" but I'm not sure to understand how to configure my RC instance.

Here : https://rocket.chat/docs/administrator-guides/notifications/push-notifications/, I disabled the gateway but nothing explain what to do with firebase keys and RC push settings.

Cheers

aramix commented 6 years ago

@geekgonecrazy I am using my own GCM credentials and using react-native apps built from the source and configured to use my own sender id.

aramix commented 6 years ago

@magicbelette did you upgrade reactnative app to FCM from GCM?

aramix commented 6 years ago

Seems to be fixed with 0.66.0 using FCM credentials instead of GCM.

teach-ed commented 6 years ago

Th his is awesome news. Awesome

On Jun 30, 2018 at 8:16 PM, wrote:

Seems to be fixed with 0.66.0 using FCM credentials instead of GCM.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

magicbelette commented 6 years ago

@aramix Yes, I'm using FCM credentials.

My problem is that my server must access Firebase servers through HTTPS_PROXY but I can't find where to configure it...

aramix commented 6 years ago

Set it as an env var and restart server meteor should use it automatically once there is an env var

magicbelette commented 6 years ago

I already tried within the init script as I'm using systemd to run Rocket.chat Environment=NODE_ENV=production HTTPS_PROXY=https://my.proxy.local:3128 HOME=<ROCKET_HOME>...

https://rocket.chat/docs/installation/manual-installation/pm2-systemd-upstart/

aramix commented 6 years ago

hmm.. can't help much. I am using mup to deploy my server

magicbelette commented 6 years ago

My proxy only authorizes requests to https://fcm.googleapis.com/. Maybe that's not the good URL to contact firebase servers :thinking: ?

geekgonecrazy commented 5 years ago

A lot has changed here. Going to go ahead and close

stranger9372 commented 3 years ago

hi. I have the same problem. I am using rocket chat server version 3.12.1 and already set the firebase server key and sender id in Push settings and restart multiple times. default cloud gateway works well and delivers messages to devices, but the self-configured mode does not. I tried to reproduce this part: https://github.com/RocketChat/Rocket.Chat/blob/develop/app/push/server/gcm.js using my log data and executed on: https://npm.runkit.com/meteor but error doesn't occur and Push Notification delivers to the device successfully. What kind of problems may lead to ANDROID ERROR: result of sender: undefined ?

Reproduce Code From server/gcm.js


var gcm = require('node-gcm');
var sender = new gcm.Sender('fcm_server_key');
var userTokens = [   'firebase_user_token' ]
var notification =  {   createdAt: '2021-09-09T18:46:47.180Z',   createdBy: '<SERVER>',   sent: false,   sending: 0, 
  from: 'push',  title: 'MyTitle',   text: 'test',   userId: 'uid',  
 payload: {     host: 'myHost',     messageId: 'mid',     notificationType: 'message',  
  rid: 'rid',     sender: {       _id: 'sid',       username: 'uname',       name: 'name'     },    
 senderName: 'sname',     type: 'd'   }, 
 badge: 2,   sound: 'default',   notId: 257066178,   apn: { category: 'MESSAGE' },   
gcm: {     image: 'myhost/assets/favicon_192.png',     style: 'inbox'   },  
 image: 'myHost/assets/favicon_192.png',   style: 'inbox' } 

console.log('sendGCM', userTokens, notification);

const data = notification.payload ? { ejson: JSON.stringify(notification.payload) } : {};
data.title = notification.title;
data.message = notification.text;

if (notification.image != null) {
    data.image = notification.image;
}
if (notification.android_channel_id != null) {
    data.android_channel_id = notification.android_channel_id;
} else {
    console.log('For devices running Android 8.0 or later you are required to provide an android_channel_id.
See https://github.com/raix/push/issues/341 for more info');
}
if (notification.badge != null) {
    data.msgcnt = notification.badge;
}
if (notification.sound != null) {
    data.soundname = notification.sound;
}
if (notification.notId != null) {
    data.notId = notification.notId;
}
if (notification.style != null) {
    data.style = notification.style;
}
if (notification.summaryText != null) {
    data.summaryText = notification.summaryText;
}
if (notification.picture != null) {
    data.picture = notification.picture;
}
if (notification.actions != null) {
    data.actions = notification.actions;
}

if (notification.forceStart != null) {
    data['force-start'] = notification.forceStart;
}
if (notification.contentAvailable != null) {
    data['content-available'] = notification.contentAvailable;
}
console.log(data)
const message = new gcm.Message({
        collapseKey: notification.from,
        // Requires delivery of real-time messages to users while device is in Doze or app is in App Standby.
        // https://developer.android.com/training/monitoring-device-state/doze-standby#exemption-cases
        priority: 'high',
        //    delayWhileIdle: true,
        //    timeToLive: 4,
        //    restricted_package_name: 'dk.gi2.app'
        data,
    });
console.log(message)
sender.send(message, userTokens, 5, function(err, result) {
    if (err) {
        console.log({ msg: 'ANDROID ERROR: result of sender', result });
        return;
    }

    if (result === null) {
        console.log('ANDROID: Result of sender is null');
        return;
    }

    console.log({ msg: 'ANDROID: Result of sender', result });

    if (result.canonical_ids === 1 && userToken) {
        try {
            _replaceToken({ gcm: userToken }, { gcm: result.results[0].registration_id });
        } catch (err) {
            console.log({ msg: 'Error replacing token', err });
        }
    }
    if (result.failure !== 0 && userToken) {

        try {
            _removeToken({ gcm: userToken });
        } catch (err) {
            console.log({ msg: 'Error removing token', err });
        }
    }
});```