Is there any way to fetch last sent message with conversation channel?

Hi,

I am looking to implement 1-1 conversation. I can see that it can be achievable through conversation channel option. I want to give it a feeling of real conversation that we have in other messaging apps.

Let say I have created a conversation channel 1-1 messaging between UserA and UserB. When UserA list for channel than it should show a name of UserB and when UserB list channel than It should show UserA instead of channel display name. So is there any way to achieve that?

2nd thing I want to see last message along with channel listing. Is it possible to get last message with timestamp when listing channels for user Amity API

Regards,
Nasir

@muhammad.nasir.ext Based on your question, here are the solutions:

  1. Workaround for Displaying User Names:
    To handle this, you can implement a solution on the frontend by detecting all users and displaying the names of users who are not the channel’s creator. This way, when UserA lists the channel, it will show the name of UserB, and when UserB lists the channel, it will show the name of UserA instead of the channel display name.

  2. Message Preview Feature:
    Please refer to the documentation for the Message Preview feature at this link: Message Preview Documentation.

Feel free to reach out if you need further assistance.

@amitysupport thank you for the reply. I want to achieve something similar to FB messenger. List down 1-1 chats with their names, along with last message & timestamp. If I go with your suggested solutions then I can display user name from channel users in this call Amity API .

For last message & timestamp I have to call message preview for each channel from FE. Isn’t there any easy way or may be I can get last message along with channel list?

image

@muhammad.nasir.ext Another approach is to use the channel API to fetch the message preview from the ‘messagePreviews’ metadata field. Please note that for the message preview feature, you will need to enable it through this link: Enable Message Preview.

I have requested the feature for the app. I am assuming that channel API Amity API returns last message preview once feature enabled

"messagePreviews": [
    {
      "messageId": "a85dca058f5b585f86a29f14",
      "channelId": "abc665aed9dbb8d036037eed",
      "messageFeedId": "507f191e810c19729de860ea",
      "segment": 0,
      "dataType": "text",
      "data": {
        "text": "test"
      },
      "creatorId": "5349b4ddd2781d08c09890f4",
      "parentId": "abc665afd7dbb8d036037eea",
      "isDeleted": false,
      "createdAt": "2024-06-26T20:22:53.728Z",
      "updatedAt": "2024-06-26T20:22:53.728Z"
    }
  ]
1 Like

@muhammad.nasir.ext yes , that’s correct.

1 Like

@amitysupport Cool, thanks. It helps

1 Like