I have a weird problem, I send notifications via FCM to topics in iOS devices.
Sometimes when the device is connected to slow internet or no internet, and then connects back to the internet, all notification sent prior are not received, and new sent notifications after will be delayed!
For example: A device would be connected back to internet all is fine but I receive the notification delayed 10min and when I receive it the very first moment it's shown, it will say in the dialog: 10min ago!
If I restart the iPhone after that, everything will be fixed again! and I can receive notifications normally.
This issue happened to me in two different devices so I am sure its not from the phone. and other apps notifications would be working without problem as well.
I am thinking maybe its something wrong with my fcm notification configurations that I send from the server, can anyone point if I am missing something here.
Message configuration:
$message = CloudMessage::fromArray([
"condition" => $the_conditions,
"notification" => [
"title" => $title,
"body" => $body,
],
"data" => $data_passed,
//Apple:
"apns" => [
"headers" => [
"apns-priority" => "10",
],
"payload" => [
"aps" => [
"alert" => [
"title" => $title,
"body" => $body,
],
"sound" => $sound,
"thread-id" => "thread_$item_id"
],
],
],
]);
I require high availability notifications that need to be sent immediately.
Note: I am using a php library to send the notification from server: kreait/firebase-php
I'm the maintainer of the SDK you're using 👋
Firstly, the message you composed is perfectly fine, there's nothing wrong with it.
In the context of the SDK I regularly receive issue reports about FCM messages being delivered with big delays or not at all, and unfortunately, there's no way to check if and when a message has been delivered from an Admin SDK. If you send a message to Firebase and Firebase doesn't respond with an error (e.g. when the payload is invalid, when a device token is not registered or when the server is unavailable), we have to assume that the delivery was successful.
To ensure highly reliable messages I currently see two ways how you could achieve that:
Use another messaging service that promises highly reliable delivery like e.g https://pushy.me/ (this is not a recommendation, I'm not affiliated to Pushy and have never used it)
When sending a message from your backend server, include a transaction ID in the data payload, and store it in a database. From the receiving client, issue a request back to your backend server to confirm the message reception. This way you could see if and when a message has been confirmed and can re-send it after a defined amount of time. This has some drawbacks of course - perhaps the client received the message, but the confirmation call failed, or messages could still be sent twice. It's just a naive idea from the top of my head 😅
Related
I use Symfony 5, ApiPlatform and Twilio
My goal is to send a message to a client, then get his answer through a webhook and store it.
So I've open my route through ngrok
ngrok http -host-header=rewrite localhost:{{port}}
And setup my twilio message settings like this :
And implemented a function to send a sms :
$client = new Client($sid, $authtoken);
$client->messages->create(
'myNumber',
array(
'from' => '+twilioNumber',
'body' => $message,
'statusCallback' => "https://a7c6f2ea3843.ngrok.io/twilio/response",
'statusCallbackMethod' => 'POST',
)
);
when I send a message, I receive a callback on this my webhook /twilio/response with the status sent and delivered.
But I never receive the callback w the content of the sms I sent to twilio in reponse of the one I received
Do I miss some configuration? Or am i missing something? Thanks for your help
For anyone who would run into this kind of problem, it was an error of configuration.
On twilio console of your number you can find a link Modify the Messaging Service configuration just above the webhooks
I needed to click on it and configure it to receive the incoming messages and enter the webhook I needed to recover data when one was received.
The webhook I had configured as shown above only send data to confirm that an sms had been send and received from twilio to your client.
LinkedIN has recently released support for webhooks and we are successful in creating a webhook url. We are able to authorise a user administrator of a company to our app and get permissions to write and read from the REST API.
However we are not receiving any webhook updates from the app for that company. And there is no documentation on how to subscribe to a particular company like in other social-media API:s witch we have vast experience from (fb,IG,Twitter).
The documentation on LinkedIn is very limited on the subject. And we are not sure what we can expect from the webhook requests from linkedIn. What is the reason we are not getting Webhooks for that company?
We dont even get webhook calls for the organisation owning the app.
Any help appreciated.
https://learn.microsoft.com/en-us/linkedin/shared/api-guide/webhook-validation?context=linkedin/context
I figure it out I need to add header json to output for validation.
Here is my code in php
if (isset($_REQUEST['challengeCode'])) {
header('Content-Type: application/json');
echo json_encode([
'challengeCode' => $_REQUEST['challengeCode'],
'challengeResponse' => hash_hmac('sha256', $_REQUEST['challengeCode'], 'client secret'),
]);
exit;
}
and for webhook subscription
$api->setApiHeaders([
'X-Restli-Protocol-Version' => '2.0.0',
]);
$developerUrn = urlencode("urn:li:developerApplication:developerid");
$personUrn = urlencode("urn:li:person:personid");
$orgUrn = urlencode(""urn:li:organization:pageid");
$endpoint = "(developerApplication:$developerUrn,user:$personUrn,entity:$orgUrn,eventType:ORGANIZATION_SOCIAL_ACTION_NOTIFICATIONS)";
$api->api("eventSubscriptions/$endpoint", ['webhook' => "WEBHOOK_URL"], 'PUT');
Webhooks are a closed beta feature at this time:
Who can use this: Any developer using a webhooks API (currently available only for social action notifications on company posts to beta partners)
Source: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/recent-changes
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.
I have 10000 users, and i want to push notification SNS to each user, with different message.
So, i cannot use Topic in this case.
The problem is it delay too much. (About 1h30 hour for this to complete)
Any solution?
Thank you so much!
Endpoint is something like internal AWS Identificator for combination: platform+device token or smth else. When we want to send an message we use it as address point instead of real.
About adding Endpoint to SNS. Generally it looks like so:
You should register your platform in AWS SNS and receive e.g. for IOS - iOS app's Application ARN. It can be done via e.g. AWS Web Console
After you should create for each target user its endpoint with method like this:
$endPoint = $snsClient->createPlatformEndpoint([
'PlatformApplicationArn' => $SNS_APP_ARN,
'Token' => 'phone token'
]);
phone token for push notification is device-token. Endpoint generally is array/object which contains EndpointArn. Use it address when send message.
After that you can send an message to specific endpoint.
$snsClient->publish(
array(
'Message' => $pushMessage,
'TargetArn' => $endpointArn
));
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.