Support Topics Documentation Slack YouTube Blog

One to one chat logic

I want to make one-to-one messaging. Messaging login will be required.
Like whatsapp or instagram. How should I establish its logic?

I want to do:

  • Saving messages in the database,
  • Showing old messages when messaging with the user is started,
  • To start instant messaging.
  • Message notifications need to be automatic

Do I need to create a channel for each user (realtime)? How can i save message and realtime. Can you help me how to do it?

Hi @Paradise_Little,

Perhaps the following approach works for you:

  1. Create the “Conversations” table:
    a. members (1:N Users)
  2. Create the “ConversationMessages” table:
    a. content (string)
    b. conversation (1:1 Conversation)
    c. conversationObjectId (string) <-- This is important!
    d. read (boolean)
  3. Rely on the Real-time database approach instead of RT Messaging. Specifically the Conditional Delivery section.
  4. In order to get the messages history, you need to request the existing ConversationMessages records that match the conversation and the member. Here is a node.js service with that (careful with the paging, consider messages will be added frequently and your offset must take care of that; in this case, I always request the first 10 records and ignore the ones I already have in the UI based on the created date):
  5. In your frontend, subscribe to the Create event for objects with the appropriate conversationObjectId: .
  6. Consider to also ignore the “just sent messages” to avoid messages duplicity. You can either extend that where clause or just dismiss it once the RT handler notifies of it.

I hope it’s a bit usefulñ

1 Like

Thank you for response.
You explained it very well. I don’t need to use the channel part so am I correct?
Will it be enough to create the tables and listen to the ConversationMessages Table?

I’ve not found any disadvantage so far. As long as you persist the message, it would work.

Hi, @Paradise_Little

Did the above option solve your issue?


I will try, thank you.