OneSignal Chrome multiple notification - c#

I have some problem with web push notification.
I'm able to send the notification regularly, but, when I send two notification and the first is still visible on the screen, the second overwrite the first one.
The REST API is called by an MVC site written with C#, the object I send is the following:
var obj = new
{
app_id = _appKey,
contents = new { en = message },
headings = new { en = title },
included_segments = new[] { "All" },
url,
chrome_web_icon = imageUrl,
priority = 1,
id = DateTime.Now.ToString("yyyyMMddHHmmss")
};
Did anyone experienced the same issue?
How can I solve that?

Got this answer from OneSignal person.
When using our REST API to programmatically send notifications, you can use the undocumented parameter web_push_topic.
In a set of notifications sharing the same web_push_topic, newly received notifications will replace older received notifications with the same topic. Only notifications sharing the same topic will be replaced; notifications without a topic or with a different topic will not be replaced. You can set different topics for different sets of notifications to control which notifications stay on screen.
The web_push_topic value can be any string value.
On Chrome, a maximum of 3 notifications is displayed at any time, even if the other notifications are not related to your site or from OneSignal. This means you can only show 3 categories of notifications to your user, not counting for other notifications that might be displayed at that time.
On Firefox on Windows, many more notifications can be shown at a time (6+).
On Firefox on Mac, and Safari on Mac, only one notification can be shown at a time, even if the other notifications are not related to your site or from OneSignal. Notifications also disappear quickly within 5 seconds and this time is not customizable.
On Chrome/Firefox on Android, multiple notifications can be shown at a time.
If you do not specify web_push_topic , each notification will be replaced by a newer notification. If you do specify web_push_topic, you can choose which notifications will be replaced and which notifications will stack.
When sending a notification using our API, setting a string value for web_push_topic will set the topic for the notification. Any notifications sharing the same topic will replace each other, but any notifications with a different topic won't be replaced.
So suppose you send 4 notifications:
Notification "Open house at 1234 Street at 3 PM this Saturday" with topic 'open-houses'.
Notification "Open house at 1234 Street changed to 4 PM this Saturday" with topic 'open-houses'.
Notification "20 new houses match your criteria in the Seattle, WA" with topic 'general-updates'.
Notification "Find an agent in your area" with topic 'promotional'.
The sequence of notifications observed will be:
Notification #1 shows.
Notification #2 replaces #1 (even if docked in Mac OS X's notification tray).
Notification #3 is shown separately (and if docked in Mac OS X's notification tray, it will use a separate entry).
Notification #4 is also shown separately.
In the end, when the subscriber checks his unread notifications, he will see three total notifications.
Example Code:
payload = {"app_id": "5eb5a37e-b458-11e3-ac11-000c2940e62c",
"include_player_ids": ["6392d91a-b206-4b7b-a620-cd68e32c3a76"],
"contents": {"en": "English Message"},
"web_push_topic": 'Unique for every notification'}

OneSignal intentionally implements notification replacement that results in this behavior.
The reason for this is to avoid cases where a subscriber could end up with up to 100 notifications to dismiss from a single website, which would be a terrible experience for them.
In the future OneSignal may allow you to avoid this limitation, but in most cases we wouldn't recommend doing this differently.

Related

In the Bot Framework, Is there a common location where I can set the speak property to true in ChannelData?

I am using the Bot Framework to build a speech enabled Bot which handles various events, and triggers a Dialog based on the event. The Bot is connected using WebChat as the interface. As this is mostly a proactive scenario, there is no prior input from the user. As a result, even though the dialog is triggered, there is no output speech, since the speech is activated only if the previous interaction was via Speech. To enable output speech, I right now have to explicitly set the ChannelData of every outgoing activity with 'speak' property as true using activity.ChannelData = new {speak = true};, which WebChat understands , and voices out the message associated with the Activity.
Is there a more efficient way to do this, by setting this property in a common location, so that all outgoing activities by default will be spoken out?
To run any code at all whenever the turn context sends an activity, you can use TurnContext.OnSendActivities:
turnContext.OnSendActivities(async (tc, activities, next) =>
{
activities.ForEach(activity => activity.ChannelData = new { speak = true });
return await next().ConfigureAwait(false);
});
This is often done with middleware, but you could possibly choose to do it at the start of your main bot logic.

