FCM Internal error encountered . Code 500. type.googleapis.com/google.firebase.fcm.v1.FcmError - push-notification

I create push Notif using FCM from backend-website to registered-customer android and ios device.
last time work perfectly . but almost this 7 day we can't send notif at all.
always get error :
"{\n \"error\": {\n \"code\": 500,\n \"message\": \"Internal error encountered.\",\n \"status\": \"INTERNAL\",\n \"details\": [\n {\n \"#type\": \"type.googleapis.com/google.firebase.fcm.v1.FcmError\",\n \"errorCode\": \"INTERNAL\"\n }\n ]\n }\n}\n"
last friday , suddenlly we can sent pushnotif again. I don't change any code (still searching cause of this problem) . Now we came back to zero . get that annoying error again.
Do someone experiencing same issue ? How to fix it ?
Need help fast. panicking here bro
i've tried search what cause this and how to fix them. but not get any clue.
hopefully we can sent push-notification with FCM again.

Related

Fetching messages from empty channel results in 403 in Microsoft Teams

I'm having issues with extracting channel messages from a Microsoft Team. I have a javascript app that crawls through all Teams in a organization and extract the number of messages from all channels in all the teams. It works wonderfully in that it return the correct amount of messages, the problem is that when the app try to fetch a message from a channel where no one have made a message in the channel there is an HTTP error with the ErrorCode 403 (forbidden). Even though the app is successful in that it delivers on what it is supposed to do, I can't have an application that sends 50 angry, red messages every time it makes a http call.
The call I am using is the following
https://graph.microsoft.com/beta/teams/{teamID}/channels/{channelID}/messages
Does anyone know if this is solvable? If not is it possible to check if a channel is empty? And if that is not an option; is there anyone to hide those dirty error messages from the console?
Edit #1
To call to the api I used:
let header = new Headers();
header.append("Authorization", "Bearer " + accessToken);
header.append("Content-Type", "application/json");
fetch("https://graph.microsoft.com/beta/teams/232808c2-d500-47b0-9ead-e238c5e2ab95/channels/19:69a01be632994d123014bbae1aa5db1e#thread.tacv2/messages", {method:"GET", headers: header})
Edit #2
I response object seems to be correct:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#teams('90baabba-1b5e-471c-a163-8a9b4b680de7')/channels('19%3A01c741f599e547f0b9b38296283b7fec%40thread.skype')/messages",
"#odata.count": 0,
"value": []
}
The problem is that in when I look in Google Chrome > Dev tools > Console, the fetch still displays the error:
GET https://graph.microsoft.com/beta/teams/4f460179-4691-42e5-8677-9101dcdb65fe/channels/19:3497f5b8f9f54149919631b32d21e608#thread.tacv2/messages 403 (Forbidden)
And when I console log the error it just displays as:
error: {code: "Forbidden", message: "Forbidden", innerError: {…}}
Only team members are allowed to read messages. Admins can do team management i.e. CRUD operations on teams, channels, tabs etc. They however cannot read messages. This is intentional and we do not have plans to change this in near future

Messages successfully sent, but no notifications visible in Firebase Cloud Messaging

