Giter VIP home page Giter VIP logo

fcm's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fcm's Issues

send_to_topic problems

When I use send_to_topic it returns nil, instead of send_with_notification_key which returns response from fcm.

500 - Internal Server Error

Could you please help me out..
Req:

require 'fcm'
class FcmController < ApplicationController
  def sendPushNote
    fcm = FCM.new("1:776--------e6ec29")
    registration_ids= ["fuOeAA-fPwI:APA91bFiUr7nNKOkXZEQYswuXq7AuQ4Hzjhw_OO-V3TGC3BnHNueZnvt8noE-35--------ByurLtBaNwVg6Zd_cIiv_0IFgSpn77g"] # an array of one or more client registration tokens
    options = {data: {score: "123"}, collapse_key: "updated_score"}
    response = fcm.send(registration_ids, options)
    case response[:status]
      when 200
        render json: {response: response[:body], status_code: response[:status]}, statu: :ok
      else
        render json: {response: response[:body], status_code: response[:status], headers: response[:headers]}, statu: :un_processible_entity
      end # when
  end # sendPush
end # class

Res :

{
response: "<HTML> <HEAD> <TITLE>Internal Server Error</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>Internal Server Error</H1> <H2>Error 500</H2> </BODY> </HTML> ",
status_code: null}

FCM.new questions

Is the FCM class thread safe or should I create a new one for each request? Is there a way to set global options?

MismatchSenderId

I am receiving this error, when I am using legacy server key.

Can someone please tell me. Thanks

Support to click action

When sending the field click_action to a Flutter app, nothing happens (the field is not received in the push notification).
This is the body I'm sending:

