"Friend Request", Direct Message

I am trying to find out how to do two things that seem to have similar mechanics. The first is to send a “friend request” or connection approval. A user selects a group and clicks to join. This sends a direct message to that groups admin. The admin can approve or deny the request. When the admin clicks approve, this triggers a database insert adding requestee to the group.

The other thing I’m looking to do is very similar, allowing users to connect with each other and then message. I have created the database query’s to find one another, but I have not been able to find any documentation on how to allow for direct messaging.

I have reviewed the following documentation (and it has helped get me very far!) but I have not been smart enough to put it all together to do what I want.

I think the answer to my first question is the answer to my second. Can someone provide an example of how to do something like this? I think novice developers like myself trying to create an app from an idea would greatly benefit from it. I will buy your next few rounds!


  1. Create a DB table with “socket_id” and “user_id”, and insert on each connect action in websockets, the socket id of the user into that table

  2. Create a new socket action “friend_request”

  3. Create a “pending friend requests” table and server connect action to be able to query the pending friend requests and put in a server connect action in your layout page

  4. When a user A sends a friend request to user B, use the “direct message” server action to send a socket event with the message type “friend_request”. In socket id insert user B’s socket_id that you can query from the table created in step 1

  5. In your layout page: use the socket component to “receive” the socket events. Select “friend_request” as the message type, then in dynamic events when message is received: you can refresh the “pending friend requests” server action, which will now contain the last friend request

Then with basically the same logic you can build the same requests to group admins