amazon-connect / amazon-connect-chatjs

Amazon Connect ChatJS - a browser-based contact center integration API for Chat on the Agent and Customer side.
https://docs.aws.amazon.com/connect/latest/adminguide/what-is-amazon-connect.html
Apache License 2.0
91 stars 53 forks source link

Issue with setGlobalConfig and messageReceipts in Amazon Connect ChatJS #222

Open bradley3322 opened 2 weeks ago

bradley3322 commented 2 weeks ago

Description:

We are developing a customer UI application utilizing Amazon Connect ChatJS. While implementing message receipts, we encountered an issue when using chatSession.setGlobalConfig to lower the throttle time.

Steps to Reproduce:

Implement chatSession.setGlobalConfig with the features field declared as follows:

react typescript

features: {
    messageReceipts: {
        shouldSendMessageReceipts: true,
        throttleTime: 1000
    }
}

Returns the error: Ignoring messageReceipt: false.
If the features field and its internal fields are not declared, the functionality works as expected with the default 5-second throttle time when using the .sendEvent function.

Expected Behavior:

The throttle time should be reduced without encountering the error, and message receipts should be sent as configured.

Observed Behavior:

The throttle time is reduced, but we receive an error message: Ignoring messageReceipt: false when using the .sendEvent function.

Code Example:

React typescript

chatSession.setGlobalConfig({ features: { messageReceipts: { shouldSendMessageReceipts: true, throttleTime: 1000 } } });

Additional Context: Amazon Connect ChatJS version: [2.2.4] We have also tested with the shouldSendMessageReceipts field removed to allow it to be set to the default but this results in the same behaviour

mhiaror commented 2 weeks ago

The error message signifies that shouldSendMessageReceipts flag is not set to true when sendEvent API is called.

It seems sendEvent is called before enabling the flag using setGlobalConfig.

The error is thrown here https://github.com/amazon-connect/amazon-connect-chatjs/blob/ea40a33a658eebedbeecbbda622ddf1b805e096d/src/core/chatController.js#L158

Based on your comments, seems like the future events are working. So, we just need to make sure the config is updated before calling sendEvent.

I tested using https://github.com/amazon-connect/amazon-connect-chat-interface and I was not able to reproduce the error.

Can you pls share minimum sample app to reproduce the issue.

bradley3322 commented 2 weeks ago

Hi,

Thank you for your attention to this matter. While I am unable to provide a minimum sample app due to certain constraints, I can share the implementation details of our current solution.

1. Global Configuration

We are using the connect.ChatSession.setGlobalConfig method to configure our chat session. This includes enabling message receipts and setting a throttle time. Below is the code snippet:

connect.ChatSession.setGlobalConfig({
  features: {
    messageReceipts: {
      shouldSendMessageReceipts: true, // DEFAULT: true, set to false to disable Read/Delivered receipts
      throttleTime: 500
    }
  }
});

2. Creating the Chat Session

After setting the global configuration, we create the chat session using ChatSession.create before starting the connection. Here is the implementation:

const customerChatSession = connect.ChatSession.create({
  chatDetails: cnn.getMediaInfo(),
  options: { 
    region: 'us-east-1',
  },
  type: connect.ChatSession.SessionTypes.AGENT,
  websocketManager: connect.core.getWebSocketManager()
});

const {connectSuccess} = await startConnection(agentChatSession, contact?.contactId);

3. Sending Events

The sendEvent method is called only after the agent sends a message. By this point, the connection and session have been established and the configuration is in place. The code for sending events is as follows:

const response = await chatSession.sendEvent({
  contentType: "application/vnd.amazonaws.connect.event.delivered",
  content: JSON.stringify({messageId: data.Id}) // messageId from the send message response
});

4. Console Log

Please refer to the attached screenshot for the console log showing each event step by step. Screenshot 2024-07-06 141701

If you need further details or have additional questions, please let me know.

Thank you

mhiaror commented 1 week ago

Hi @bradley3322

From logs it seems like the issue is happening in Agent UI using ConnectStreams SDK with ChatJS SDK.

I am confused, because you mentioned you are building customer UI application using ChatJS ?

Also, I see multiple instances of log INFO ["new features added, initialValue: , newValue: MESSAGE_RECEIPTS_ENABLED",true] , seems like there are multiple instances of the SDK in the same browser. Ideally, we should see this message only once .

QQ. Why do you have multiple SDKs initialized ? I see logs from minimized version of Streams SDK, non-minified version of Streams SDK, ChatsessionHandler logs ?

Pls note than GlobalConfig is a singleton in your browser https://github.com/amazon-connect/amazon-connect-chatjs/blob/9b0147fd696a8c40952dcc8e38a1e613da406227/src/globalConfig.js#L4 but from logs it does not seem like a singleton, If you can not share sample application. Best path forward is if you can add a debugger here and ensure its not initialized multiple times and acts as a singleton.

bradley3322 commented 1 week ago

I apologize for any confusion. In my previous message, I referred to it as a ‘customer UI,’ but I meant "representative UI"

I will respond to the questions asked after conducting a review. Thank you for your understanding and patience