{
     notification: {
         title: 'Title',
         body: 'Message',
         tag: 'Update',
         click_action: 'FLUTTER_NOTIFICATION_CLICK'
 }

Doesn't this gem support this or am I doing something wrong?

Message not posting for Firebase

I am getting the response as
{:body=>"{"multicast_id":6960682389725131834,"success":2,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1497533189234401%0aef4f2ef9fd7ecd"},{"message_id":"0:1497533189249924%0aef4f2ef9fd7ecd"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Thu, 15 Jun 2017 13:26:29 GMT"], "expires"=>["Thu, 15 Jun 2017 13:26:29 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alt-svc"=>["quic=":443"; ma=2592000; v="38,37,36,35""], "accept-ranges"=>["none"], "vary"=>["Accept-Encoding"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
But the message is not there on firebase console or not posted to device

Not working for ios 10

response = fcm.send(registration_ids, options) function status : "success":1, "failure":0
but did not getting on the app background.

Exponential Backoff

Is it really necessary to build exponential backoff to our server logic?

How frequent will we get this error? At what amount of rps will we hit this error?

How should we manage sync of exponential backoff time in huge distributed workers(100-1000) environments which pull notification jobs from queue.

title and body not show in notification

hai im sule
i tested in ruby 2.5.3 and rails 5.2 .3

notification title and body no show
here example code

fcm = FCM.new("keyfcm")
 options = {
              "notification": {
                  "body": "book aproving",
                  "title": "your booking for serive has been approve",
                  "click_action": "MainActivity"
              }
    }
    response =fcm.send_to_topic_condition(
    "'USER_ID_23' in topics && 'testing' in topics",
    data: {
       "body": "This is a FCM Topic Message!",
       "title": "Teknopolitan bsd",
       })

Certificate Verify Failed

SSL_connect returned=1 errno=0 state=error: certificate verify failed

registration_ids= [token2] # an array of one or more client registration tokens
options = {data: {message: "123"}, collapse_key: "updated_score"}
response = fcm.send(registration_ids, options)

I just implement the simplest code to send notification to Android. Double check the server key and tokens are correct. Any guide? (Environment is Window 10)

Thanks.

How do I send image with notification

This is how my options look. I am receiving notification without image. How do I send image?

options = {
      data: {
           title: "MagoGenie", 
           message: "Have a Great Day!!",
           image_url: "https://www.magogenie.com/uploads/magogenie_related/web_banner-min.png"
     }
}

Invalid Registration IOS

Hi guys!
I'm facing a problem when i try to send a notification to IOS devices:
"results":[{"error":"InvalidRegistration"}]}",

But it happens only to IOS devices, to Android it's working fine.
Do you know what can i do to fix it?

To have sure about my APNS certificate, i generate a new certificate and added to firebase, but nothing changes..

I'm using the last FCM gem vesion too 1.0.2
Do you have any suggestion?
thanks!

Keyword arguments not supported

All of the examples use the keyword argument format

fcm.add(notification_key: "foo", project_id: "123" ..)

But these are not actually supported by the library, which requires parameters by position.

๐Ÿ“ข๐Ÿšจ[announcement] planned organization name change

๐Ÿšจ This may affect you if you reference this gem's github url in your code/workflow

Just a heads up everyone. We are renaming our organization to decision-labs. This will also be reflected in the name of github organization. We will be doing this next week Friday 25th of September 11:00h GMT

After that everything should continue to work as before. BUT when you have the chance you should change the references to spacialdb to decision-labs

If you have any questions please feel free to post them here.

Thanks

Any known issues with ruby 1.9.3 ?

I would like to use this with ruby 1.9.3 but your gem does not allow it. I'll try to run it anyway but for speeding up debug time, do you know already what part of you code might have issues with that version ?

Thank you.

FCM response

Firebase Response={"multicast_id":6346611008984444477,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1527570229728811%746f20adf9fd7ecd"}]}
But My firebase console didnt receive any message May i know the correction

Thanks in Advance

Data is null

While on receive data is null on notification.

You can still send to invalid topics (regex)

This code tries to stop you from sending to topics that don't match the valid regex provided on FCM.

def send_to_topic(topic, options = {})
  if topic =~ /[a-zA-Z0-9\-_.~%]+/
    send_with_notification_key('/topics/' + topic, options)
  end
end

But the =~ method will still match a string that has invalid characters in it, as long as there are valid characters in it. [see here].(https://ruby-doc.org/core-2.2.0/Regexp.html#method-i-3D~)

So the following can happen:

$ topic = "TopicA$"
$ topic =~ /[a-zA-Z0-9\-_.~%]+/
$ => 0

Can we change this to return false when invalid characters are present in the topic? Something like this maybe?

$ topic = "TopicA$"
$ topic.gsub(/[a-zA-Z0-9\-_.~%]+/, "").length == 0
$ => false

Notifications stop working after some time

We are using this library with JRuby-9.1.15.0 and Sidekiq.

Notifications work for sometime when sidekiq is restarted and stop working after sometime.

We are creating a new FCM instance everytime while sending notifications.

Could this be related to thread safety?

Can not send notification with Ruby 1.8.7

I am using Ruby version 1.8.7.

I use this FCM gem https://github.com/spacialdb/fcm and want to send notification message to Android client app but it does not work.

In Controller:
fcm = FCM.new(FIREBASE_API_KEY, :timeout => 30) options = {:data => {:message => "This is a FCM Topic Message!"}} response = fcm.send_to_topic('global', options)

Class FCM:
`require 'httparty'
require 'cgi'
require 'json'
class FCM
include HTTParty
base_uri 'https://fcm.googleapis.com/fcm'
default_timeout 30
format :json

attr_accessor :timeout, :api_key

def initialize(api_key, client_options = {})
    @api_key = api_key
    @client_options = client_options
end

def send_with_notification_key(notification_key, options = {})
body = { :to => notification_key }.merge(options)

params = {
    :body => body.to_json,
    :headers => {
    'Authorization' => "key=#{@api_key}",
    'Content-Type' => 'application/json'
}

}

response = self.class.post('/send', params.merge(@client_options))
response.parsed_response
end

def send_to_topic(topic, options = {})
if topic =~ /[a-zA-Z0-9-_.~%]+/
send_with_notification_key('/topics/' + topic, options)
end
end
end`

The server key is correct, because I can send notification successfully by PHP code.
The response output as below: {"message_id"=>8885803884270587181}
Could anyone please to point out what wrong with the code. Any help would be greatly appreciated.

Error while trying to use fcm

Am getting this error: LoadError (cannot load such file -- fcm), while trying to use fcm gem. But if i use gcm it has no error. But i upgraded to using firebase.
I have it in my gemfile and i have tried out everything i can. Can any one help me out please?

This is my class that i use to send the notification with

class Device < ActiveRecord::Base

    require 'fcm'

  def self.notify_android(recipient)
        fcm = FCM.new(".....")
        registration_ids= recipient # an array of one or more client registration tokens
        options = {data: {hi: "invoice"}}
        response = fcm.send(registration_ids, options)
  end

end

INVALID_PROJECT_ID

This isn't a bug, but I'm leaving this here as a closed issue because hopefully it helps someone else. I spent many hours determine that what is called PROJECT_ID here is not actually called PROJECT_ID in FCM.

The PROJECT_ID is actually the "SENDER ID"

image

image

Is this ready for use?

I'm currently using your GCM gem on a project and I'm upgrading my Android app to use FCM. Is this gem ready for use? Only asking because the initial push was 12 hours ago.

Thanks!

Handle response failures in lib

Hello

Currently, at work we are processing lots of FCM notifications. We want to be able to properly handle failures of few notifications in batches of 1000 notifications.

In the doc it is mentioned:

Array of objects representing the status of the messages processed. The objects are listed in the same order as the request (i.e., for each registration ID in the request, its result is listed in the same index in the response).

Don't you think it could be a good idea to have the ability to process result and get better error handling?

For example:

response = fcm.send(registration_ids, options, return_errors: true)
pp response.errors
    {
      "kjlhgeqiworguhqeporigqhe98y324t513": "MismatchSenderId"
    }

Cheers
๐ŸŒฎ

base uri

Hi anyone, why base uri declare like:
base_uri 'https://fcm.googleapis.com/fcm'

not:
base_uri 'https://fcm.googleapis.com/fcm/send'

I cant work properly. Please tell me

SocketError (Failed to open TCP connection to fcm.googleapis.com:443)

When I try to implement the example I get this error thrown at the console.

SocketError (Failed to open TCP connection to fcm.googleapis.com:443 (getaddrinfo: Temporary failure in name resolution))

I think it has to do that FCM API URL in the Gem is outdated. The documentation suggests the following API URL for this purpose

https://fcm.googleapis.com/fcm/send

This site has been updated in the background

Regular curl command to test push notifications work for me.

Using the Gem i get a notification that says
"This site has been updated in the background" instead of the notification

Response is 200, success

Status success, but not receiving notification.

Getting this response:

{:body=>"{\"multicast_id\":5212874389930311708,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1490785863976498%81297788962bca0e\"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Wed, 29 Mar 2017 11:11:03 GMT"], "expires"=>["Wed, 29 Mar 2017 11:11:03 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alt-svc"=>["quic=\":443\"; ma=2592000; v=\"37,36,35\""], "accept-ranges"=>["none"], "vary"=>["Accept-Encoding"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}

Response says "success" but the client never receives any push.

I'm able to send push notifications to $RECIPIENT when I'm using console.firebase.com.
If I send with spacialdb/fcm, then no push is sent. Even though the reply from the server looks ok. => (:status_code=>200, :response=>"success")

Any idea what might be wrong?

code

    require 'fcm'
    
    fcm = FCM.new('$TOKEN')
    
    
      # An array of one or more client registration tokens
    registration_ids = ['$RECIPIENT']
    
    options = { data: { score: '123' }, collapse_key: 'updated_score' }
    response = fcm.send(registration_ids, options)
    puts "Sendt: #{response}"

running code

    $ ruby fcm.rb
    
    Sendt: {:body=>"{\"multicast_id\":60356242858746826,\"success\":1,\"failure\":0,
    \"canonical_ids\":0,
        \"results\":[{\"message_id\":\"0:1528896392320437%e06a962bca0e\"}]}", 
    :headers=>{"content-type"=>["application/json; charset=UTF-8"],
        "date"=>["Wed, 13 Jun 2018 13:26:32 GMT"], "expires"=>["Wed, 13 Jun 2018 13:26:32 GMT"], "cache-control"=>["private, max-age=0"],
        "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], 
    "x-xss-protection"=>["1; mode=block"],
        "server"=>["GSE"], "alt-svc"=>["quic=\":443\"; ma=2592000; v=\"43,42,41,39,35\""],
        "accept-ranges"=>["none"], "vary"=>["Accept-Encoding"],
         "connection"=>["close"]}, :status_code=>200, :response=>"success",
        :canonical_ids=>[], :not_registered_ids=>[]}

Regarding dashboard

Hi Kashif,
I have a need to show the notification history send from the specific FCM key with their state : delivered successfully or missed. Thats-why i am looking for a dashboard . Because we have only got the status by server that the particular notification have reached (to particular server ie: fcm and apn,s) but cant have such information that is that particular notification is delivered to device or not?

So please help if you can do any needful.
Quick response is awaited.
Thanks

InvalidRegistration Error with success response and status code 200

Hi. I have just integrated fcm in my rails applications. i have tried to test the notifications but this is giving me invalid registration error although registration key is correct.
Following is the response
{:body=>"{\"multicast_id\":7702172266196992064,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"InvalidRegistration\"}]}", :headers=> {"content-type"=>["application/json; charset=UTF-8"], "date"=>["Thu, 16 Nov 2017 13:54:00 GMT"], "expires"=>["Thu, 16 Nov 2017 13:54:00 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alt-svc"=>["hq=\":443\"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=\":443\"; ma=2592000; v=\"41,39,38,37,35\""], "accept-ranges"=>["none"], "vary"=>["Accept-Encoding"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}

Ios Notification is not receiving at device

Facing an issue with Ios Notification which is not receiving at device. Same setup is working fine with Android.
Found few discussion but didn't help
a. #15
b. #1 (comment)

Here is my
Request:

fcm = FCM.new(ENV["FCM_TOKEN"])
options = {data: {message: message}, priority:'high'}
response = fcm.send(device_tokens, options)

Response:
{:body=>
"{"multicast_id":8122297942819980145,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1505802064679190%9310a6bdf9fd7ecd"}]}",
:headers=>
{"content-type"=>["application/json; charset=UTF-8"],
"date"=>["Tue, 19 Sep 2017 06:21:04 GMT"],
"expires"=>["Tue, 19 Sep 2017 06:21:04 GMT"],
"cache-control"=>["private, max-age=0"],
"x-content-type-options"=>["nosniff"],
"x-frame-options"=>["SAMEORIGIN"],
"x-xss-protection"=>["1; mode=block"],
"server"=>["GSE"],
"alt-svc"=>["quic=":443"; ma=2592000; v="39,38,37,35""],
"accept-ranges"=>["none"],
"vary"=>["Accept-Encoding"],
"connection"=>["close"]},
:status_code=>200,
:response=>"success",
:canonical_ids=>[],
:not_registered_ids=>[]}

Please let me know if i'm doing anything wrong here.
@kmckinley @kashif @fluxsaas
Thank you

Initializer FCM through an initializer

Hi, I was recently using your gem to send messages to Firebase. But I don't like to configure an instance always when I want to send.

So about that, I was thinking about creating an initializer way to configure the gem before sending notifications. Instead of doing this:

require 'fcm'

fcm = FCM.new('API_KEY')

registration_ids = ['11', '12']
options = {
  title: 'Portugal vs Denmark',
  body: '5x1'
}

fcm.send(registration_ids, options)

And start doing this:

# config/initializers/fcm.rb
require 'fcm'

FCM.configure do |config|
  config.api_key = 'MY_API_KEY'
end

And the file I want to send notifications, just:

FCM.send(registration_ids, options)

I was working this morning on a version of that, but I stopped to try to view if this is useful right now. What do you think about that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.