Communication between two users using real time api

Hi, I want to integrate rocket chat real time api on Flutter app for communication between users. Can anyone tell me about sequence of API I need to consume for this. I need it in real time.

Probably need to start here:

My objective is to communicate between two users using Rocket chat real time api.

First of all, I consumed “createDirectMessage” that gives me rId. And then I send message using “sendMessage” api. But message is not received at receiver end.

I double checked that userName provided sent on “createDirectMessage” is correct.

I think you are going to have to give us a lot more information here.

How is your server setup. What version?

Some samples of code?

final String webSocketUrl = “wss://open.rocket.chat/websocket”;

I am using this socket url.

Flow of events:

  1. Login using this api

{“msg”:“method”,“method”:“login”,“params”:[{“user”:{“email”:“xxx”},“password”:{“digest”:“xxxx”,“algorithm”:“sha-256”}}],“id”:“47”}

this api responds with:
{“msg”:“result”,“id”:“47”,“result”:{“id”:“xxxx”,“token”:“xxxxx”,“tokenExpires”:{"$date":1631366708063},“type”:“password”}}

  1. Then I use this Api

{“msg”:“sub”,“name”:“stream-room-messages”,“params”:[“room-id”,false],“id”:“stream-room-messages-65RVqEc_16_MxJWZXbF1pw==”}

that gives this reponse

{“msg”:“nosub”,“id”:“stream-room-messages–s3KM9yYvRlMZuhAfooT6w==”}

  1. then I call this api to send message

{“msg”:“method”,“method”:“sendMessage”,“params”:[{"_id":“user-id”,“rid”:“room-id,”,“msg”:“Hello Hassan!”}],“id”:“48”}

That responds me with

{“msg”:“result”,“id”:“48”}

But message I sent from client 1 is not received on client 2 stream.

I have mentioned url I am using on a message before

Can you format your code when you paste it? It makes it much easier to read!

I copied a bit of yours to https://beautifier.io/ to test

{
    “msg”: “method”,
    “method”: “sendMessage”,
    “params”: [{
        "_id": “user-id”,
        “rid”: “room-id,”,    <<< extra comma here after room-id? 
        “msg”: “Hello Hassan!”
    }],
    “id”: “48”
}

It should look like this from the docs?

{
    "msg": "method",
    "method": "sendMessage",
    "id": "42",
    "params": [
        {
            "_id": "message-id",
            "rid": "room-id",
            "msg": "Hello World!"
        }
    ]
}

Yours seems to be missing:

"_id": "message-id",

Please go back and check all your code carefully, and use our examples to test.

1 Like

Which stream do I need to listen to receive messages on my client mobile application? Message sent from my client application is received by rocket chat web client, but vice versa is not functioning. Thanks in advance.

Before working on rocket chat, I created a simple meteor server. And on that server,

meteor.collections['messages']

listening to the above stream was working

Working on a simple meteor server is probably not like working on a full Rocket.Chat server.

I’ll have to try and find you some more help as this is not a simple exercise and you are not helping by not giving decent information.

I really suggest you read some of the links in here on ‘How to ask for help’

These two are particularly useful.

https://www.chiark.greenend.org.uk/~sgtatham/bugs.html

http://www.catb.org/esr/faqs/smart-questions.html

Rocket.Chat Version: 3.16.0-develop
NodeJS Version: 12.22.1 - x64
MongoDB Version: 4.2.8
MongoDB Engine: wiredTiger
Platform: darwin
Hardware: Macbook Pro 2017
OS: MacOS BigSur
Client: Flutter App

My objective is to establish communication between Flutter clients.

I am using API in this sequence currently.

{
    "msg": "method",
    "method": "login",
    "params": [
        {
            "resume": "tIz9zGw9kyPjpD-Hz2pjXsxw3jpOrnzSyeiGBvD7qwY"
        }
    ],
    "id": "1"
}

Above is the first API I am using.

Then, create room I am using below api

{
    "msg": "method",
    "method": "createDirectMessage",
    "params": [
        "hassan123"
    ],
    "id": "3"
}

and then

{
    "msg": "method",
    "method": "sendMessage",
    "params": [
        {
            "_id": "R4aglvDhjgx0Tv0SIBXkH40g",
            "rid": "LQPcW3fdd66A6w6baTPc9F3G5czz9T45AQ",
            "msg": "Hello"
        }
    ],
    "id": "4"
}

Message is received on rocket chat web client. But Its not getting received on Flutter client.

StreamBuilder(
stream: BlocProvider.of(context)
.meteor
.collections[‘messages’],

It’s the stream that worked on simple meteor client. But its not working with rocket chat