Messages are reported as successfully sent, but no pop-up notifications appear.
With onMessage it is sometimes possible to log the message.
Requesting an FCM token only works on localhost.
When tried on the .com site, the error message depends on whether I use the PC or chromebook - the error messages generated are different.
I have used 2 different devices, but always Chrome browser. The cloud function writes the message and the FCM response to the function log, so it confirms success in sending.
When I deleted onMessage from the recipient webpage there was no sign of any notification.
The webpage is open during these trials. This is web/javascript.
Notification permission is set to allow, in both devices.
I have spent hours on web searches trying to find any hint as to what to try.
firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': '593287500713'
});
const messaging = firebase.messaging();
the relevant code which runs with the webpage
messaging.onMessage(function (payload) {
console.log('Message received. ', payload);
});
I assume that without onMessage, the notifications should appear based on the Firebase SDK, but they don't. WRONG ASSUMPTION
When in the background, nothing appears. (I think notifications are supposed to appear automatically.)
I can request and receive an FCM token when running on local host but the same code throws an error when deployed. "Request is missing required Authentication..."
I have been in contact with support # Google who have assured me that this suggestion, and then another would 100% fix the problem. Nothing made any difference.
I have tried the code snippets in the Firebase docs and also github examples.
If I could find existing code that works, that would be a great start, because I think that finding a solution after about 40 hours of effort is hopeless.
Have I missed something obvious?
UPDATES....
I have found two reasons for not seeing notifications.
1) My PC had a setting which seems to have partially suppressed the display. Unexpected because YouTube notifications do display. (Open notification tray on far right bottom of screen. "focus assist" with a crescent moon symbol. If when clicked it says "on" or "alarms only" I think this restricts what is seen.)
2) My assumption based on the Firebase docs and video was that onMessage() is to prevent notifications when the user is on the webpage and to allow the developer to ignore or handle the notifications within the page. Half right. Apparently the notifications are default ignored UNLESS onMessage() does something with them. The docs give snippets of code for onMessage() but only how to log to the console.
Also, found an amusing problem. Now that my PC has registered the recipient of the messages, it receives them even if that recipient is signed out and has signed in on another device. That sounds like a problem.
The currently working version of the code. This goes in the webpage / app (NOT in the messaging-sw.js file
The introductory video to messaging suggests that it is bad UX to have notifications from a website popping up when someone is on the website. Therefore the code can include onMessage() to either ignore the notification or to handle it within the page.
The docs give a version of onMessage that just logs the notification to the console and has just a comment about doing something else.
Other parts of the docs explain that the system automatically displays notifications.
Therefore I inferred that without onMessage() the notifications would appear automatically.
It seems I was wrong.
It has taken me a massive amount of time to figure this out and to find some code to make the notifications appear. (Even now I am not sure I have grasped what is happening, but the following seems to work)
This goes in the web page / app. (Not in the messaging-sw.js. Putting it there will throw an error "using window methods")
[Do note that I also found my PC was set in a way that seemed to allow YouTube to send notifications, but was preventing the display of FCM notifications. (See explanation in question)
So far I have tested this when the use has the webpage open, the webpage in the background and when the browser is closed. Notifications appear with the default sound and are listed in the notification tray.
This also happens if the recipient is signed out of the webpage and signed in on another device.. the messages continue to go to the same device.
Messages go to devices not to users]
messaging.onMessage(function (payload) {
try{ //try???
console.log('Message received. ', payload);
noteTitle = payload.notification.title;
noteOptions = {
body: payload.notification.body,
icon: "typewriter.jpg", //this is my image in my public folder
};
console.log("title ",noteTitle, " ", payload.notification.body);
//var notification = //examples include this, seems not needed
new Notification(noteTitle, noteOptions);//This can be used to generate a local notification, without an incoming message. noteOptions has to be an object
}
catch(err){
console.log('Caught error: ',err);
}
});
``````````

Firebase messaging failing on flutter after some time

I'm having an issue with FCM on flutter. I have implemented messaging from my server so I'm storing my phone token for each user.
The thing is that when a user logs in for the very first time everything works properly, messages are being sent and user gets notified.
If I do not use the app during the weekend, on Monday I try to send a message by doing some actions on my app but messages are not being sent. I can see my token stored properly in my database.
I'm using firebase_messaging 2.1.0 for flutter.
This is how I get my token
_fireBaseMessaging.getToken().then((token){
_myPhoneToken = token;
});
1-I know token may change when:
App deletes Instance ID
App is restored on a new device
User uninstalls/reinstall the app
User clears app data
But none of this happens.
Any advice on how to handle this scenario? thanks in advance.
UPDATE
Provided you have setup the FCM sdk the right way (but you said that it works the fist time you install the app, so I guess so).
Provided that you are sure that the device_token you are using is the one of the device on which you are expecting to receive the notification (check if it's still the same), you should get on this device your notification quite soon if you use "priority" : "high".
{
"to" : "device_token",
"priority" : "high",
"notification" : {
"sound": "default",
"body" : "Test Notification body",
"title": "Test Notification title"
}
}
This method call
_firebaseMessaging.getToken().then((String token)
return always the new token even if it has been updated. So if you print this out on your device and you send a notification on this token without error, there's no reason why you should not get the token if the device has a valid internet connection active.
It's true that the device token can change during time. If you uninstall and reinstall the app, you can see the token will change and if you try to send a notification on the old one, you will get an error.
If instead the token will change during application lifetime, you can be notify on your server side by listening:
_firebaseMessaging.onTokenRefresh.listen((newToken) {
_fcm_token = newToken;
// send the new fcm to your server
});
So first of all I suggest you to be able to send a notification to a device with Postman. Check if the token you are using is still the one on the device. Then you can try to uninstall and reinstall the application and try to use the old token. You will get an error. Then try to send to the new one, and you should get your notification.
Then wait for some days and try again, check if the token has changed or not and if it's not changed you should be able to send the notification without problems with the same token.
Also be aware that data message on Android if the app is terminated are still not supported.
Some networks/router/mobile can cut the connection between firebase library and firebase server due to inactivity (5min without message). This cut may be detected by the library up to 30min (FCM heatbeat interval).
These are some links discussing this issue:
https://github.com/firebase/quickstart-android/issues/307
Android: Delay in Receiving message in FCM(onMessageReceived)
I contacted firebase support but they told that since the issue is caused by external part they cannot fix it (I suggest decreasing heartbeat interval ...)
I fixed it in android using an interval job which apply these instructions:
context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));
You may write this specific code for Android side and should find something similar for ios side.

How to implement rich notifications in ios 10 with Firebase

I have been looking for a solution for this since quite a while. But I am not able to find anything. I have implemented Push Notifications for iOS using FCM. But I don't know if FCM supports iOS 10 rich notifications. If it does, I didn't find code to implement it. Thanks in advance.
I have the same question why rich notification not working.. and the problem is with FCM mutable-content payload .. it turns in to gcm.notification.mutable-content when payload receives and that's why there is a problem which is not resolved yet.
For more information, you can check this issue from github.
Its resolved now.. you can check that link and also check this answer AL.
Just an update in relation with #ElCaptainv2.0's answer.
The mutable_content has been added for FCM:
Currently for iOS 10+ devices only. On iOS, use this field to represent mutable-content in the APNS payload. When a notification is sent and this is set to true, the content of the notification can be modified before it is displayed, using a Notification Service app extension. This parameter will be ignored for Android and web.
Note: The parameter value should be boolean, not Integer.
It was also mentioned in the GitHub thread just a few hours ago by kroikie.
I was working on this for hours and hours and hours and hours. All my notifications worked fine except the rich notification image would never show. Here is the answer is plain english:
Change this:
"mutable-content": 1 // wrong
To this:
"mutable_content": true // correct
Here is the outgoing payload:
"aps": {
"alert": {
"title": "Hello",
"body": "What do you think of this image?"
},
"mutable_content": true
},
"media-url": "https://firebasestorage.googleapis.com/....."

iOS Push Notifications error after sending wrong token

I've been implementing a small PHP script which will send Push Notifications to Apple's APN servers.
I've got a database with all device tokens that registered for push notifications within my App.
My script will query the database for the tokens and send them to Apple.
Everything works great with a big but... I manually inserted a wrong token into my table and executed the script again.
I've realized that after that wrong token is sent to Apple, all notifications after that won't reach the devices.
Apple seems not to return any OK if everything worked fine but it does send a KO code if something went wrong. I get an error from Apple for that wrong token but I don't get any response afterwards for all the other notifications.
I open only one connection for all the tokens inside the database.
I prepare a socket context with this line:
$streamContext = stream_context_create(array(
  'ssl' => array(
   'local_cert' => $this->signFile
  )
 ));
Then start a communication channel with the APN servers:
$this->hFile = stream_socket_client(self::$serverUrl[$environment], $err, $errstr, 60, STREAM_CLIENT_CONNECT, $streamContext);
Finally I send the message:
fwrite($this->hFile, $command);
I thought of setting a new connection for every notification but I wanted to ask SO opinion first...
By the way, I know that PHP isn't the best choice for this but it came as a requirement from somewhere else and we are forced to set the system this way.
Thank you and have a nice day,
Alex.
I finally found a solution:
As soon as I detect that a token is invalid, I close the connection and open it again to start sending tokens right after the wrong one.

Resources