derek82511 / cordova-azure-notification-hubs

Register and receive push notifications via Azure Notification Hub.
MIT License
10 stars 30 forks source link

How do I subscribe to the Tag Expression in Azure Notification Hub #11

Open niren777 opened 5 years ago

niren777 commented 5 years ago

I'm able to configure the Azure Notification Hub with Cordova app. The code, I used is given below

    pushNotification = PushNotification.init({
        notificationHubPath: '<notificationHubPath>',
        connectionString: '<connectionString>',
        android: {}
   });
  pushNotification.on('registration', function (data) {
        console.log('data.registrationId', data.registrationId);
        console.log(data.azureRegId);
   });
  pushNotification.on('error', function (data) {
        console.log(JSON.stringify(data));
  });
  pushNotification.on('notification', function (data) {
        console.log(JSON.stringify(data));
   });

with the above code, the mobile receives the notification when I send notification from Azure portal using Test Send. When I add Tag Expression in Test Send, the mobile is not receiving the notification.

I'm not sure how to subscribe to a particular tag

The function pushNotification.subscribe() gives error subscribe is not a function

Is there a way to subscribe to the tag?

derek82511 commented 5 years ago

Hi niren777, You can use your backend server to register a device to some tag by using the azure push notification hubs apis. Here is the implementation of java: https://github.com/Azure/azure-notificationhubs-java-backend

niren777 commented 5 years ago

@derek82511 In the backend, we use python. We have integrated the backend with Azure Notification Hub using the tutorial https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-python-push-notification-tutorial. In the backend we use the tag to send a notification but the mobile is not receiving since the mobile is not registered to the particular tag.

The java based notification that you mentioned is different from the python backend. In our setup, the frontend is independent of backend. The backend only to serve the Restful APIs. So I'm not sure about registering the frontend device from the backend.

derek82511 commented 5 years ago

@niren777 You can implement your python code to call the azure push notification hubs rest apis.

The link of register rest api: https://docs.microsoft.com/en-us/rest/api/notificationhubs/create-registration

The azure push notification hubs backend implementation of java almost use this rest api to register device or send message to azure.

niren777 commented 5 years ago

@derek82511 Should I still use this plugin(cordova-azure-notification-hubs) in my app If I register the device from the backend app?

exhaler commented 3 years ago

@derek82511 Should I still use this plugin(cordova-azure-notification-hubs) in my app If I register the device from the backend app?

@niren777 where you able to register the device in the backend?