expo-community / expo-server-sdk-ruby

A Ruby library for sending push notifications with Expo's notification service
MIT License
95 stars 53 forks source link

publish with invalid registration_id fails with "no implicit conversion of String into Integer" #30

Open sungsong88 opened 4 years ago

sungsong88 commented 4 years ago

My class:

### Data Used: {"content"=>"Aaaaaa", "repeat"=>nil, "repeat_unit"=>nil, "remind_at"=>nil, "completed_at"=>nil, "reminded_at"=>nil, :type=>"Reminder", :title=>"Reminder", :body=>"Aaaaaa", :sound=>"default"}

class NotificationService::EXPO < NotificationService

  delegate :app, to: self

  def self.app
    @app ||= Exponent::Push::Client.new
  end

  def notify(notification)
    data = notification.push_notification_data
    app.publish({
      to: registration_id,
      sound: "default",
      title: data[:title],
      body: data[:body],
      badge: user.total_counts["notifications"],
      data: data
    })
  end

end

When registration_id is not valid anymore because the EXPO app that has that registration_id is removed from the device, it fails with:

ETHON: performed EASY effective_url=https://exp.host/--/api/v2/push/send response_code=200 return_code=ok total_time=9.14811
TypeError: no implicit conversion of String into Integer
    from app/models/notification_service/expo.rb:34:in `notify'
    from (irb):218

For now, I'm going to begin rescue that chunk.

Is there a way I can avoid that error? I can't seem to find what causes the problem.

The data I used is {"content"=>"Aaaaaa", "repeat"=>nil, "repeat_unit"=>nil, "remind_at"=>nil, "completed_at"=>nil, "reminded_at"=>nil, :type=>"Reminder", :title=>"Reminder", :body=>"Aaaaaa", :sound=>"default"}

felixletkemann commented 4 years ago

I have got the same issue here!

sungsong88 commented 4 years ago

+1 This issue is driving me crazy...