fcm icon indicating copy to clipboard operation
fcm copied to clipboard

How to send Data Message notification type?

Open chuysb opened this issue 3 years ago • 2 comments

Is there a way to set the notification type as mentioned in the FCM docs?

I'm having problems implementing with React Native (expo managed projec) and found a little piece of advice in the expo docs:

Notification messages are only handled (and displayed) by the Firebase library, meaning they won't necessarily wake the app, and expo-notifications will not be made aware that your app has received any notification. (source)

chuysb avatar Jan 13 '21 12:01 chuysb

@soyjesus did you manage to find a way to send expo-notifications? We're also i need of sending data only notifications.

billowapp avatar May 10 '21 09:05 billowapp

I'm building Finni.app and we are using the following Notification class to send data-only messages.

<?php

namespace App\Notifications;

.........

class AppAlertDashboardReady extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [FcmChannel::class];
    }


    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
                //
            ];
    }

    public function toFcm($notifiable)
    {
        $message = "You can view your financial report now";

        return FcmMessage::create()
          ->setNotification(null)
          ->setData([
            'type' => 'testtext',
            'title' => 'Your Finni Dashboard is Ready',
            'body' => $message
          ])
          ->setAndroid(
              AndroidConfig::create()
                  ->setFcmOptions(
                      AndroidFcmOptions::create()->setAnalyticsLabel(
                          'analytics'
                      )
                  )                  
          );
    }
}

sudoanand avatar Oct 19 '21 12:10 sudoanand

Happy to look over any PR that wants to take a stab at implementing this.

dwightwatson avatar Aug 31 '22 23:08 dwightwatson