2

I'm integrating amazon connect chatbot on my end and I want to establish a connection between a customer and an agent. In order to so, I have used onMessage event to retrieve agent messages back on my platform but right now, it is not triggered.

I have initially used aws-sdk and @aws-sdk/client-connectparticipant library to send messages where I have used multiple SDKs api in this order

startChatContact -> createParticipantConnection -> sendEvent -> sendMessage

This was done in order to establish a connection between a client and an agent, so that they can send messages to each other as well. With these SDKs, I was successfully able to send messages from customer to agent but in order to retrieve the messages back, I have used getTranscript api inititally, which I was calling in every 2 seconds to check for any updated messages. I have also stored message ids on my end to avoid any duplicate entries.

But now I'm looking for a better solution and for that, I have used amazon-connect-chatjs library and I have used the code below:

import "amazon-connect-streams";
import "amazon-connect-chatjs";

connect.contact(contact => {
  if (contact.getType() !== connect.ContactType.CHAT) {
    // applies only to CHAT contacts
    return;
  }

  contact.onAccepted(() => {
    const cnn = contact.getConnections().find(cnn => cnn.getType() === connect.ConnectionType.AGENT);

    const agentChatSession = connect.ChatSession.create({
      chatDetails: cnn.getMediaInfo(),
      options: {
        region: "us-west-2"
      },
      type: connect.ChatSession.SessionTypes.AGENT,
      websocketManager: connect.core.getWebSocketManager()
    });
  });
});

I have also tried creating a customer chat session, but it is not working as well

const customerChatSession = connect.ChatSession.create({
  chatDetails: {
    contactId: "...",
    participantId: "...",
    participantToken: "..."
  },
  options: { // optional
    region: "us-west-2"
  },
  type: connect.ChatSession.SessionTypes.CUSTOMER
});

Apart from that, I have used onTyping event, but it is not getting triggered as well.

Please let me know if I'm missing anything or doing anything wrong here.

Update1

if i add console.log

const customerChatSession = connect.ChatSession.create({
  chatDetails: {
    contactId: "...",
    participantId: "...",
    participantToken: "..."
  },
  options: { // optional
    region: "us-west-2"
  },
  type: connect.ChatSession.SessionTypes.CUSTOMER
});

console.log("Here");

then even it does not print Here.

There is no error on console.

To create agentChatSession need websocket

connect.core.getWebSocketManager()

this is undefined even.

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189

0 Answers0