You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import"amazon-connect-chatjs";// v1.3.1import{ConnectClient,StartChatContactCommand,}from"@aws-sdk/client-connect";// v3.254.0// start a chat contactconstclient=newConnectClient({region: "us-east-1",credentials: {accessKeyId: "...",secretAccessKey: "...",sessionToken: "...",},});const{ ContactId, ParticipantId, ParticipantToken }=awaitclient.send(newStartChatContactCommand({InstanceId: "...",ContactFlowId: "...",ParticipantDetails: {DisplayName: "Customer"},}));// set global config (enable delivery/read receipts)connect.ChatSession.setGlobalConfig({});// create chat sessionconstsession=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 messageletonce=true;session.onMessage(async(event)=>{if(event.data.Type==="MESSAGE"&&once){once=false;// attempt to send a read receiptconst{Id: messageId}=event.data;console.log("Sending read receipt for message:",messageId);try{awaitsession.sendEvent({contentType: "application/vnd.amazonaws.connect.event.message.read",// notice there's no JSON.stringify(...) wrappingcontent: { 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 chatawaitsession.connect();
Expected result:
The read receipt is sent successfully.
Actual result:
The read receipt fails to be sent:
Sending read receipt for message: (...some message id...)
Failed to send read receipt for message '(...some message id...)': {
"type": "InvalidParameterType",
"message": "Expected params.Content to be a string",
"stack": [
"InvalidParameterType: Expected params.Content to be a string",
...
],
"metadata": null
}
Analysis:
Even though ChatController.sendEvent() and MessageReceiptsUtil.prioritizeAndSendMessageReceipt() support content to be an Object instead of a String:
Thus, when AWSChatClient.prototype.sendEvent() is ultimately invoked, the content value in its Object form is used, instead of its JSON String form (which is what the client expects):
Steps to reproduce:
Expected result:
The read receipt is sent successfully.
Actual result:
The read receipt fails to be sent:
Analysis:
Even though
ChatController.sendEvent()
andMessageReceiptsUtil.prioritizeAndSendMessageReceipt()
supportcontent
to be anObject
instead of aString
:amazon-connect-chatjs/src/core/chatController.js
Line 135 in d85c517
amazon-connect-chatjs/src/core/MessageReceiptsUtil.js
Lines 75 to 76 in d85c517
amazon-connect-chatjs/src/core/MessageReceiptsUtil.js
Line 163 in d85c517
amazon-connect-chatjs/src/core/MessageReceiptsUtil.js
Line 179 in d85c517
When the
connectparticipant:SendEvent
operation is invoked through the client, the originalcontent
value is sent:amazon-connect-chatjs/src/core/MessageReceiptsUtil.js
Line 123 in d85c517
amazon-connect-chatjs/src/core/MessageReceiptsUtil.js
Line 170 in d85c517
amazon-connect-chatjs/src/core/MessageReceiptsUtil.js
Line 177 in d85c517
amazon-connect-chatjs/src/core/MessageReceiptsUtil.js
Line 184 in d85c517
Thus, when
AWSChatClient.prototype.sendEvent()
is ultimately invoked, thecontent
value in itsObject
form is used, instead of its JSONString
form (which is what the client expects):amazon-connect-chatjs/src/client/client.js
Lines 233 to 239 in d85c517
amazon-connect-chatjs/src/client/client.js
Lines 245 to 261 in d85c517
Proposed fix:
One of the following:
ChatController.prototype.sendEvent()
to validate thatcontent
must be a JSONString
.MessageReceiptsUtil
to invokeAWSChatClient.prototype.sendEvent()
withcontent
being a JSONString
value.AWSChatClient.prototype.sendEvent()
so that it invokesJSON.stringify()
ifcontent
is anObject
.The text was updated successfully, but these errors were encountered: