Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message receipts are enabled by default only when setGlobalConfig() is invoked #132

Closed
marcogrcr opened this issue Feb 25, 2023 · 0 comments
Labels
⌛️ In Progress Team is currently working on fix

Comments

@marcogrcr
Copy link
Contributor

Steps to reproduce:

import "amazon-connect-chatjs"; // v1.3.1
import {
  ConnectClient,
  StartChatContactCommand,
} from "@aws-sdk/client-connect"; // v3.254.0

// start a chat contact
const client = new ConnectClient({
  region: "us-east-1",
  credentials: {
    accessKeyId: "...",
    secretAccessKey: "...",
    sessionToken: "...",
  },
});

const { ContactId, ParticipantId, ParticipantToken } = await client.send(
  new StartChatContactCommand({
    InstanceId: "...",
    ContactFlowId: "...",
    ParticipantDetails: { DisplayName: "Customer" },
  })
);

// create chat session
const session = connect.ChatSession.create({
  chatDetails: {
    contactId: ContactId,
    participantId: ParticipantId,
    participantToken: ParticipantToken,
  },
  options: { region: "us-east-1" },
  type: connect.ChatSession.SessionTypes.CUSTOMER,
});

// setup a message handler that will execute once for a message
let once = true;
session.onMessage(async (event) => {
  if (event.data.Type === "MESSAGE" && once) {
    once = false;

    // attempt to send a read receipt
    const { Id: messageId } = event.data;
    console.log("Sending read receipt for message:", messageId);
    try {
      await session.sendEvent({
        contentType: "application/vnd.amazonaws.connect.event.message.read",
        content: JSON.stringify({ messageId }),
      });
      console.log("Sent read receipt for message:", messageId);
    } catch (e) {
      console.error(
        `Failed to send read receipt for message '${messageId}':`,
        e
      );
    }
  }
});

// connect to the chat
await session.connect();

Expected result:

The read receipt can is sent successfully since read/delivered receipts are enabled by default.

Actual result:

The read receipt fails to be sent because read/delivered receipts are disabled:

Sending read receipt for message: (...some message id...)

Failed to send read receipt for message '(...some message id...)': {
    "errorMessage": "Ignoring messageReceipt: false",
    "data": {
        "contentType": "application/vnd.amazonaws.connect.event.message.read",
        "content": "{\"messageId\":\"(...some message id...)\"}"
    }
}

Analysis:

Even thought the documentation in README.md indicates that read/delivery receipts are enabled by default:

//Control switch for enabling/disabling message-receipts (Read/Delivered) for messages
//message receipts use sendEvent API for sending Read/Delivered events https://docs.aws.amazon.com/connect-participant/latest/APIReference/API_SendEvent.html
features: {
messageReceipts: {
shouldSendMessageReceipts: true, // DEFAULT: true, set to false to disable Read/Delivered receipts
throttleTime: 5000 //default throttle time - time to wait before sending Read/Delivered receipt.
}
}
});

This default only applies when the setGlobalConfig() method is invoked at least once:

var setGlobalConfig = config => {
var loggerConfig = config.loggerConfig;
var csmConfig = config.csmConfig;
GlobalConfig.update(config);
/**
* if config.loggerConfig.logger is present - use it in websocketManager
* if config.loggerConfig.customizedLogger is present - use it in websocketManager
* if config.loggerConfig.useDefaultLogger is true - use default window.console + default level INFO
* config.loggerConfig.advancedLogWriter to customize where you want to log advancedLog messages. Default is warn.
* else no logs from websocketManager - DEFAULT
*/
WebSocketManager.setGlobalConfig(config);
LogManager.updateLoggerConfig(loggerConfig);
if (csmConfig) {
csmService.updateCsmConfig(csmConfig);
}
//Message Receipts enabled by default
if (!(config.features?.messageReceipts?.shouldSendMessageReceipts === false)) {
console.warn("enabling message-receipts by default; to disable set config.features.messageReceipts.shouldSendMessageReceipts = false");
setFeatureFlag(FEATURES.MESSAGE_RECEIPTS_ENABLED);
GlobalConfig.updateThrottleTime(config.features?.messageReceipts?.thorttleTime);
}
};

Additionally, the error message when the feature is disabled is not very readable due to the expression used in the error message:

this.logger.warn(`Ignoring messageReceipt: ${GlobalConfig.isFeatureEnabled(FEATURES.MESSAGE_RECEIPTS_ENABLED) && "missing messageId"}`, args);
return Promise.reject({
errorMessage: `Ignoring messageReceipt: ${GlobalConfig.isFeatureEnabled(FEATURES.MESSAGE_RECEIPTS_ENABLED) && "missing messageId"}`,
data: args
});

Proposed fix:

Read/delivered receipts should be enabled regardless of whether setGlobalConfig() is invoked or not.

Additionally, the error message when the feature is disabled should be improved with something like the following:

const cause = GlobalConfig.isFeatureEnabled(FEATURES.MESSAGE_RECEIPTS_ENABLED) ?
  "missing messageId"
  : "message receipts are disabled";
const msg = `Ignoring messageReceipt: ${cause}`;

this.logger.warn(msg, args);

return Promise.reject({
  errorMessage: msg,
  data: args
});
@spencerlepine spencerlepine added the ⌛️ In Progress Team is currently working on fix label Mar 15, 2023
@spencerlepine spencerlepine added 🗒️ In Backlog Reviewed by team, added to backlog and removed ⌛️ In Progress Team is currently working on fix labels May 19, 2023
@spencerlepine spencerlepine added ⌛️ In Progress Team is currently working on fix and removed 🗒️ In Backlog Reviewed by team, added to backlog labels Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌛️ In Progress Team is currently working on fix
Projects
None yet
Development

No branches or pull requests

3 participants