Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure GCM push notifications? #1096

Closed
maxlinux2000 opened this issue Oct 14, 2015 · 29 comments
Closed

How to configure GCM push notifications? #1096

maxlinux2000 opened this issue Oct 14, 2015 · 29 comments

Comments

@maxlinux2000
Copy link

Hi
I want to activate GCM notifications.

so I have creates a new project in the google console with te following API

xpush4

And this is the configuration... but obviously doesn't work.

xpush1
xpush2
xpush3

Where is my error?

And the second question... how to test it?

Can I send a message to a user not connected and hi receive a notification on his android phone?

tnx
MaX

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@geekgonecrazy
Copy link
Contributor

@maxlinux2000 Let me take a look at this process. We're using a package i'm not familiar with to do the push notifications. So I need to brush up.

@gmsecrieru
Copy link
Contributor

@geekgonecrazy For what it's worth, if you are referring to raix:push we are using an outdated RC version. Might be an opportunity to update.

@geekgonecrazy
Copy link
Contributor

@gmsecrieru good point! Hopefully its more flexible.

@Tharnas
Copy link

Tharnas commented Oct 16, 2015

@maxlinux2000 I also have problems configuring GCM push notifications. I found a way to check if the phone receives the notification on stackoverflow (provide there the API key and the device ID (you can find this id in the logs of the server when you login the first time on a new phone))

I can receive the notifications from this php script, but not from the rocketchat server.

I hope this helps.

@maxlinux2000
Copy link
Author

... the ID of my phone? sorry but I don't understand.
witch server and witch log in order to get this ID?

Another problem, the interface of the google console has changed a lot. Do you know
any recent tutorial how to configure the push notification? I want to check if something is wrong in my configuration.

MaX

@Tharnas
Copy link

Tharnas commented Oct 17, 2015

Sorry I didn't explained myself well.

I expect you have your Rocket.Chat running on your own server (e.g. on docker like for me) and you build your android application like explained in this article.

After you built the application you install it on your phone and log in to your server. During the login you check the stdout of your server. (with docker you can do it with docker logs -f "containername").
Then the server will write something like this:

[method] loadLocale: de
CLIENT register [ 'OK' ]
CLIENT token [ { gcm: 'A** ... **' } ]
[publish] settings
[publish] admin-settings

Where A****** is the device ID.

Afterwards you can follow the article on stackoverflow to check if your phone receives the notification you sent from phpfiddle.

@Tharnas
Copy link

Tharnas commented Oct 17, 2015

Meanwhile I managed to make the push notifications work.
For me it didn't work in the beginning because I didn't restart the server after I configured push notifications. (Could be nice to have a hint that a restart is required)

@maxlinux2000
Copy link
Author

Many many tnx for your help.

Please post here some screenshot of your google console configuration,
about the GCM.(obviously deleting private data)

Another question about these mysterious (for me) GCM in rocket.chat:
If you send a private message to a user that is not connected, this
user will be receive immediately a push message on his phone like
whatsapp?

On 10/17/15, Tharnas [email protected] wrote:

Meanwhile I managed to make the push notifications work.
For me it didn't work in the beginning because I didn't restart the server
after I configured push notifications. (Could be nice to have a hint that a
restart is required)


Reply to this email directly or view it on GitHub:
#1096 (comment)

ciao,
MaX

@Tharnas
Copy link

Tharnas commented Oct 17, 2015

Your welcome :-)

I went to here to get my API Key and Sender ID:
google developers
Then I provided this two ids to Rocket.Chat server like here: (and afterwards restarted the server!!!)
rocket chat push
When I built the application i put a config.push.json file in the root folder of Rocket.Chat with the following content: (didn't test if this step is realy needed)

{
  "gcm": {
    "apiKey": "A*****",
    "projectNumber": 8******
  },
  "production": true,
  "badge": true,
  "sound": true,
  "alert": true,
  "vibrate": true
}

After I installed the application on my phone, logged in and sent a message it looks like this:
screenshot_2015-10-17-21-31-04

@maxlinux2000
Copy link
Author

Ok, I can confirm that the json file is not necessary because the chat
wont run due the error that he can not load the push configutarion 2
times.

Now my problem :)

Push: Send message "@maxlinux2000" via query { userId: 'QPE3RsvcJ6bsaakQP' }
I20151018-04:36:16.618(-4)? Push: Sent message "@maxlinux2000" to 0
ios apps 0 android apps
I20151018-04:36:16.623(-4)? Push, GUIDE: The "Push.appCollection" is
empty - No clients have registred on the server yet...