UWP scheduled Notification, Toast after app is closed

now, I'm developing some notification app about the online contest.
image:
I managed to get HttpResponse, and parse it to my Class, and add my app as a startup program.
the problem is that I can't find a good way to How notify my app user.
yesterday, I founded Appointment class and I used it. but always, Appointment should be accepted by user's hand. and It is quite slow, and sometime it crashed.
while (mys.Count != 0)
{
Contest contest = mys.Pop();
var appointment = new Appointment();
appointment.Location = "Codeforces";
appointment.Subject = contest.name;
appointment.StartTime = contest.startDate;
appointment.Reminder = TimeSpan.FromHours(1);
var rect = new Rect();
string tmp = await AppointmentManager.ShowAddAppointmentAsync(appointment, rect);
list.Add(contest); //<- observable collection
}
so I changed my mind to use toast notification class. because I think it doesn't need to be accepted by user.
the main question is"
I wonder how can i push notification about the events which will be held in several days.
I mean
my App user just once execute my App.
my App Queried to website, and get some event. (I did {1, 2})
for all appropriate event, I want to push all event to Toast Notification that is valid after my App is closed or my Computer re-boot.
I downloaded Karaoke one App from MS Store, and it pushes Notification periodically 24 hours, even it has no background process(I think), and even I never execute app after rebooting.
below image is Karaoke one App Notification.
How can i Implement it?.
Thanks for read.

Bot receiving duplicate card click events

