Cloudkibo / CloudKibo

CloudKibo
0 stars 0 forks source link

Configure Voip push notification #511

Closed sumairasaeed closed 7 years ago

sumairasaeed commented 7 years ago

Here we need to configure server to send voip push notification to iOS using APNS when application is in background.

sojharo commented 7 years ago

I have gone through some articles in this about how to integrate apns with nodejs. I found some libraries and some examples on how to do this. I couldn't find any of them using push notification. Maybe I couldn't figure out if they are push notification. I would discuss these libraries with sumaira today in order to pick correct library.

jekram commented 7 years ago

are we not doing push notification with apple?

sojharo commented 7 years ago

We need to use pushkit which is not working with current setup of azure push notifications.

sojharo commented 7 years ago

Sumaira and I worked on this, after discussion, we chose the library and I started integrating apns in our server. After integration, when I started the server, it got crashed when server tried to import library. The error was coming from inside the library. I have opened the issue on the repository of author here:

https://github.com/node-apn/node-apn

Next, I will try other library.

sojharo commented 7 years ago

We found another library and I have halfway integrated the library. It is little bit complex to do setup of this library. This new library integration is half done. I would complete the remaining of this tomorrow, IA.

http://logicalparadox.github.io/apnagent/

https://github.com/logicalparadox/apnagent

sojharo commented 7 years ago

I tried installation of other library but also didn't work I tried installing the new version of nodejs too. Looks like these libraries are still not mature. There are problems in them and they are making server crash. When I see the logs I find that crash happened inside the library which crashed the server.

sojharo commented 7 years ago

There were tremendous amount of examples on how to setup APN with PHP but there were just these two libraries for nodejs to do setup with APN.

jekram commented 7 years ago

Apple dose not provide sample code for nodejs to send notification?

sojharo commented 7 years ago

I just looked into it again. Apple doesn't provide libraries or sample code for this. They provide certificates and tokens that we can put in any provider server. Sumaira had also told me that there are providers which link with APNS to send notification. Azure is also such provider which sends notification to APNS. It is upto us to create the provider server.

I looked into some tutorials on how to create APNS provider server. For nodejs, I found these two libraries which convert our server to apns provider server. The other such libraries were about PHP.

https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/

In the following page, there is a section on provider server responsibilities.

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1

In order to write these APNs provider server ourselves, we can read the APNS provider API of apple which would let us know how to create connection with apns server and exchange tokens. They talk about this here.

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html

Libraries are also using this API behind the scenes but they make our work easier as they take care of making sessions and connections. There were many of these libraries created for the PHP, there were two for nodejs. I think if they don't work then we would need to integrate with API and our server would then maintain the connection and token.

sojharo commented 7 years ago

I started reading the documentation of Provider API of APNS and have started writing the code . This is under construction.

sojharo commented 7 years ago

I have implemented the code in this but the notification is getting failed when I try to send it. Working more on it

sojharo commented 7 years ago

I have completed the work on it and it seems that push notifications are going there is no failure message. I will now test it with iOS device.

jekram commented 7 years ago

Ok. Lets test and wrap it up

sojharo commented 7 years ago

I spent a lot of time on this today. It did many problems with nodejs version. I tried upgrading the nodejs version which completely broke our cloudkibo server. I had to revert it back and install all the libraries one by one as due to low RAM of our droplet, it didn't install all libraries at once.

Finally, I created a separate nodejs application with new version of nodejs. It is just small application with apns integration. With this, now I am able to make it work and there are no problems from the server and apns side. However, the push notification is not being sent to device due to the device token. APNS says that it is incorrect device token. Sumaira gave me another device token but it didn't work. I have asked her to let me know when she gets the correct device token as this can be generated from sumaira's computer for each device. This is the error that I am getting:

going to send push
result of voip push
{ sent: [],
  failed:
   [ { device: '621fa6d331cda4076318851e1e40411d97f543c97a97bfd470631d957afb17e2',
       status: '400',
       response: [Object] } ] }
{ reason: 'BadDeviceToken' }

From server perspective, I have been able to connect nodejs with apns and send push notification to apns. However, I had to create separate nodejs application for this. This new application is just APNS provider server which is required to send the push notification.