A question more:
You android app, is this build in cordova/phonegap?

https://github.com/RocketChat/Rocket.Chat/wiki/Build-the-Android-Cordova-Web-App-and-connect-to-your-own-Rocket.Chat-Server

regards
MaX

On 10/17/15, Tharnas [email protected] wrote:

Your welcome :-)

I went to
here
to get my API Key and Sender ID:
google developers
Then I provided this two ids to Rocket.Chat server like here: (and
afterwards restarted the server!!!)
rocket chat push
When I built the application i put a config.push.json file in the root
folder of Rocket.Chat with the following content: (didn't test if this step
is realy needed)

{
  "gcm": {
    "apiKey": "A*****",
    "projectNumber": 8******
  },
  "production": true,
  "badge": true,
  "sound": true,
  "alert": true,
  "vibrate": true
}

After I installed the application on my phone, logged in and sent a message
it looks like this:
screenshot_2015-10-17-21-31-04


Reply to this email directly or view it on GitHub:
#1096 (comment)

ciao,
MaX

@Tharnas
Copy link

Tharnas commented Oct 18, 2015

When I send a message it looks like this:

[methods] canAccessRoom ->  userId: XC****** rid: XC******jg******
stream.permissions.read XC****** XC******jg******
[methods] canAccessRoom ->  userId: XC****** rid: XC******jg******
Push: Send message "@testuser" via query { userId: 'jg******' }
send to token { gcm: 'A************************' }
sendGCM [ 'A*****************' ] { _id: '3a**********',
  createdAt: Sun Oct 18 2015 08:51:09 GMT+0000 (UTC),
  createdBy: '<SERVER>',
  from: 'push',
  title: '@testuser',
  text: 'Test',
  payload:
   { rid: 'XC******jg******',
     sender: { _id: 'XC******', username: 'testuser' },
     type: 'd',
     name: null },
  badge: 1,
  sound: 'chime',
  apn: { text: '@testuser:\nTest' },
  query: { userId: 'jg******' } }
Create GCM Sender using "A*******"
A:Send message to: A**********
Push: Sent message "@testuser" to 0 ios apps 1 android apps
Push, GUIDE: The "Push.appCollection" - No APN clients have registred on the server yet...
ANDROID: Result of sender: {"multicast_id":78*******,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:144******"}]}

Your result looks like that the app does not register at the server.

As I have a docker environment so I use this way to build it: https://github.com/RocketChat/Rocket.Chat/wiki/How-to-Build-Rocket.Chat-for-Android

Is it possible for you to chat between webpage and app?
When you send the message from the webpage to the phone do you have the app open? (it will just send a notification when the app is not open / in foreground)

@maxlinux2000
Copy link
Author

OK I understand the problem...
Rocket.chat.cordova don't support push messages, so no way to have a cordova custom app that can substitute whatsapp.

So, new strategy: 2 app!
One native with my custom rocket.chat
One in cordova with others stuffs.

But I never built a native app, so please tell me if these steps are corrects:

In order to build my own rocket.chat app for android

a) a local ubuntu 14.04 - 64bit on machine with 4GB ram
b) android studio with 22 and 23 sdk + java7
then I will install the envoronment for docker:

apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main

" > /etc/apt/sources.list.d/docker.list

apt-get update

apt-get -y upgrade

apt-get install -y linux-image-generic-lts-trusty

reboot

and follow at reboot:

apt-get install -y docker-engine

docker run hello-world

docker installed!

Now the rocket.chat environment:

apt-get install -y openjdk-7-jdk

apt-get install -y bison git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip

apt-get install -y g++-multilib

git clone https://github.com/rocketchat/Rocket.Chat

docker run -i -t -v /root/Rocket.Chat rocketchat/meteor12androidbuilder

cd Rocket.Chat

meteor add-platform android

meteor add crosswalk

meteor build --server http://chat.mydomain.org ./build

and... if all run correctly I will have an apk configured for my server... correct?


Following, now I will configure a rocket,chat server in a VPS under ubuntu 14.04 64bit (with dns name chat.mydomain.org)

