当客服代理发送消息时,onMessage事件未被触发 amazon-connect-chatjs。

3

我正在集成亚马逊连接聊天机器人,并希望在客户和代理之间建立连接。为此,我使用了onMessage事件来检索代理消息并将其发送到我的平台上,但目前它没有触发。

我最初使用了aws-sdk@aws-sdk/client-connectparticipant库来发送消息,在此过程中,我按照以下顺序使用了多个SDK API:

startChatContact -> createParticipantConnection -> sendEvent -> sendMessage

这是为了建立客户和代理之间的连接,以便他们也可以相互发送消息。使用这些SDK,我成功地能够从客户端向代理发送消息,但为了检索消息,我最初使用了getTranscript API,每2秒钟调用一次以检查是否有更新的消息。我还在我的端点上存储了消息ID,以避免任何重复条目。

但现在我正在寻找更好的解决方案,为此,我使用了amazon-connect-chatjs库,并使用了以下代码:

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()
    });
  });
});

我也尝试创建了一个客户聊天会话,但它并没有像预期的那样工作。

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

除此之外,我使用了onTyping事件,但它也没有触发。

请告诉我是否有遗漏或者做错了什么。

更新1

如果我添加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");

即使它不打印Here,也没有错误信息在控制台上显示。

创建agentChatSession需要使用websocket。

connect.core.getWebSocketManager()

这是undefined甚至。

1个回答

0
你对onAccepted事件的实现看起来是正确的。
const cnn = contact.getConnections().find(cnn => cnn.getType() === connect.ConnectionType.AGENT);

const agentChatSession = connect.ChatSession.create({
    chatDetails: cnn.getMediaInfo(), // REQUIRED
    options: { // REQUIRED
        region: "eu-central-1", // REQUIRED, must match the value provided to `connect.core.initCCP()`
    }, type: connect.ChatSession.SessionTypes.AGENT, // REQUIRED
    websocketManager: connect.core.getWebSocketManager() // REQUIRED
});

您需要使用嵌入式CCP来接受聊天请求。然后,您可以像这样回复消息:
agentChatSession.onMessage(event => {
    // TODO react to message
})

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接