Suggest me meteor or node package for chrome notification that can work in desktop as well as mobile chrome

Package name for the meteor that can help to send notification in desktop as well as mobile chrome browser?

1 Like

I simply use the REST API of onesignal. Just get up to speed with that (free) service and you’ll find it works a treat.

@dthwaite Thanks…

Onesignal looks good.

when I allow from my web browser it is not adding the user to the dashboard.

What to do if I block the permission? I want to ask permission again.

Can you showcase some example with meteor.

Could you PLEASE give me some guidance on this. I’m ripping my hair out trying to get it setup.

I’m trying to test on localhost:3000 and keep getting cross domain issues. Even my production site won’t work, same cross domain issues.

var sendNotification = function(data) {
		  
			$.ajax({
				url: "http://onesignal.com/api/v1/notifications",
				headers: {
					'Authorization':'Basic fffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
					'Content-Type':'application/json; charset=utf-8'
				},
				data: data,
				method: "POST",
			}).done(function( data ) {
				if ( console && console.log ) {
					console.log( "Sample of data:", data.slice( 0, 100 ) );
				}
			});
			
		};

		var message = { 
		  app_id: "xxxxxxxxxxxxxxxxxxx",
		  contents: {"en": "English Message"},
		  include_player_ids: ["zzzzzzzzzzzzzzzzzz"]
		};

		sendNotification(message);

Is ‘authorization’ : ‘Basic XXX’ is rest api key?

Yeah you get it from their console.

How did you load the manifest file?

I’ve not got too much time to go through my implementation in step by step detail but essentially I have this:

I include their script in my HTML head section:

<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>

I created an initialisation export as follows:

// Uses https://onesignal.com to provide web notifications
export const oneSignal=function() {
    if (Meteor.settings.public.onesignal) {
        var OneSignal = window.OneSignal || [];
        var settings = {
            'appId': Meteor.settings.public.onesignal.appId, // Get from OneSignal
            'notifyButton': {
                enable: false
            },
            'welcomeNotification': {
                title: 'My System name',
                message: 'You\'re now set up for notifications',
            },
            'safari_web_id': Meteor.settings.public.onesignal.webId, // Get from OneSignal
            'autoRegister': true
        };
        OneSignal.push(['init', settings]);
    }
};

I import and call this function once at start up:

Meteor.startup(function() {
    if (Meteor.isClient) {
        oneSignal();
    }
});

I have a server method that stores a oneSignal user Id into my Meteor.users collection:

// Adds a OneSignal user id to be associated with the logged in user
export const oneSignalUserId=new ValidatedMethod({
    name: 'general.onesignal.userid',
    validate(userId) {
        check(userId, String);
    },
    run(userId) {
        // Note that there's an id for every browser or device used
        Meteor.users.update(this.userId,{$addToSet: {oneSignalUserIds: userId}});
    }
});

Which I would call early on from the client after authentication like so:

// If we have native messaging then make sure their userId is registered with the MMM database
if (window.OneSignal) {
    OneSignal.push(function() {
        OneSignal.getUserId(function(userId) {
            if (userId) oneSignalUserId.call(userId);
        });
    });
}

And here’s where I make a call to notify one or more users from my server:

var options = {
    headers: {
        Authorization: 'Basic ' + Meteor.settings.notifications.onesignal_apikey,
        'Content-Type': 'application/json; charset=utf-8'
    },
    data: {
        'app_id': Meteor.settings.public.onesignal.appId,
        'contents': {en: message}, // My message
        'headings': {en: title}, // notification title
        'android_group': 'message',
        'include_player_ids': ids, // Array of oneSignal user Ids (from my Meteor.users table)
        'url': url // where to go if user clicks on notification
    }
};
HTTP.call('POST', Meteor.settings.notifications.url, options, function(error, result) {
    // Process the return for any ids that were not recognised to remove them from our database
    if (result && result.data && result.data.errors && result.data.errors.invalid_player_ids) {
        result.data.errors.invalid_player_ids.forEach(playerId => {
            Meteor.users.update({oneSignalUserIds: playerId}, {$pull: {oneSignalUserIds: playerId}});
        });
    }
});

In all the above you’ll notice that oneSignal keys, ids and urls etc are set up in my Meteor.Settings. Also note that I clean up my record of oneSignal user ids as per their advice.

Hope this helps. As with all these things, it’s a bit of a procedure and you have to read their documentation carefully.

3 Likes

THANK YOU

I’ll work on this, and if there’s anything missing add to it. You rock. Thank you.

Their docs and customer service leave much to be desired, but hey, it’s complicated stuff. Thank you for your time.

THANK YOU.

It works. I will post a full code on my website about this.

I’ve got a very stripped down and basic simple to use version that will provide other users with the basics in the future. Thank you so much, your code confirmed and helped me get it running. Cheers from www.SkyRooms.io

Thanks @SkyRooms @dthwaite

http configuration worked
https didn’t work

In local machine its worked fine.

In production my landing page is with https with green lock signal.
when I lockedIn green locked signal disappeared. It is because of I am using some http link inside project.

So do i need to configure oneSignal as http type?

My site is full https or not?

OneSignal: Please check your manifest at https://mysite/manifest.json. The gcm_sender_id field is missing or invalid, and a valid value is required. Please see step 2 at https://documentation.onesignal.com/docs/web-push-sdk-setup-https.

Hey, drop OneSignal right now, and move to FoxPush.com

1 simple copy and paste code and you’re running. I had it working quickly. Free tier of 50k users.

But, the correct configuration is using Raix.

See my post here: OneSignal Custom Sounds

You can simply use node toast notifications. You don’t need anything more fancy thsn that.

Dependencies:
$ npm install node-notifier --save

Use this on your node project file:
var notifier = require(‘node-notifier’);

notifier.notify({
title: ‘Testing’,
message: 'your message ',
sound: false
});

Thanks, @inspiraller.

I want browser notification.
One signal fulfilling my requirement but it does not work in https site, only working on HTTP site

is this what you are after: