1

I'm trying to build my own chat frontend for the Rocket.Chat Live Chat. But currently I have the problem, that I can't subscribe to a live chat room for listening.

1) RealtimeAPI: I connect to the the rocket.chat webservice

2) RealtimeAPI: I register the guest user with "livechat:registerGuest"

3) Rest API: I create a room with "/api/v1/livechat/room?token="

I get this as answer:

{ room:
 { _id: '43TJpc3q9eRjqhFXW',
   msgs: 1,
   usersCount: 2,
   lm: '2020-05-26T13:29:21.965Z',
   fname: 'jxkyZ72fFneYCMNnM',
   t: 'l',
   ts: '2020-05-26T13:29:21.965Z',
   departmentId: '2DKbAHmjxHtEL8g3n',
   v:
    { _id: 'D6B7wJ7kcFb2QmR2u',
      username: 'guest-83',
      token: 'jxkyZ72fFneYCMNnM',
      status: 'online' },
   cl: false,
   open: true,
   waitingResponse: true,
   _updatedAt: '2020-05-26T13:29:22.047Z',
   servedBy:
    { _id: 'irByyRx98ii4wjGmj',
      username: 'Admin',
      ts: '2020-05-26T13:29:22.019Z' } },
newRoom: true,
success: true }

I use this _id: '43TJpc3q9eRjqhFXW' value for the subscription room name, all others cause "invalid event"

4) I try to subscribe to "stream-room-messages" and to "stream-livechat-room", but for both I receive only {"msg":"nosub","id":"3"} and not something like this

{
    "msg":"ready",
    "subs":[
        "43TJpc3q9eRjqhFXW"
    ]
}

And I receive no messages from the live chat room.

Can someone tell me what I'm doing wrong or what is missing?

Thanks in advance Frank

DeeFour
  • 436
  • 5
  • 17

1 Answers1

4

Ok, I found my own answer, after a lot of testings.

To subscribe for live chat message events the object has to look like this: (Correct Object)

{
 "msg":"sub",
 "id":"3",
 "name":"stream-room-messages",
 "params":[
     roomname,
     {
       "useCollection":false,
       "args":[{"visitorToken":token}]
     }
  ]
}

It must be "visitorToken" instead of "token".

the official documentation is wrong here, it says: (Wrong Object)

{
    "msg":"sub",
    "id":"6NctZomXL3ZdtKNsn",
    "name":"stream-livechat-room",
    "params":[
        "KTZqPAR9DQGxKcxzf",
        {
            "useCollection":false,
            "args":[
                {
                    "token":"jkGaw6duhiuh45"
                }
            ]
        }
    ]
};

Now it works to subscribe the live channel and to receive messages from the Live Agent.

DeeFour
  • 436
  • 5
  • 17
  • Please note that the message name needs to be changed from "stream-livechat-room" to "stream-room-messages" as well! – daniel-sc Jan 04 '22 at 11:57