# Communication between two users using real time api

**URL:** <https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392>\
**Category:** Development\
**Created:** [June 11, 2021, 12:25pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392 "2021-06-11T12:25:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hassan20896](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@Hassan20896](https://forums.rocket.chat/u/Hassan20896)\
**Post date:** [June 11, 2021, 12:25pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/1 "2021-06-11T12:25:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 11, 2021, 3:44pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/2 "2021-06-11T15:44:37Z")

</div>

Probably need to start here:

> **[Realtime API](https://developer.rocket.chat/api/realtime-api)**

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 12, 2021, 4:24pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/3 "2021-06-12T16:24:33Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![Hassan20896](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@Hassan20896](https://forums.rocket.chat/u/Hassan20896)\
**Post date:** [June 12, 2021, 5:16pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/4 "2021-06-12T17:16:31Z")

</div>

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

I am using this socket url.

---

<div class="post-metadata">

**Author:** ![Hassan20896](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@Hassan20896](https://forums.rocket.chat/u/Hassan20896)\
**Post date:** [June 13, 2021, 1:33pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/5 "2021-06-13T13:33:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 14, 2021, 8:46am UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/6 "2021-06-14T08:46:10Z")

</div>

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/](https://beautifier.io/) to test

```auto
{
    “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?

```auto
{
    "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.

---

<div class="post-metadata">

**Author:** ![Hassan20896](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@Hassan20896](https://forums.rocket.chat/u/Hassan20896)\
**Post date:** [June 15, 2021, 7:59pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/7 "2021-06-15T19:59:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 15, 2021, 11:20pm UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/8 "2021-06-15T23:20:14Z")

</div>

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’

> <https://gist.github.com/reetp/a66149d5f060f260643a353ca7067a98>

These two are particularly useful.

[https://www.chiark.greenend.org.uk/~sgtatham/bugs.html](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html)

[http://www.catb.org/esr/faqs/smart-questions.html](http://www.catb.org/esr/faqs/smart-questions.html)

---

<div class="post-metadata">

**Author:** ![Hassan20896](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@Hassan20896](https://forums.rocket.chat/u/Hassan20896)\
**Post date:** [June 16, 2021, 4:34am UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/9 "2021-06-16T04:34:17Z")

</div>

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.

```auto
{
    "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

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

```

and then

```auto
{
    "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

---

<div class="post-metadata">

**Author:** ![ayyoob](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@ayyoob](https://forums.rocket.chat/u/ayyoob)\
**Post date:** [August 6, 2024, 10:34am UTC](https://forums.rocket.chat/t/communication-between-two-users-using-real-time-api/11392/10 "2024-08-06T10:34:32Z")

</div>

Hii hassan ,have you implemented rocket chat in your flutter app,  
i also want use Rocket chat in flutter app,if you have done ,could you help me
