我正在尝试使用DDP来启动LiveChat会话,但我面临着一些问题。
https://rocket.chat/docs/developer-guides/realtime-api/livechat-api
我正在按照文档做所有的步骤。在第一个API结果中,您可以看到它是saus numAgents: 2和online: 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包获得的。
发布于 2020-05-10 05:31:57
我通过一个组合解决了这个问题
火箭聊天现场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在livechat的房间中获得空间消息,而通过订阅stream-livechat-room获得房间状态的更改(如切换到另一个代理)。
https://stackoverflow.com/questions/46388089
复制相似问题