Send Notifications using target feeds with getstream.io - javascript

I've been working with getstream.io for a while
and currently I'm facing an issue with the notifications.
To start using notifications I thought it was easier to implement in reactions due to having the targetFeeds property, but I'm facing an access error. I'm trying achieve it doing the next.
UserA commenting in UserB publication
// Client is initialized with UserA info
const comment = await client.reactions.add('comment', activity.id, { data }, { targetFeeds: [`notifications:UserB.ID`] });
My question is how to send a notification to UserB notification feed.
The result I expect is userB receiving a notification like "userA has commented in your publication" or alike.

I believe the default feed for notifications is 'notification' (no s.)
Also I'm not fully aware of what you are tying to accomplish, but just a heads up there is also the TO field for targeting.
https://getstream.io/docs/targeting/?language=js

The issue as first pointed by Sanchaz was that I was using notifications as slug for the notification feed instead of notification, I thought that wasn't the case because I created the notification feed with notifications slug.
StreamIO support stated that if the notification feed doesn't match notification slug, the default permissions doesn't apply, therefore the solution was to rename the slug from notifications to notification.

Related

track message reports using Multicast ID on google firebase in php

Is there a way to track delivery report of a particular message that have been sent via FCM to android device, i found we can add delivery_receipt_requested to track delivery and i have added that my json data as follows,
{"to":"KEY",
"data":{
"data":{
"title":"test message",
"message":"sent",
"image":null}
},
"notification":{
"delivery_receipt_requested":true
}
}
and i receive a response
{"multicast_id":6417448921485349071,"success":1,"failure":0,"canonical_ids":0,"results":[{"error":"false"}]}
In php or javascript i need something like if we pass that multicast_id need to get the current status of the text. I found it was almost nightmare to get the desired result, but its not impossible is there anyway guys?
There is currently no way to manually ask the FCM server about the status of the sent message.
Based from your post, it seems you already did your homework on checking the FCM service. Implementing the delivery receipts is the only way (AFAIK) that you could attain the behavior you mentioned in your post.
Implementing the delivery receipt not only needs the delivery_receipt_requested parameter in your payload, you have to implement an XMPP server protocol as well. Along with the Upstream Messaging part on your client app (for the acknowledgement part).

Can I Send a Web Notification on a Specific Time?

I am trying to implement notifications that do not need the interaction of the backend to be shown. The use of this is to put a remind me button, that would send a notification on certain time of the day (that the user specified). I am pretty new to service workers but I understand that they work asynchronously. That being said, is there any way in which I could do something like the following pseudocode?
function timeLeft(time){
setTimeout(() => showNotification(), time);
}
This would work if I put it on a regular javascript file and the user has the browser still open.
It does not need to be exactly like that, it just needs to solve my problem. Thank you un advance.
First you need to have an ID for each browser. If you use the Push API, then you can use the browser endpoint.
When a user adds a reminder, you must store the tuple (endpoint, send_at, reminder) in your database on your server
Run a cron job on your server (or create a scheduled job with Sidekiq, etc.) in order to send the reminder at the correct time (using the Push API)
Otherwise you can use a service which allows you to create scheduled notifications: see this example on my blog.

Sending message on Intercom on user's behalf

does anyone know how to send a message from intercom(https://www.intercom.com/) on user's behalf? I need to set up an event listener that opens intercom chat window and sends a message when a some button is clicked.
i am working with react version of intercom if it helps.
will be very grateful for any hints.
If you are using the Intercom chat widget, you can pre-populate a custom message in the widget on the user's behalf like so
const myCustomMessage = 'Hi there!'
window.Intercom('showNewMessage', myCustomMessage)
Of course, the user still has to actually send the message. This might not be exactly what you wanted but it's an alternative in case you want to fully automate everything except the decision to send the message (which is the right UX in a lot of situations).
Documentation is here.
for those who are in the same trouble:
https://developers.intercom.com/reference#user-or-contact-initiated-conversation
For sending messages on the user's behalf, you may check this out https://developers.intercom.com/intercom-api-reference/reference/create-a-conversation
You may need the user's user_id or id from the reference above to create a conversation. For those who are using MobileSDK or intercom_flutter, the id is not provided within the package or SDK. I found a workaround by using this Search for contacts API to get the id.

Notification system with Firebase triggers on callback on every reload

So I'm trying to make a notification system similar to Facebook's system. I have a cron job running in the background and when it feels the need to send out a notification to an user it uses the PHP (REST) SDK to send a push to Firebase. On the dashboard I have an 'on' callback that fetches all incoming notifications for the user and shows a notification for each incoming new notification
var push_ref = firebase_ref.on('child_added', function(push) {
new PNotify({
title: 'Notification',
text: push.val().message,
...
});
});
However, when I reload the page all previously sent notifications pops up simultaneously and fills the screen with notification boxes. I don't wanna delete the sent push notifications because later on I'm gonna make a system to fetch them and put them in a dropdown box (similar to the notification dropdown on Facebook).
My question is;
How can I keep all sent notifications but at the same time disable that Firebase returns all notifications when the client goes online again?
UPDATE:
Looked through their documentation again and saw that their retrieving data types are very different. It says under "child_Added" that it "is triggered once for each existing child and then again every time a new child is added to the specified path". This is why it is triggered once I reload the page with all the existing children.
Can you see any other types that might work for me, because I haven't found any.
You could have the client update each message on receipt to acknowledge that it was shown (set acknowledged = true or whatever). Then use the acknowledged field to filter the UI treatment to only highlighting unacknowledged messages.
This assumes the messages are user-specific, or your data structure will require a message/user mapping to hold the acknowledgements.
If the user is reading from a public stream of messages, you could save a user-specific lastReadDate or something that filters out the old messages.

SignalR Content Specific Notifications

I am using SignalR for notifications in my web site but i couldn't find a way to send notifications according to the page/content.
Let me explain in details.
Assume that, there is a page for showing a record from database (for example a blog post).
So there is only one page for showing posts as it should be.
And every post has a like counter which i want to update via signalr notifications, if another user clicks like button. Until here, it is very easy to accomplish.
This page contains a javascript code block like below
var notify = $.connection.notificationHub;
notify.client.updatePostLikeCount = function (likeCount) {
$("#likeCount").text(likeCount);
};
And this function triggered from server-side like below (it is in another class instead of Hub class)
var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.User(user.Id).updatePostLikeCount(likeCount);
But a user might open more than one post; so if a notification is sent from server-side all opened tabs receive this notification and update its counter.
I looked for .Caller method but it is not available in IHubContext interface which GetHubContext() returns and couldn't find another way.
To summarize, i want to send notifications to users who had opened the post which user liked.
EDIT: After sending question i got an idea. Continue sending notification as being and filtering according to the content at client side. It is not very good but i think it will work with charms.

Categories