(clean ubuntu 14.04 64bit installation on vps with public IP address and all as root)
(I know that is not good, but in this first phase I can't considerate the security problems)

apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main

" > /etc/apt/sources.list.d/docker.list

apt-get update

apt-get -y upgrade

apt-get install -y linux-image-generic-lts-trusty

reboot

apt-get install -y docker-engine

docker run hello-world

git clone https://github.com/rocketchat/Rocket.Chat

docker run -i -t -v /root/Rocket.Chat rocketchat/meteor12androidbuilder

cd Rocket.Chat

meteor add-platform android

meteor add crosswalk

meteor build --server http://chat.mydomain.org ./build

With this, I will have a rocketchat server runnig a port 80 on http://chat.mydomain.org


that's sound good? Do you see something wrong or omitted?

regards
MaX

@Tharnas
Copy link

Tharnas commented Oct 18, 2015

I'm not sure if I realy got you.
Why would you build 2 apps? One is enough.

I build mine like the following: (after I installed docker and probably git on a new clean machine)

cd /root/
git clone https://github.com/rocketchat/Rocket.Chat

docker run -i -t -v /root/Rocket.Chat:/home/Rocket.Chat rocketchat/meteor12androidbuilder

-- create apk
cd /home/Rocket.Chat
meteor add-platform android
meteor build --server http://chat.mydomain.org ./build

-- sign apk
cd build/android

-- if you don't have a keystore yet
keytool -genkey -alias appName -keyalg RSA -keysize 2048 -validity 10000

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 release-unsigned.apk appName
$ANDROID_HOME/build-tools/23.0.1/zipalign 4 release-unsigned.apk  appName_`date +"%Y-%m-%d_%H-%M"`.apk
exit

(You will find the apk in /root/Rocket.Chat/build/android/appName_date +"%Y-%m-%d_%H-%M".apk)
I'm not sure if you need the signing only if you want to publish it through play store or also to install it on the phone.

You don't need to install all of this stuff "openjdk-7-jdk bison git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip g++-multilib" on the host machine (if I get it right). The docker image "rocketchat/meteor12androidbuilder" contians all the dependencies it needs.

The build of the apk in docker is independent on how you publish your server.

@Tharnas
Copy link

Tharnas commented Oct 18, 2015

By the way I'm not sure if you can build the latest version as there are currently some issues: #1156

@maxlinux2000
Copy link
Author

TNX for the help!

before build it, I need to re-install my system from 0

My pc is a 64bit, but I'm using the 32bit version of ubuntu.... So
backup, backup and backup!!

I think I will need 2 day before to build the app. I hope that the bug
will be solved. :)

So, I will answer to this very interesting topic, asap.
Now reboot to new installation and reconfigure all my system :(

regards
MaX

On 10/18/15, Tharnas [email protected] wrote:

By the way I'm not sure if you can build the latest version as there are
currently some issues:
#1156


Reply to this email directly or view it on GitHub:
#1096 (comment)

ciao,
MaX

@Tharnas
Copy link

Tharnas commented Oct 18, 2015

You are welcome.
I'm pleased to help you out.

@maxlinux2000
Copy link
Author

Hi all,
I'm coming back after rebuild from zero, my develop laptop with ubuntu 64bit.

During these day I've tried to build the chat in docker, with success, but I have a big problem:

I need to integrate with a Iframe the chat in my cordova app.
I have altrady do this work, but now is rising again the on topic problem:

HOW TO add the push notifications (in Cordova)?

I'm search a plugin and this seem good:
https://github.com/phonegap/phonegap-plugin-push

but I need an esay way to check if my app is sending the ID of the phone to the server chat.
Is there a log in the server where i can chek it? where? (the server is a ubuntu 14.04 64bit.)

last but not last, Some one have experiencop how to use phonegap-plugin-push in a real proj?

regards
MaX

@Tharnas
Copy link

Tharnas commented Oct 25, 2015

Welcome back :-)

with you can run the following command to see the output of the server:

docker logs -f "containername"

When the client registers at the server you will see something like this:

[method] loadLocale: de
CLIENT register [ 'OK' ]
CLIENT token [ { gcm: 'A** ... **' } ]
[publish] settings
[publish] admin-settings

I think the client registers always after you installed the app and start it or log in. Not sure.

@maxlinux2000
Copy link
Author

during the last days i have do a lot of works, far of my favourite chat, but now I'm back :)

