Is there a way to programmatically create a follow relationship between two users?

I’m trying to make follow requests work more similar to the Facebook friends architecture, where after a request is accepted, the relationship is created bidirectionally, but I havent found a way to create follow relationships with the API. Is there some other way to achieve what I’m trying to do?

Hello @tahmeednabi our product already supports follow/unfollow feature, here’s our docs: Follow / Unfollow - Amity Docs , is this what you are looking for?

Yes I’m using that feature, but trying to create follow requests between users server side, so that I can make it work like the facebook friends relationships. To be more clear:

Default amity follow method:
User A requests to follow User B, User B can accept or reject. User B has to then follow User B back, which User A needs to also accept or reject.

Method I’m looking for
User A requests to follow User B. User B can accept or reject. If accepted, User B automatically also follows User A and is automatically accepted.

To achieve this I wanted to see if there was some way to create that follow relationship given two user IDs by calling some sort of API.

In this case, we would recommend you to follow this flow:

  • After user A accepts a follow request from user B, then at the same time, call the follow function for user A to follow user B back (this will result as an auto-follow)
  • You can filter/observe this event on frontend

Thanks for getting back to me so quick.

I think I’ve implemented the system as you’ve described, however I’m not observing the “auto-follow” behaviour you’re describing. I’m using the typescript SDK to run a query to accept the request from a user and follow them back at the same time, as shown in code below:

const query1 = createQuery(acceptFollower, userId);
await runQuery(query1);
const query2 = createQuery(follow, userId);
return runQuery(query2);

However, as I said the auto-follow isnt working, and instead the user needs to accept the follow request themselves. Let me know If I’ve done something wrong. Thanks!

Hi @tahmeednabi after discussing with the team, we would recommend you to use Without Request process instead, please see the docs here https://docs.amity.co/social/typescript-react-native/follow-unfollow#user-connection-method-concept

Please let us know if this can achieve what you want to do?

In that case, if User A follows User B, wouldn’t posts by User B be visible to User A (in their social feed), automatically, without their approval?

Yes, if user A follow user B, user B’s posts will automatically be visible to user A