1

我正在尝试使用 DDP Realtime API 发起 LiveChat 对话,但我遇到了问题。

https://rocket.chat/docs/developer-guides/realtime-api/livechat-api

我正在按照文档执行所有步骤。在第一个 API 结果中,您可以看到它 saunumAgents: 2online: true. 但是,当我尝试向同一部门发送消息时,它会说:“对不起,没有在线代理”。

有没有办法找出问题所在?

的结果livechat:getInitialData

{ enabled: true,
  title: 'xyz.com',
  color: '#C1272D',
  registrationForm: false,
  room: null,
  triggers: [],
  departments:
   [ { _id: 'CxCTgXL4csw3TcW6S',
       enabled: true,
       name: 'Support',
       description: '',
       numAgents: 2,
       showOnRegistration: true,
       _updatedAt: 2017-09-24T06:46:39.657Z } ],
  allowSwitchingDepartments: true,
  online: true,
  offlineColor: '#666666',
  offlineMessage: 'We are not online right now. Please leave us a message:',
  offlineSuccessMessage: '',
  offlineUnavailableMessage: '',
  displayOfflineForm: true,
  videoCall: true,
  offlineTitle: 'Leave a message',
  language: '',
  transcript: false,
  transcriptMessage: 'Would you like a copy of this chat emailed?' }

的结果livechat:registerGuest

{ userId: 'j65Cp5peeLJLYhWQi',
  token: 'J8IpnpB1yN1AYtO0e0EzLhuaRhe0zaZkjHBAamsehSO' }

登录结果

{ id: 'j65Cp5peeLJLYhWQi',
  token: 'J8IpnpB1yN1AYtO0e0EzLhuaRhe0zaZkjHBAamsehSO',
  tokenExpires: 2017-12-23T07:45:01.928Z }

的结果sendMessageLivechat

{ isClientSafe: true,
  error: 'no-agent-online',
  reason: 'Sorry, no online agents',
  message: 'Sorry, no online agents [no-agent-online]',
  errorType: 'Meteor.Error' }

这些是我发送到的参数sendMessageLiveChat

"_id" : "j65Cp5peeLJLYhWQi" 
"rid" : "a_random_string" 
"msg": "Hello" 
"token" : "J8IpnpB1yN1AYtO0e0EzLhuaRhe0zaZkjHBAamsehSO"

有人可以帮助我吗?

这就是我调用 registerGuest 的方式。

ddpClient.call("livechat:registerGuest",[{"token":authToken,"name":"test1","email":"test2@gmail.com","department":department._id},25],function(err, info){

});

我这里传递的令牌是管理员的 authToken

ddpClient 对象是使用 DDP npm 包获取的。

4

1 回答 1

0

我通过组合解决了这个问题

  1. 同时将机器人设置为实时聊天代理和经理(我在某处读过该提示,这可能是胡说八道)
  2. 在管理 -> 全渠道 -> 路由中,我设置了“即使没有代理在线也接受”(因为我的机器人从未在线,如果 DMessaged 时它正在回复)+“将机器人代理分配给新对话”
  3. 我已经为自己设置了一个 livechat-manager + livechat-agent 角色,但留在了不同的部门,这样我就可以接管

火箭聊天实时 api 文档已经过时了,由于随机论坛帖子而使流房间消息正常工作。通常,registerGuest 也可以使用非常少的参数,即随机的、自生成的令牌 + 名称。

这是我的完整设置代码

    async subscribeToLiveRoom(message){
      var _self = this
      // let initial = await this.api
      //   .call("livechat:getInitialData",[token])
      // register
      const token = this.randomString()
      var guestUser = await this.api
        .call(
          'livechat:registerGuest',
          [{
            token: token,
            name: _self.$auth.user.name
          }]
        )
        .catch(console.error)
      console.log('guest', guestUser.visitor.token)
      this.setActiveGuest(guestUser)
      var roomId = this.randomString()
      this.setActiveRoom(roomId)
      let msg = await this.api
        .call(
        'sendMessageLivechat',
        [{
          _id: _self.randomString(),
          rid: roomId,
          msg: message,
          token: guestUser.visitor.token
        }])
        .catch(console.error)

      try {
        let  liveStream = await this.$subscribe("stream-livechat-room",[
          roomId,
            {
              "useCollection": true,
              "args":[
                {
                  "visitorToken": guestUser.visitor.token
                }
              ]
            }
        ])
      this.msgLive = await this.find('stream-livechat-room')

      } catch (e) {
        console.log(e)
      }
      //
      try {
        var  roomStream = await this.$subscribe("stream-room-messages",[
          roomId,
            {
              "useCollection": true,
              "args":[
                {
                  "visitorToken": guestUser.visitor.token
                }
              ]
            }
        ])

        console.log('roomstream')
        var update = this.find('stream-room-messages')

      } catch (e) {
        console.log('an error occured', e)
      }
      console.log( this.msg)
    },
    async sendToLiveRoom(message, rId){
      var _self = this

      // let initial = await this.api
      //   .call("livechat:getInitialData",[token])
      // register

      let msg = await this.api
        .call(
        'sendMessageLivechat',
        [{
          _id: _self.randomString(),
          rid: rId,
          msg: message,
          token: _self.guest.visitor.token
        }])
        .catch(console.error)


    },

顺便说一句,由于没有很好的记录,您将通过订阅获得实时聊天室中的房间消息,stream-room-messages同时通过订阅获得房间状态更改(如切换到另一个代理)stream-livechat-room

于 2020-05-10T05:31:57.583 回答