I am using the following libraries to connect a bot to a Google Pub/Sub endpoint to perform a simple reply to a card click event.
Google.Apis.HangoutsChat.v1 1.34.0.1233
Google.Cloud.PubSub.V1 1.0.0-beta18
When I construct my card, everything looks normal in the UI, including the button that is supposed to raise the event.
The topic and subscription contain the default settings, following the guide here
I found the following information from the Google documentation about retries here
Responding synchronously
A bot can respond to an event synchronously by returning a
JSON-formatted message payload in the HTTP response. The deadline for
a synchronous response is 30 seconds.
A synchronous response from a bot is always posted in the thread that
generated the event to the bot.
After clicking the button, my subscriber receives 3 duplicate events. The events have the correct response with all of the right metadata, but are exact duplicates of each other, including the id of the message itself.
I don't feel there is a necessarily large delay in the response of the bot (it should happen in <1 second for this test), so I am not sure why these messages are being duplicated.
I've also tried setting the thread id for the card when responding (via the Thread property itself, or the ThreadKey property), but I always seem to get a new thread id when I post a message.
var cardMessage = MessageSender.Spaces.Messages.Create(new Message()
{
Space = new Space()
{
Name = inReplyToThisMessage.Space.Name
},
Thread = new Thread()
{
Name = inReplyToThisMessage.Thread.Name
},
Cards = new List<Card>()
{
card
},
}, inReplyToThisMessage.Space.Name);
var sendCardResult = await cardMessage.ExecuteAsync().ConfigureAwait(false);
//Thread id of sendCardResult does not match inReplyToThisMessage.Thread.Name no matter what
Interestingly enough, trying to create a new message in response to the click event causes the bot to display a "Unable to connect to bot. Try again later", but displays 3 new messages. Also, when specifying an arbitrary thread key, this key is never echoed back in the bot's response.
Make sure you are returning the main event method properly. What looks to be happening is that you are making an asynchronous call to the chat, but then the chat is looking for a response from the actual event method itself. Google will traditionally try three times before giving up (even if it doesn't take thirty seconds)
If you are indeed returning the event call correctly after you made your api request, then there is something in your code that is causing the Google Bot to think it is not getting a response, so it tries three times. Since the issue could be multi-faceted I would need to look at how you are accepting and returning the click response.
This bug has finally been fixed by Google.

Is there a way to "flush" the messages into Facebook Messenger?

TL;DR: the bot takes 2-9 seconds to send any message to the user, even if I send the message from the very first line in MessagesController.cs.
I have used the Bot Framework to create a couple of bots for Facebook Messenger and I noticed that one of them is significantly slower than the other.
Both bots have the code below as the very first lines in the MessagesController.cs. This is supposed to send the Typing indicator to the user.
One bot consistently takes 2 seconds to show this typing indicator to the user on Facebook, while the other takes 9 seconds.
Activity typing = activity.CreateReply(null);
typing.ServiceUrl = activity.ServiceUrl;
typing.Type = ActivityTypes.Typing;
ConnectorClient connector = new ConnectorClient(new Uri(typing.ServiceUrl));
await connector.Conversations.SendToConversationAsync(typing);
The second bot indeed does much more work (calling various web APIs), but since these lines are the very first in the controller, I expect the typing indicator to be sent to the user immediately, after which the bot can continue doing its work.
However, it seems that the messages (including the typing indicator) are not sent until the bot completes its work.
Is there a way to "flush" the messages to the user to have a typing indicator sent immediately, or am I encountering some other issue?
Update: I've tried the ConnectorClient.Dispose() method but it doesn't seem to help make it any faster to send messages.
I am not sure what you mean by "flushing" the messages to the user but your bot should show the typing indicator immediately until you type a message and there is some process in the background. To avoid processing information until the user types a message you can use the ActivityTypes like this:
if (activity.Type == ActivityTypes.Message)
{
Activity typing = activity.CreateReply(null);
typing.ServiceUrl = activity.ServiceUrl;
typing.Type = ActivityTypes.Typing;
ConnectorClient connector = new ConnectorClient(new Uri(typing.ServiceUrl));
await connector.Conversations.SendToConversationAsync(typing);
}
else
{
HandleSystemMessage(activity);
}
...
However, it makes sense that the user cannot type anything until the application has already given a answer back to the previous question.

Windows Store App - Local Toast Notification

This may seem like an odd question, but is there a way to send a local toast notification from a Windows 8 Store App to the machine--and NOT show it on the screen? I have a background task that needs to send a sync request to the UI thread. I have been searching for the better part of 8 hours trying to get different methods to work--and it comes down to this will work for me, but I don't want the request text to show up on the screen when I call it.
I should also add that Toast Notifications WILL be used in the app, so I can't simply turn it off globally, I need only the ones I specify to not show up, to be hidden. Is this possible?
Ideally, I would rather do a Raw Notification, but I can't figure out how to do a local Raw Notification (of if its even possible to simulate it without hitting my API.).
EDIT: Root Problem
My background task is doing work behind the scenes every 15 minutes--to basically send a sync request to the main app. The OnPushNotificationReceived, should capture this and perform a full sync of all data I need: Such as GPS coordinates, checking if "ToDoItems" are nearing due dates and need to be escalated in priority, etc. Among other things, such as checking if there are any documents on the local file system that have been marked as complete and need to be uploaded to Azure file storage, etc.
The answer might be in the OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
args.Cancel = true
From MSDN: https://msdn.microsoft.com/en-us/library/br241295
Cancel:
Read/write Gets or sets whether Windows should perform its default handling of the notification.
You receive the notification and process it in your OnPushNotificationReceived listener, set the cancel to true and voila!
Basically you already processed the notification, so you cancel the default behaviour that is showing the notification.
EDIT CONTENT:
The Raw Notification basically is an empty envelope where you can put any content in any form you want, could be an object, an image, a dictionary... Basically you decide the content to send and obviously the app must know the datamodel to be able to process it.
To create Notifications easily I recommend you this Nuget Package: https://github.com/WindowsNotifications/NotificationsExtensions/tree/master/Windows%208.1%20RT
Example on how to create a toast notifcation:
var toastNoti = ToastContentFactory.CreateToastText02();
toastNoti.TextHeading.Text = "TEXT IN BOLD";
toastNoti.TextBodyWrap.Text = "TEXT IN NORMAL CASE ";
toastNoti.Launch = "NOTIFICATION ARGUMENTS";
var doc = new XmlDocument();
doc.LoadXml(toastNoti.ToString());
var endNotification = new ToastNotification(doc);
endNotification.Tag = "1";
ToastNotificationManager.CreateToastNotifier().Show(endNotification);
Hope this helps. Tell us any result please.

Categories

Resources