How to use Token Device

Created on 29 August 2023, over 1 year ago
Updated 4 April 2024, 10 months ago

Problem/Motivation

Hi, I need help with device tokens, I don't know how to generate them or how to save them in drupal, nor how to use them. The connection of the module with firebase works perfectly, but when trying to detect a device and send it a notification, I don't know how to see its token. Could you help me? Thank you

💬 Support request
Status

Closed: cannot reproduce

Version

3.0

Component

Documentation

Created by

🇦🇷Argentina OPtii

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @OPtii
  • 🇧🇷Brazil leopaccanaro

    Hello.

    I suggest you reading
    https://firebase.google.com/docs/ios/setup
    https://firebase.google.com/docs/android/setup

    After you've added the SDK into your mobile app, you need to receive the token. I would recommend having an endpoint in Drupal that will receive Firebase token and store it in your database.
    Then you can use it to send notifications.

    At the homepage of this module we added a guideline. Have you read it?

    Module Setup
    These are the steps to get the notifications working:
    
    Create a Firebase account
    Add Firebase to your iOS project OR Android project
    Enable this module
    Add your firebase Server Key into /admin/config/system/firebase
    Each device has a token. Store that token on Drupal
    Call Firebase service passing the device's token and message
    // Token is generated by app. You'll have to send the token to Drupal.
    $fakeToken = 'e3vUiwcvkpY:APA91bEDZzKTIkaL0e-UTwiV6EGi1m5J5PrDMxejm6-d85vdwAgd';
    $messageService = \Drupal::service('firebase.message');
    $messageService->setRecipients($fakeToken);
    $messageService->setNotification([
      'title' => 'Title goes here',
      'body' => 'Body goes here',
      'badge' => 1,
      'icon' => 'optional-icon',
      'sound' => 'optional-sound',
      'click_action' => 'optional-action',
    ]);
    $messageService->setData([
      'score' => '3x1',
      'date' => '2017-10-10',
      'optional' => 'Data is used to send silent pushes. Otherwise, optional.',
    ]);
    $messageService->setOptions(['priority' => 'normal']);
    $messageService->send();
  • 🇦🇷Argentina OPtii

    Hi @leopaccanaro. Yes, I have read that information about the module. I will tell you about my situation, I am currently using the Drupal "PWA" (Progressive Web App) module, as a result of this module what I need is to send notifications to those devices that have the web installed as an APP.
    I know there is a module "Advanced Progressive Web App" that sends notifications but only with the "minishlink/web-push" library version 4, which I can't install because it requires PHP 7 or lower and I'm currently working with PHP 8
    So I was trying to do it with this firebase module.

  • 🇧🇷Brazil leopaccanaro

    Hello octaviosch.
    FCM with websites is not my specialty. Additionally, the SDK is mainly used in Javascript/Typescript websites not PHP.

    That been said, have you read https://firebase.google.com/docs/cloud-messaging/js/client and https://dev.to/thisdotmedia/pwa-push-notifications-with-firebase-cloud-m...?

    This second link in particular covers an example, with Javascript. You'll have to do lots of adaptations, but I guess it's possible to achieve what you want.

    If you are unable to do it, please have a Github repository available (or similar) so we can look into the codes and help you, when we have the time.
    Your question is not really about this module and Drupal community.

  • Status changed to Closed: cannot reproduce 10 months ago
  • 🇯🇵Japan ptmkenny

    Closing as a repo to reproduce the issue was requested and six months have passed with no response.

Production build 0.71.5 2024