BadDeviceToken when trying to send the notification (APN) with apnotic gem Rails - ruby-on-rails

I am trying to fire a notification using gem 'apnotic'.
connection = Apnotic::Connection.development(cert_path: "#{Rails.root}/lib/mondofiPush.pem", cert_pass: "")
token = "5e67102820556ee177ffbe0a64ee3a391b89ac61ff2602c97587e838ef93cca"
notification = Apnotic::Notification.new(token)
notification.alert = "Notification from Apnotic!"
response = connection.push(notification)
But in response I get:
{"reason"=>"BadDeviceToken"} we checked that token if fine.
Can anybody please guide me to solve this?

Related

Failed to send FCM send notifications

I am using fcm gem for sending push notifications in my rails application. I can able to retrieve the firebase registration id successfully.
But sending firebase notification results in Type Error ["registration_id"] is not a symbol or a string, the request is not hitting the firebase. My controller code is as follows,
class FirebaseNotificationsController < ApplicationController
require 'fcm'
def send_notification
#fcm = ENV['FCM_SERVER']
notification =
{
"notification":
{
"title": "test title",
"message": "test body"
}
}
response = #fcm.send(['firebase_registration_id'], notification)
end
end
I have even tried JSON parse, but still could not able to solve the error. What could be the solution and also my rails version is 5.2.3 and ruby version is 2.6.3.

Rpush notification fails to deliver

I am new to Rails. I am trying to send push notification using rpush gem.
I am following these steps:
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["#{d.device_token}"]
n.data = { title: "#{self.title}"}
n.save!
The notification gets saved but is not getting delivered, and I get the following error description:
"Unable to deliver notification 10, received error (Failed to deliver to all recipients. Errors: NotRegistered.)"
Not able to understand the issue here. Please help me.
Thanks!
When you find above mentioned message in your log, means, as said #abielita and rpush wiki documentation, the identification_id GCM is using to send notification, is no more valid.
Device with (d.device_token) as registration token, is no more registered on GCM (Firebase) Service.
This message come for a specified reason: adapt your code to this condition.
Maybe is better destroy your "d" record !?
Becomes helpful Rpush.reflect in config/initializers/rpush.rb
Uncomment event notification on.gcm_invalid_registration_id and add your code inside block
e.g.
on.gcm_invalid_registration_id do |app, error, registration_id|
Device.where(registration_id: registration_id).take.destroy
end
and encloses your sending notification code inside a conditional check
unless(d.nil?)
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["#{d.device_token}"]
n.data = { title: "#{self.title}"}
n.save!
end
I hope it help

How to configure Push Notification in Mobile App Buider?

I'm using a Mobile App Builder to make some prototype. One of them I need to send push notification. So, I created a App with App Builder and configure a push settings using Push Notification Services (App GUID and App Route).
After that, I was defined settings a Apple Certificate to send push (https://new-console.ng.bluemix.net/docs/services/mobilepush/t_push_provider_ios.html)
So, when I try to send push notification using Push Notification Services (Bluemix) I receive a msg:
1 - Internal server error. No devices found.
When I see a log in XCode I Found:
registerDeviceToken:completionHandler:]_block_invoke_2 in IMFPushClient.m:116 :: Response of device registration - Response is: httpStatus: 201
responseHeaders: {
Connection = "Keep-Alive";
"Content-Type" = "application/json";
Date = "Thu, 12 May 2016 18:21:22 GMT";
Location = "https://enviarpush.mybluemix.net:443/imfpush/v1/apps/428e6b13-2cc7-4f99-8d7e-9741d6742709/devices/AFAF9994-535D-4F6C-9789-317E680833A8";
"Transfer-Encoding" = Identity;
"X-Backside-Transport" = "OK OK";
"X-Global-Transaction-ID" = 2301423703;
"X-Powered-By" = "Servlet/3.0";
}
responseJson: {
createdMode = API;
createdTime = "2016-05-12T18:21:22Z";
deviceId = "AFAF9994-535D-4F6C-9789-317E680833A8";
href = "https://enviarpush.mybluemix.net:443/imfpush/v1/apps/428e6b13-2cc7-4f99-8d7e-9741d6742709/devices/AFAF9994-535D-4F6C-9789-317E680833A8";
lastUpdatedTime = "2016-05-12T18:21:22Z";
platform = A;
token = 7574a3f1d14a7a01f8d43663cef686b3cb66a634b71ed20608a739c4f55356db;
userId = "";
}
Response text: {"createdTime":"2016-05-12T18:21:22Z","lastUpdatedTime":"2016-05-12T18:21:22Z","createdMode":"API","deviceId":"AFAF9994-535D-4F6C-9789-317E680833A8","userId":"","token":"7574a3f1d14a7a01f8d43663cef686b3cb66a634b71ed20608a739c4f55356db","platform":"A","href":"https://enviarpush.mybluemix.net:443/imfpush/v1/apps/428e6b13-2cc7-4f99-8d7e-9741d6742709/devices/AFAF9994-535D-4F6C-9789-317E680833A8"}
This infos confirm that my device was register, I'm right?
Thanks
Moving forward we will be integrating the device registration, for the period we are experimental we will be creating a number of blog posts that explain some of the key integration you will need to do manually in code. This will include how we recommend integrating with a bluemix backend.
You have to register a device to the IBM Push Notifications Service in order for it to successfully receive push notifications. I would suggest looking at the following documentation:
Enabling iOS applications to receive push notifications
There is also a sample available that demonstrates these capabilities:
HelloPush

iOS Push Notification returning the number 94

I'm integrating push notification for iOS using the gem houston on Ruby on Rails as the web service but whenever I try to send a push notification, it only returns the number "94". Tested it a few hours ago, it returned the number "83" instead. What do you think is causing this and what does those numbers mean?
Code:
token = params[:user]["device_token"]
certificate = File.read("../flux-ws/public/certificates/#{PEM_FILE}")
passphrase = ""
connection = Houston::Connection.new(GATEWAY_URI, certificate, passphrase)
connection.open
notification = Houston::Notification.new(device: token)
notification.alert = {
:body => "HELLO WORLD"
}
notification.badge = 57
pushed_data = connection.write(notification.message)
connection.close
Return value:
{"pushed_data":94,"status":200}
Nevermind, guys. I solved it. The bundle id on the pem file didn't match with the bundle id on my project. That was what caused it and after I matched both, it delivered the push notification successfully.

Using xmpp4r_facebook gem facebook chat message not being sent

I am using xmpp4r_facebook gem to send a message to a facebook friend using my facebook application. Please note I have xamp_login permission. The problem is the message is not being sent. I have followed some other instructions from stackoverflow and implemented as they instructed. But still no message is being sent. Please note, to check, I have changed the facebook application sandbox mode off and make it live. But still not working.
Any help possible?
Or any other library suggestions can you provide?
please let me know!
sender_uid = current_user.uid
receiver_uid = TaggedPerson.last.uid.to_s
sender_chat_id = "-#{sender_uid}#chat.facebook.com"
receiver_chat_id = "-#{receiver_uid}#chat.facebook.com"
message_body = "message body"
message_subject = "message subject"
jabber_message = Jabber::Message.new(receiver_chat_id, message_body)
jabber_message.subject = message_subject
client = Jabber::Client.new(Jabber::JID.new(sender_chat_id))
client.connect
client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client,
ENV.fetch('APP_ID'), current_user.oauth_token,
ENV.fetch('SECRET_KEY')), nil)
# 0
client.send(jabber_message)
# nil
client.close
# nil
Can you use "Jabber::debug = true" and give more info?

Resources