Jump to content

Why not offer push notifications solution


kmk

Recommended Posts

2 hours ago, tonyv said:

Engagement without substance is at best overrated, more accurately useless. I want substance, not clicks. I don't need their noses in an app if they're only gonna click LIKE and not write anything. 

It’s an assumption that increasing engagement decreases substance. I disagree with that assumption for my own community, but I suppose that is very dependent on each community and the type of content you have to begin with. 

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...
On 5/16/2019 at 6:53 AM, Matt said:

Sales figures mean nothing sadly. There's little point investing a lot of energy into a system that does not work on one of the top two phone platforms.

I think we're on Web 5.0 by now.

I would agree, other than push notifications which require an app for iOS.

Take a look at https://firebase.google.com/ its provide a full solution for native/apps/web in one place, and the best Cloud Messaging (FCM) is no-cost and it can be handled by php with a simple http 1.1 API:

<?php

$request = new HttpRequest();
$request->setUrl('https://fcm.googleapis.com/fcm/send');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
    'content-type' => 'application/json',
  'authorization' => 'key=<CONFIG_SERVER_KEY>'
));

$body = [
    "to" => "<user-firebase-token>",
    "time_to_live" => 259200,
    "data" => [ //Some custom stuff
    	"update"=> true, //you can tell the service worker to self update
    	"actions"=> [["action"=> "ok", "title"=> "OK"],["action"=>"link", "title"=>"Acces","link"=>"https://forum.com"]],  //Send somo actions to compose buttons
    	"actionsUrl"=> {"link"=>"https://google.com"}, //and ask to open another url
    ],
     "notification": [
           "body" => "Fancy Notification",
           "title" =>"Small Tittle",
           "image"=> "https://cdn.forum.com/monthly_2020_09/log.png.c10d6f024b155b08ab5f46d029749b42.png", //think on send topic first image
           "click_action"=> "https://invisioncommunity.com/forums/topic/451842-why-not-offer-push-notifications-solution/" //
       ],
      "fcm_options"=> [
       	 "analytics_label"=> "forum-push"
       ]
   ];
$request->setBody(json_encode($body));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

At front-end with service worker (supported by all modern browsers) 

// If you would like to customize notifications that are received in the
// background (Web app is closed or not in browser focus) then you should
// implement this optional method.
messaging.onBackgroundMessage(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
     // Customize notification here
      const {notification} = payload;
      const {data} = payload;
      data.click_action = notification.click_action;	  
	  const {title} = notification;
	  const notificationOptions = {
		  requireInteraction: true, //Some default options
		  data: data,
		  ...notification
		  };
	
	  console.log(notificationOptions);
	  //Show notification
	  return self.registration.showNotification(title,
		notificationOptions);
});

 

More details: https://github.com/firebase/quickstart-js/tree/master/messaging


All you need to do is handle the token from firebase to user, and then in the service queue send notifications to user when needed.

When the user has the focus on the web page you can handle the notifications in the UI.

 

It will work on all top users and technologies.

 

 

 

Edited by Marquinhos
Link to comment
Share on other sites

2 hours ago, Marquinhos said:

Take a look at https://firebase.google.com/ its provide a full solution for native/apps/web in one place, and the best Cloud Messaging (FCM) is no-cost and it can be handled by php with a simple http 1.1 API:


<?php

$request = new HttpRequest();
$request->setUrl('https://fcm.googleapis.com/fcm/send');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
    'content-type' => 'application/json',
  'authorization' => 'key=<CONFIG_SERVER_KEY>'
));

$body = [
    "to" => "<user-firebase-token>",
    "time_to_live" => 259200,
    "data" => [ //Some custom stuff
    	"update"=> true, //you can tell the service worker to self update
    	"actions"=> [["action"=> "ok", "title"=> "OK"],["action"=>"link", "title"=>"Acces","link"=>"https://forum.com"]],  //Send somo actions to compose buttons
    	"actionsUrl"=> {"link"=>"https://google.com"}, //and ask to open another url
    ],
     "notification": [
           "body" => "Fancy Notification",
           "title" =>"Small Tittle",
           "image"=> "https://cdn.forum.com/monthly_2020_09/log.png.c10d6f024b155b08ab5f46d029749b42.png", //think on send topic first image
           "click_action"=> "https://invisioncommunity.com/forums/topic/451842-why-not-offer-push-notifications-solution/" //
       ],
      "fcm_options"=> [
       	 "analytics_label"=> "forum-push"
       ]
   ];
$request->setBody(json_encode($body));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

At front-end with service worker (supported by all modern browsers) 


// If you would like to customize notifications that are received in the
// background (Web app is closed or not in browser focus) then you should
// implement this optional method.
messaging.onBackgroundMessage(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
     // Customize notification here
      const {notification} = payload;
      const {data} = payload;
      data.click_action = notification.click_action;	  
	  const {title} = notification;
	  const notificationOptions = {
		  requireInteraction: true, //Some default options
		  data: data,
		  ...notification
		  };
	
	  console.log(notificationOptions);
	  //Show notification
	  return self.registration.showNotification(title,
		notificationOptions);
});

 

More details: https://github.com/firebase/quickstart-js/tree/master/messaging


All you need to do is handle the token from firebase to user, and then in the service queue send notifications to user when needed.

When the user has the focus on the web page you can handle the notifications in the UI.

 

It will work on all top users and technologies.

 

 

 

The comment Matt made was in reference to push via web, which isn't supported in iOS without using native apps. They now have a native app.

Link to comment
Share on other sites

  • 1 year later...
  • 3 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...