I have some problem to build rocketchat without docker
(https://github.com/RocketChat/Rocket.Chat/wiki/Deploy-Rocket.Chat-without-docker)
due a bug.

... with your last post i assume that I can see the logs using the doker... correct?

but with your command I receive that:

root@chat:# docker logs -f "rocket.chat"
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
root@chat:
#

My environment run in VPS server ubuntu 64bit and rocketchat is lauched with:

screen
cd Rocket.Chat/
git pull
meteor update
meteor
(ctrl-a-d to exit from screen)

How I can do it?

@Tharnas
Copy link

Tharnas commented Oct 29, 2015

Sorry this is my fault, use docker logs -f rocket.chat (without ")

For building there is also an image for docker.
I will write you later more detailed when i have more time.

@Tharnas
Copy link

Tharnas commented Oct 29, 2015

So, I'm back.

It looks like your docker client is not properly connected to the docker deamon. Check if set it up correctly. (https://docs.docker.com/installation/ubuntulinux/)
When it's correctly set up you can run docker version and you should get something like this:

root@chat:~# docker version
Client:
 Version:      1.8.3
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f4bf5c7
 Built:        Mon Oct 12 05:39:44 UTC 2015
 OS/Arch:      linux/amd64

Server:
 Version:      1.8.3
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f4bf5c7
 Built:        Mon Oct 12 05:39:44 UTC 2015
 OS/Arch:      linux/amd64

Afterwards you can follow the instructions on this page https://github.com/RocketChat/Rocket.Chat/wiki/Deploy-with-Docker to setup the rocket.chat server. (you need to have docker-compose installed)

After the server is running you can build your application like described there https://github.com/RocketChat/Rocket.Chat/wiki/How-to-Build-Rocket.Chat-for-Android

@maxlinux2000
Copy link
Author

Hi, tnk for help!
I will setup the machine soon following your post.

My docker daemon is not runnig:

root@chat:~# docker version
Client:
Version: 1.8.3
API version: 1.20
Go version: go1.4.2
Git commit: f4bf5c7
Built: Mon Oct 12 05:37:18 UTC 2015
OS/Arch: linux/amd64
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?

Today I have received my first push message (!!) using this tutorial:

http://phonegappro.com/tutorials/apache-cordova-phonegap-push-notification-tutorial-part-1/

Now in theory my cordova app (with rocketchat in a iframe) can self register in my chat server, sending the phone-id and the chat, always in theory, can send push messages....

but now my dude:

How can I send push messege from rocket.chat using the interface?
In the wiki I cannot found the steps how to do it.
I thinks that rocket.chat must send push messages, when I send a private message to a person that is not connected to the chat, in this moment... like whatsapp :)
But Rocket.chat can do that?

@bufke
Copy link

bufke commented Dec 5, 2015

I'm trying to understand this all - are push notifications impossible when using self hosted rocket chat and the RocketChat app from the Play store?

@GaWr26
Copy link

GaWr26 commented Dec 8, 2015

Please clarify the setup process for this.
Does this now work on self hosted servers and the current App(2.1.0) in the Play Store? In the play store it says: "Support push notification from self hosted deployments via our gateway." What does this mean?

I have setup my app like @Tharnas explained and put the data for Server API Key and Sender ID in the Settings but push doesn't seem to work

@Tharnas
Copy link

Tharnas commented Dec 8, 2015

Hi,
I have to admit it's a little bit ago when I was working the last time on Rocket.Chat. So I hope I don't tell you any lie.

With Google Cloud Messaging (GCM) it's like that:
When you register for an API key, you have to provide the package name of your (android) application. Therefore your phone knows which app to invoke when a notificaiton from GCM is received.

This means you need and API key from GCM with the package name of the app that is uploaded to the play store. As you are not the owner of this app/package name I don't know if you are able/allowed to register for this package name. (Not sure if or how they can check this)

I will try to make it run with the app from the play store and let you know.

@GaWr26
Copy link

GaWr26 commented Dec 8, 2015

@Tharnas thanks for the update. There is a new property push_gateway in the PUSH Settings on the server. This might somehow be the key to getting it work with the app from the store. Unfortunately I can't find any documentation on how to use this.

@Tharnas
Copy link

Tharnas commented Dec 8, 2015

I also saw that after I updated my server.

Currently I struggle with logging in from the application. Need to check this first.

@GaWr26
Copy link

GaWr26 commented Dec 8, 2015

This works now and can be closed. Just install the latest version of the Server and get the Android App from the play store. Everything is configured to work by default. IOs App is already in the approval process. Big Up Rocket.Chat Team!

@shantanuthatte
Copy link

For guys who end up at this issue:

  1. Get the API Key and Project ID from Google Developer Console.
  2. Enter the following details in admin/Push:
    • Gateway: https://rocket.chat
    • GCM API Key: <Your-API-Key>
    • GCM Project ID: <Your-Project-ID>
  3. Install app from Play Store.
  4. Login
  5. Test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants