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

agentChatSession.onEnded() does not trigger on contact transfers #24

Open
marcogrcr opened this issue Jun 10, 2020 · 1 comment
Open
Labels
🗒️ In Backlog Reviewed by team, added to backlog

Comments

@marcogrcr
Copy link
Contributor

marcogrcr commented Jun 10, 2020

I have a need for allowing agents to access their chat transcripts immediately after finishing a chat session. Given that streaming CTRs is not a suitable solution for our use case due to its asynchronous nature, I have developed a solution around this by using a combination of chatSession.getTranscript() and chatSession.onMessage(). A simplification of the solution looks like this:

connect.contact(contact => {
  if (contact.getType() === connect.ContactType.CHAT) {
    contact.onAccepted(async () => {
      const session = await contact
        .getConnections()
        .find((c) => c.getType() === connect.ConnectionType.AGENT)
        .getMediaController();

      const transcript = new TranscriptCustomClass();

      // uses session.getTranscript()
      transcript.populatePreviousMessages(session);

      // dedupes message if present in session.getTranscript(), sorts messages
      session.onMessage(event => transcript.appendMessage(event));

      // waits for transcript.populatePreviousMessages() to complete
      session.onEnded(event => transcript.complete(event));
    });
  }
});

So far, I've used the chatSession.onEnded() event to detect when the chat transcript can be considered "complete" and be made available for consumption. However, I've realized that this method is not called when the agent uses /connect/ccp-v2's "quick connect" feature to perform a transfer.

For the purposes explaining the problem, I'm going to refer to the transferred contact (i.e. initial contact) chat session as initialSession and the current contact (i.e. transferred contact) as currentSession.

Currently, the following behaviors occur:

  1. When the contact is transferred and accepted by another agent, initialSession.onEnded() event is never triggered (I wonder whether this translates to a memory leak).
  2. When the contact is transferred and accepted by the initial agent (e.g. the queue has only one available agent), a new contact is created (as expected), however:
    1. When events/messages are sent to the current contact, both initialSession.onMessage() and currentSession.onMessage() trigger. I believe only currentSession.onMessage() should trigger.
    2. When the current contact session finishes, both initialSession.onEnded() and currentSession.onEnded() trigger. I believe initialSession.onEnded() should trigger when the transfer completes, and only currentSession.onEnded() should trigger.

I've worked around this problem by examining the received messages and stop capturing in initialSession when I receive the following sequence of events I've noticed always occur before a transfer:

// event 1
{
  ContentType: "application/vnd.amazonaws.connect.event.transfer.succeeded"
}

// event 2
{
  ContentType: "application/vnd.amazonaws.connect.event.participant.left",
  ParticipantRole: "AGENT",
}

Note: I've also noticed these events/messages can sometimes come out-of-order to .onMessage(), so I have to sort them first by their AbsoluteTime before performing the detection.


Questions:

  1. Is this by design?
  2. If so, is the workaround guaranteed to always be true (i.e. the sequence of events before a transfer will not change)?
@marcogrcr marcogrcr changed the title chatSession.onEnded() does not trigger on contact transfers agentChatSession.onEnded() does not trigger on contact transfers Jun 10, 2020
@marcogrcr
Copy link
Contributor Author

marcogrcr commented Jun 10, 2020

Update: After examining the code, it looks like that happens because amazon-connect-chatjs triggers .onEnded() only when it encounters an application/vnd.amazonaws.connect.event.chat.ended event:

if (incomingData.ContentType === CONTENT_TYPE.chatEnded) {
this._forwardChatEvent(CHAT_EVENTS.CHAT_ENDED, {
data: null,
chatDetails: this.getChatDetails()
});
this.breakConnection();
}

I believe this is the expected behavior for customerChatSession objects, but not for agentChatSession objects.

@spencerlepine spencerlepine added the ⌛️ Needs Triage Needs team review label Apr 26, 2023
@spencerlepine spencerlepine added 🗒️ In Backlog Reviewed by team, added to backlog and removed ⌛️ Needs Triage Needs team review labels May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗒️ In Backlog Reviewed by team, added to backlog
Projects
None yet
Development

No branches or pull requests

2 participants