Push sharp: Sending same message again and again - push-notification

I am new to Push Sharp.
I am trying to send messages to Android devices using Push Sharp. It works great but the problem is that Push Sharp is sending same message again and again.
My Code is:
AndroidPushBroker = new PushBroker();
var googleKey = CustomConfigurationManager.GetValueFromSection("appSettings", "GoogleServerAccessKey");
AndroidPushBroker.RegisterGcmService(new PushSharp.Android.GcmPushChannelSettings(googleKey));
var jsonMessage = "{\"InformationId\":\"" + notification.Message + "\",\"badge\":7,\"sound\":\"sound.caf\",\"NotificationType\":\"" + notification.Type.ToString() + "\"}";
GcmNotification androidNotifcation = new GcmNotification().ForDeviceRegistrationId(notification.DeviceId)
.WithJson(jsonMessage);
AndroidPushBroker.QueueNotification(androidNotifcation);
Issue: When i send message "Message 1" and then later on send "Message 2", it sends "Message 1" again. Do I need to remove items from Queue ? Or what am I missing. ?
Note: I have single instance of Push Broker in my application.

I'm not very experienced with PushSharp either, but my guess is that you are not emptying the notification queue after sending your message.
Try to add the following after your QueueNotification call
AndroidPushBroker.StopAllServices();

Finally I got the issue.
I was registering my gcm service again and again which was causing duplicate events.
AndroidPushBroker.RegisterGcmService(new PushSharp.Android.GcmPushChannelSettings(googleKey));
This should be called only once.

Related

FCM / APNs =>When specifying apns-collapse-id, old notifications on IOS devices are replaced by new one but new banner is always appearing

(notification banner)
What is apns-collapse-id?
https://stackoverflow.com/questions/40009738/ios-thread-id-doesnt-group-push-notifications#:~:text=What%20is%20apns,it%27s%20for%20coalescing!
I am sending notifications to my Ios users(to ios devices) every x seconds.
In this notifications I am informing users about current state of charging of their electric vehicles.
Some of our users are complaining that notifications are annoying and they are popping up too often.
My goal is to replace old notification with new on without interrupting the user. (just replace the data, no sound, no new banner).
On the server I specified apns-collapse-id in notification header. The new notification is replacing the old one but banner is appearing with every new notification and the user is annoyed.
Is this normal behaviour?
Is it possible to disable "banner displaying"?
(Ideal behaviour would be to show banner just for the first notification).
On the server I am using FCM. The type of notification is Notification messages.
Is it possible that this behaviour is bug in FCM?
message.Apns = new ApnsConfig
{
Aps = new Aps(),
Headers = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>
{
{"apns-collapse-id", notification.ThreadId}
})
};

Angular Push notification error in service worker, Unexpected token P in JSON at position 0

I am trying to use push notification in a pwa, but it is failing to receive the notification.
On the client side I am receiving the following error
Uncaught SyntaxError: Unexpected token P in JSON at position 0
at Driver.onPush (ngsw-worker.js:1967)
at ngsw-worker.js:1871
I add an image that includes the data that reaches the service worker
As you can see in the previous image, the data field is empty, however when I send it I am adding a text
To test the application I am releasing the notification with the following:
https://web-push-codelab.glitch.me/
I already appreciate any contribution.
If your payload is in any json format, like the one above, the error does not appear, but the notification is not shown in your client and no other error message is shown. You have to use a certain json format. One minimal working payload is:
{ "notification": {"title": "message title", "body": "message body"} }
I haven't found the exact and complete spec for this json, but here (search for "payload") you'll find a more complete example.
Make sure you are correctly sending the payload.
Everything is fine except ngsw-worker can't parse the payload.
If you are on windows, try this:
--payload="{\"hello\":\"world\"}"
And not this:
--payload='{"hello":"world"}'
Example (using webpush cli):
web-push send-notification --endpoint="https://fcm.googleapis.com/fcm/send/xxx:xxx" --key="xxxxxxxxxxxxx" --auth="xxxxxxxxxx" --payload="{\"hello\":\"world\"}" --vapid-subject="https://localhost:8000" --vapid-pubkey=xxxxxxxxxx --vapid-pvtkey=xxxxxxxx

How to receive data from an Iframe in Dart?

I know that the only way to communicate with an iframe is using the postMessage method as follow:
iframe.contentWindow.postMessage("my message", window.location.href);
but I would like to know how to receive data from the iframe after any change on it.
In the receiver window, when you receive the message, you get the sender passed with the message and you can send back to this sender.
window.onMessage.listen((e) {
e.source.postMessage({'somedata': 'xxx'}, '*');
});
See also
https://github.com/dart-lang/sdk/issues/26351
https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel

Using caller id as twilio number in asp.net mvc

I've opened up a twilio trial account. I want to use my verified called ID number in my asp.net application instead of buying a new twilio number. But I don't know how to use it. Here are my codes,
public ActionResult SendSms()
{
string ACC_SID = ConfigurationManager.AppSettings["ACC_SID"];
string AUTH_TKN = ConfigurationManager.AppSettings["AUTH_TKN"];
TwilioRestClient client = new TwilioRestClient(ACC_SID, AUTH_TKN);
client.SendMessage("+8801941234567", "+8801671234567", string.Format("This is a test message!"));
return RedirectToAction("SmsView");
}
Nothing happened with it. How can I use my called ID to send sms?
I faced the same scenario while I was working on Twilio first time and at that time I used below steps to make things workable.
1) First of all I would suggest please add Try{} catch{} block in your SendSMS function. this will give you idea like SendMessage worked correctly.
2) In twilio we need to register mobile no before send SMS.
3) if your function works fine(no error occur) then in Twilio there is LOG tab where you can see weather your SMS send correctly or not.
Twilio developer evangelist here.
Jinesh's answer has some useful parts, like using a try/catch block to see errors.
However, the problem is that you are trying to send an SMS from your own number, not from a Twilio number. When sending SMS, you can only send from Twilio numbers. Please see this page for details on why.
You should have got a Twilio number when you signed up. Try using that number as the From number instead.

Unable to get message from queue in IBM websphere MQ

I am connecting remotely to MQ on the server and i installed MQ client v6.0 on my machine.
I am able to put the message into the queue but i am unable to get the message from the same queue the output is "RC2033: MQRC_NO_MSG_AVAILABLE"
Can anyone please help me to find the issue?
Will this be due to properties of the queue?
The following is the code which i am using to pop the message :
Pop Message:
queue = mqQMgr.AccessQueue("queue_name", MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED);
MQMessage queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
MQGetMessageOptions queueGetMessageOptions = new MQGetMessageOptions();
queueGetMessageOptions.Options = MQC.MQGMO_WAIT;
queueGetMessageOptions.MatchOptions = MQC.MQMO_NONE;
queueGetMessageOptions.WaitInterval = 1000;
queue.Get(queueMessage, queueGetMessageOptions);
tbPoptxt.Text = "Message No" + count + ":" + queueMessage.ReadString(queueMessage.MessageLength);
PUSH CODE
int optons = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;//Queue which opens with options output
queue = mqQMgr.AccessQueue("queue_name", optons);
MQMessage queueMessage = new MQMessage();
queueMessage.WriteString(tbPushtxt.Text.ToString());
queueMessage.Format = MQC.MQFMT_STRING;
MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
queuePutMessageOptions.Options = MQC.MQGMO_SYNCPOINT | MQC.MQGMO_FAIL_IF_QUIESCING;
queue.Put(queueMessage, queuePutMessageOptions);
mqQMgr.Commit();
I am using same queue for putting a message and poping a message
Look in the samples directory for the nmqsput and nmqsget c# examples - these do exactly what you are after and are good working examples.
Looking at the code above, I do not think there is a problem getting the message, followed up by your comment that amqsputc failed to find a message as well. I think the problem is on the putting side.
This may sound a silly question, but how do you know the message is there. What is the curdepth after the put? Look at the queue status - are there any uncommitted messages? (One thing I've seen before is putting under a unit of work (syncpoint) and then not committing and then another application trying to get it.

Resources