How to implement following categories and seeing posts under that category? - getstream-io

In examples on the Get stream Website, I see that they show examples where users are following other users and then they get to see the posts of the user they are following. How can I change this and make it so that users can follow a category(s) instead of a user and then see posts on their feed from the category(s) they are following? Currently, when I make a new post, I add a custom field to capture category id. Not sure what to do next.
I'm using the Get Stream for Laravel.

In Stream a feed can represent anything. So it can be a user, or a timeline (wall) or a category. Simply create a feed for the category and add the activities to it with the TO field. Then your user can follow the category feed.
More information about this can be found on the official docs: https://getstream.io/docs/#targetting

Related

Avoiding duplicates in different feeds with getstream.io

Let's say I want to build a system where each user has access to a notification feed and an aggregated feed, with the following groups:
user as flat feed
hashtag as flat feed
notification as notification feed
timeline as aggregated feed
We also have the following relations:
user:b follows hashtag:a
user:b follows user:a
Now consider the following situation:
If user A posts with hashtag A, I would like user B to get an activity in its notification feed (thanks to relation 1). But I also would also like all followers of user A to see in their timeline that user A did something. Then, user B will get the activity in its notification feed, and in its timeline (because of relation 2): there is a duplicate.
Is there a way to avoid this situation ?
A naive way would be to manually filter the feed and prune the aggregated activities we do not want to see. But this of course seems non optimal.
Thank you very much!
You can use discard rules to avoid activities matching one of rule from getting added to a follower's feed.
This is usually something you use to avoid own activities from showing up in your notification feed.
Here's the link to the docs on Discard Rules:
https://getstream.io/docs/#discard-rules

GetStream: Prevent adding the same activity in flat-feed

I'm using a flat-feed, to be able to follow and unfollow other profiles.
But as i see it, i want to group the verbs as it is possible in the aggregated-feed.
Because i want to aggregate likes to the same activity.
user2 and user3, likes image1.
user1 follow user2 and user3.
Meaning that user1 now have two activities, of users liking the same image and i want it to be displayed as one activity.
Should i handle this myself by sorting it with the foreign key and then collect the activities into one? Or can i somehow blend the flat-feed with aggregated-feed?
This How to build a news feed with aggregate and flat types? is similar, but i need to be able to follow and unfollow.
After finding out that i could combine flat-feed and aggregated-feed i came up with this setup:
In this example beneath, User2 is publishing an artwork, meaning that User2-feed now includes an activity that shows his artworks.
Shortly after User3 likes his newly posted artwork, meaning that User3-feed now include an activity that shows his like of the artwork.
User1 is following User2-feed and User3-feed which create User1-aggregatedfeed that include all activities from the two feeds, that User1 is currently following. It means that User1’s own activity will not being shown in his own User1-aggregatedfeed unless he is following his own feed, which isn’t possible.
The same artwork that is added to User2-feed is also added to Artist1-feed because the artist of the artwork is Artist1. Meaning that the same artwork is now added to two feeds that User1 is following. But activity will only be added to User1-aggregatedfeed once, because we store the “artwork publish” activity with the same foreign key.
Flat-feed combined with aggregated-feed example

Related objects in activity feed

I'm building an activity feed application, where a user can like/comments on each activity feed. I went through GetStream.io documentation and looks like I'll have to send the activity with object ids.
{
id:"ef696c12-69ab-11e4-8080-80003644b625",
actor:"User:1",
object:"Comment:12",
started_at:"2014-11-11T15:06:16+01:00",
target:"Feed:100",
time:"2014-11-11T14:06:30.494",
verb:"add"
}
User:1 and Feed:12 are the objects in my application database? Does it mean that, while retrieving activities, I'll have to hit my database to retrieve the complete feeds?
Say the Feed:12 had few likes and comments earlier from other users. How do I get the complete set of likes/comments on user timeline feed?
What if I want to customize the view, say I want to show all users (image, name, the profile like etc) along with comment with timestamp similar to FB? Do I need to send these attributes as additional parameters for each feed?
Thanks,
Yes, when you fetch a feed from Stream and we give you back these references like user:1 or comment:12, we expect that you'd "enrich" those details from your database.
Typically what our users do is track the name of the model (eg, user) and the user_id (eg, 1). When you get the feed and put it into a hash map, you'll iterate over the activities, pull out all of the actor attributes, and do a single lookup like select * from user where id in (1,3,5,6,9,12) so that you're only hitting your database one time for all user objects or all comment objects or whatever. Then, replace those activities in your hash map so now you'd have actor: <object for User 9> and any other attributes you'd need for your UI presentment.
Then do the same for other references you pass in the activity, and so on.
Things we DON'T recommend are putting in string references for things that could change on your side. For example, if you had actor: "user:ian" instead of my user_id, if I ever change my username later then things probably wouldn't work properly on your side.

Sending specific words to webhook

I'm trying to make an agent that can give me details about movies.
For example, the user says "Tell me about (movie-name)", which sends a post request to my API with the (movie-name) which then returns the response.
However, I don't understand how to grab the movie name from the user's speech without creating a movieName entity with a list of all the movies out there. I just want to grab the next word the user says after "tell me about" and store it as a parameter. How do I go about achieving that?
Yes, you must create a movieName entity, but you do not need to create a list of all movies. Maybe you are experienced with Alexa which requires a list of suggested values, but in api.ai you don't need to do that.
I find that api.ai is not very good at figuring out which words are part of a free-form entity like movieName, but hopefully adding enough user expressions will help it with that.
edit: the entity I was thinking of is '#sys.any' but maybe it would be better to use a list of movie names with the 'automated expansion' feature. I haven't tried that, but it sounds like the way that Alexa's custom slots work, which is actually a lot more flexible (just using the list as a guideline) then people seem to think.

Foursquare get venue details

We are planning to use foursquare api to get venue in a particular city. I want data of all the food outlets in a particular city. I have managed to get the categories list but not sure how to get venues from that particular category in a particular city or area.
Please share some tutorials or document which i can check out.
One way of doing what you want will be using the Venues Platform for browsing according to a category ID.
Look at venue search API reference.
Example of using it:
I know that 4bf58dd8d48988d11f941735 is nightlife (just picked the first one I saw)
So I will call the API (the ll is someplace in New York):
https://api.foursquare.com/v2/venues/search?ll=40.7268,-73.9972&categoryId=4bf58dd8d48988d11f941735&limit=50&intent=browse&radius=1500&your ids/oauth
Or use the explorer to see results right away.
Important, read the search API and the parameters used here to alter behavior to your needs.
Another very important thing, the API parameters are case sensitive!! (so if they want categoryId, categoryid will not work :) )

Resources