aws / amazon-chime-sdk-js

A JavaScript client library for integrating multi-party communications powered by the Amazon Chime service.
Apache License 2.0
699 stars 471 forks source link

How to get previous chat messages? #2806

Closed andrii-hrytsyshyn closed 7 months ago

andrii-hrytsyshyn commented 7 months ago

What are you trying to do?

I am trying to get previous chat messages?

What documentation have you looked at so far?

I'm looking for a code example of how to get the entire chat history. This is how I make connections. How can I get the entire chat history? async authenticate() { const client: ChimeSDKMessagingClient = new ChimeSDKMessagingClient({ region: 'eu-central-1', credentials: { accessKeyId: this.credentials.AccessKeyId, secretAccessKey: this.credentials.SecretAccessKey, sessionToken: this.credentials.SessionToken } }); this.client = client; const configuration = new MessagingSessionConfiguration(this.profileService.getUserArn(), this.credentials.SessionToken, undefined, client); const logger = new ConsoleLogger('SDK', LogLevel.ERROR); const messagingSession = new DefaultMessagingSession(configuration, logger); const observer: MessagingSessionObserver = { messagingSessionDidStart: this.handleMessagingSessionStart.bind(this), messagingSessionDidStartConnecting: this.handleMessagingSessionDidStartConnecting.bind(this), messagingSessionDidStop: this.handleMessagingSessionDidStop.bind(this), messagingSessionDidReceiveMessage: this.handleMessagingSessionDidReceiveMessage.bind(this), }; messagingSession.addObserver(observer); messagingSession.start().then(() => { this.messagingSession = messagingSession; }).catch(err => { console.error(err); }); }

devalevenkatesh commented 7 months ago

I think you could look into below API: https://docs.aws.amazon.com/chime-sdk/latest/APIReference/API_messaging-chime_ListChannelMessages.html

We may not be able to retrieve all the message using just this Chime SDK for JavaScript and you will need to combine above API with the messaging APIs in Chime SDK for JavaScript.

We did something similar in the telehealth widget demo: https://github.com/aws-samples/amazon-chime-sdk/blob/5b64a888309375e80d69012e24458885a174683c/apps/telehealth-widget/frontend/src/components/Chat.tsx#L71

Suggest checking it out: https://aws.amazon.com/blogs/business-productivity/embed-healthcare-appointment-scheduling-widget-with-the-amazon-chime-sdk/

For further support please open a support ticket for further help.