[LiveChat] server internal error on method `sendMessageLivechat`
Rocket.Chat Version: 0.56.0 Running Instances: 1 DB Replicaset OpLog: Disabled Node Version: 4.8.1 - x64
server internal error on method sendMessageLivechat while not logged in yet.
requests:
sending: {
"msg": "method",
"method": "livechat:registerGuest",
"params": [
{
"token": "dedecdabcabacbeba",
"name": "test1",
"email": "[email protected]"
}
],
"id": "1"
}
response: {
"msg": "result",
"id": "1",
"result": {
"userId": "6FrmEm7XP8LdAimoi",
"token": "0sy_Yt555_SYmorF2KGuJlLrqYxgq0bq8cY-a7Y0v9s"
}
}
sending: {
"msg": "method",
"method": "sendMessageLivechat",
"params": [
{
"_id": "XqEEHhQHvhFmK3Zoz",
"rid": "ziUm63f(c3ZBMN@ZWn",
"msg": "test",
"token": "0sy_Yt555_SYmorF2KGuJlLrqYxgq0bq8cY-a7Y0v9s"
}
],
"id": "2"
}
response: {
"msg": "result",
"id": "2",
"error": {
"error": 500,
"reason": "Internal server error",
"message": "Internal server error [500]",
"errorType": "Meteor.Error"
}
}
server logs:
Exception while invoking method 'sendMessageLivechat' TypeError: Cannot read property 'department' of undefined
at Object.RocketChat.Livechat.getRoom (/app/bundle/programs/server/packages/rocketchat_livechat.js:3216:14)
at Object.RocketChat.Livechat.sendMessage (/app/bundle/programs/server/packages/rocketchat_livechat.js:3250:23)
at [object Object].Meteor.methods.sendMessageLivechat (/app/bundle/programs/server/packages/rocketchat_livechat.js:1118:30)
at [object Object].methodsMap.(anonymous function) (/app/bundle/programs/server/packages/rocketchat_lib.js:1021:26)
at [object Object].methodMap.(anonymous function) (packages/rocketchat_monitoring.js:2731:30)
at maybeAuditArgumentChecks (/app/bundle/programs/server/packages/ddp-server.js:1823:12)
at /app/bundle/programs/server/packages/ddp-server.js:905:20
at [object Object]._.extend.withValue (packages/meteor.js:1122:17)
at /app/bundle/programs/server/packages/ddp-server.js:904:41
at [object Object]._.extend.withValue (packages/meteor.js:1122:17)
at /app/bundle/programs/server/packages/ddp-server.js:903:46
at [object Object]._.extend.protocol_handlers.method (/app/bundle/programs/server/packages/ddp-server.js:876:21)
at /app/bundle/programs/server/packages/ddp-server.js:755:85
2017-05-29T05:49:19.086614985Z
where do you get the rid from? usually you have to define it in registerguest
@legendecas can you please test using the develop branch?
I've done a few fixes while converting livechat to JS
@sampaiodiego I'm using docker image tagged with 0.57.0-develop now, the problem is still there. Is docker image tagged with 0.57.0-develop synced with repo's develop branch?
from my debugging sessions there neeeds to be a call "livechat:getInitialData" before "livechat:registerGuest", furthermore you got to supply a token in registerGuest
@whuber-work Yes, that's right. But what's the issue's idea is that if the method sendMessageLivechat called before login properly the server would response with an internal server error rather than a client error.
@legendecas yes, 0.57-develop docker tag is synced with develop branch.
ok now I got it.. we need to enforce guest to be logged in to call sendLivechatMessage. is that fine to you?
also thx @whuber-work for helping in the investigation
@sampaiodiego well... I'm suggesting that the server should not response with server error while it's caused by client's fault and should be detailed with error messages.
@renatobecker can you investigate if this is still an issue? I think since we moved livechat visitor away from regular users, this shouldn't be an issue anymore.
@sampaiodiego, Okay I'll take a look on this.
@sampaiodiego,
I have tested the methods on server in the same way as described by @legendecas.
When I called the livechat:registerGuest method, I got the response like below:
{
"msg": "result",
"id": "3",
"result": {
"userId": "deteeL7h8swBnHYPN",
"visitor": {
"_id": "deteeL7h8swBnHYPN",
"username": "guest-3",
"token": "dedecdabcabacbeba",
"visitorEmails": [
{
"address": "[email protected]"
}
],
"name": "test1"
}
}
}
Then, I called the sendMessageLivechat method passing the same params and I got the response like this:
{
"msg": "result",
"id": "4",
"result": {
"_id": "XqEEHhQHvhFmK3Zoz",
"rid": "ziUm63f(c3ZBMN@ZWn",
"msg": "test",
"token": "dedecdabcabacbeba",
"alias": "test1",
"ts": {
"$date": 1533235780843
},
"u": {
"_id": "deteeL7h8swBnHYPN",
"username": "guest-3",
"name": "test1"
},
"mentions": [],
"channels": [],
"_updatedAt": {
"$date": 1533235780847
},
"newRoom": true,
"showConnecting": false
}
}
One important thing to notice is that when calling the sendMessageLivechat we need to pass the correct token, in this case the token is => dedecdabcabacbeba.
If the token passed by params is not correct, an error will be raised on client-side:
{
"msg": "result",
"id": "5",
"error": {
"isClientSafe": true,
"error": "invalid-token",
"message": "[invalid-token]",
"errorType": "Meteor.Error"
}
}
So it seems that after many changes since this issue was created, this case is no longer happening. I'm closing this issue and I'll be waiting for feedback from @legendecas.
Thanks.