We can easily connect our current server (which is running on old nodejs version) with this provider server that I have just created with the help of webhook. In this way, we will have two nodejs services running along side. One will be our cloudkibo server and other will be provider server. Both would communicate with each other. I am pushing this provider server as part of our cloudkibo repository so that we would not need to create separate private repository for provider server.

sojharo commented 7 years ago

I worked more on this with sumaira by using the device tokens and keys that she gave me. Now, the push notification is received by the iPhone device sent by my provider server. We would have to integrate this new provider server with our cloudkibo server. I had to do apn integration in separate nodejs application (provider server) because our current cloudkibo code is using very old nodejs version and libraries. Upgrading them gave so many errors i.e. entire libraries are replaced in new version.

jekram commented 7 years ago

Should we get a larger droplet and upgrade to the latest nodejs? We would have to do that anyway some time. Is the error due to size of the droplet?

Sould we have two services? Or now?

jekram commented 7 years ago

Or one?

sojharo commented 7 years ago

The error is due to old nodejs version. The RAM size problem was happening when I was re-installing the libraries for new version of nodejs. There were so many libraries that the process was killed. The killing of process happens in ubuntu when there is low memory available.

For the provider server, we can use a separate droplet. It can be small droplet as the provider server that I have created is very small. Just like a very small micro-service running.

For our current cloudkibo server, we would increase the RAM size once we decide to upgrade nodejs version there.

For now, the provider server is written in new version of nodejs.

sojharo commented 7 years ago

I would manage both cloudkibo server and apns provider server in same repository so no need to create a separate repository for provider server.

sojharo commented 7 years ago

I have completed the work on this now and pushed the code. Both anps provider server and cloudkibo server are part of one (this) repository now. Both are connected with each other with help of webhooks. CloudKibo server can call the webhook on apns provider to send push notification. i tested with postman:

screen shot 2017-05-21 at 3 26 33 pm

We need to now have a droplet where we can run the apns provider server.

jekram commented 7 years ago

The status on the deck it is not done and this marked resolved. Which is correct?

sojharo commented 7 years ago

This was done on Saturday. I might have missed it on Saturday slide. I remember writing done for two tasks. I might have misstyped it as not done. I will correct it in deck.

On May 22, 2017 12:12, "Cloudkibo" notifications@github.com wrote:

The status on the deck it is not done and this marked resolved. Which is correct?

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/Cloudkibo/CloudKibo/issues/511#issuecomment-303017592, or mute the thread https://github.com/notifications/unsubscribe-auth/AFitCZZbDi_PmgygZzvBtd_zJViBQBqbks5r8TVqgaJpZM4NU0s9 .

sojharo commented 7 years ago

I rechecked it is marked done on Saturday work slide.

On May 22, 2017 23:02, "Sojharo Mangi" sojharo@gmail.com wrote:

This was done on Saturday. I might have missed it on Saturday slide. I remember writing done for two tasks. I might have misstyped it as not done. I will correct it in deck.

On May 22, 2017 12:12, "Cloudkibo" notifications@github.com wrote:

The status on the deck it is not done and this marked resolved. Which is correct?

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/Cloudkibo/CloudKibo/issues/511#issuecomment-303017592, or mute the thread https://github.com/notifications/unsubscribe-auth/AFitCZZbDi_PmgygZzvBtd_zJViBQBqbks5r8TVqgaJpZM4NU0s9 .

jekram commented 7 years ago

Thanks


From: Sojharo notifications@github.com Sent: Monday, May 22, 2017 11:02 AM To: Cloudkibo/CloudKibo Cc: Cloudkibo; State change Subject: Re: [Cloudkibo/CloudKibo] Configure Voip push notification (#511)

This was done on Saturday. I might have missed it on Saturday slide. I remember writing done for two tasks. I might have misstyped it as not done. I will correct it in deck.

On May 22, 2017 12:12, "Cloudkibo" notifications@github.com wrote:

The status on the deck it is not done and this marked resolved. Which is correct?

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/Cloudkibo/CloudKibo/issues/511#issuecomment-303017592, or mute the thread https://github.com/notifications/unsubscribe-auth/AFitCZZbDi_PmgygZzvBtd_zJViBQBqbks5r8TVqgaJpZM4NU0s9 .

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/Cloudkibo/CloudKibo/issues/511#issuecomment-303175564, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFFrzAgMpNhruzM7V1xIkv8B3UggDs2Wks5r8c3IgaJpZM4NU0s9.