How to get live messages from ts-sdk

I’m facing an issue with getting real-time message in typescript sdk. Please provide me with an example of this.

Hi @sarathdixit please find all info & samples here:

Amity Support

@SocialPlus_Support I’m not seeing any examples of live messages that automatically display new messages in a particular channel without requiring a manual refresh

@sarathdixit

If you subscribe to sub channel topic, like the example here; You should get automatic updates to RTE and live Messages will be update the collection of messages for you.

export async function subscribeSubChannel(
  subChannelId: string,
): Promise<Amity.Unsubscriber> {
  const subChannel = (await fetch(
    createQuery(getSubChannel, subChannelId),
  )) as Amity.SubChannel;

  return subscribeTopic(getSubChannelTopic(subChannel));
}

@cijin Thanks for the solution. I’m facing another issue the observeMessage function fires multiple times for a single message and also I’m not getting the creator object like name and avatar in the messages data. How can I achieve those creator data?

@sarathdixit

Hey, there’s two ways around it.

  1. You can use liveMessage instead. It will handle any updates to a message. Also, will always only return you the latest message, when multiple updates are recieved.

  2. You could compare the the updated payload’s updatedAt time with the current objects updatedAt time and use the latest one

As, for creator name and avatar, it kind of does not make sense to make it part of the messagePayload. There is however the creatorId which you could use to retrieve the required info.