Rocket.chat: How to send direct message in Rochet Chat using REST Api?

Created on 14 Dec 2017  路  4Comments  路  Source: RocketChat/Rocket.Chat

I work with codeigniter. And i try to build own chat in my project using REST APi of Rochet Chat. But I don't know how to send private message or create direct room. In documentation this topic doesn't exist.If you know ansver help me. Thanks.

Most helpful comment

Yes you can. Just testes and worked with this:

      curl -H "X-Auth-Token: TAKE-YOUR-TOKEN-FROM-YOUR-LOGIN-JSON" \
      -H "X-User-Id: YOUR-USER-ID" \
      -H "Content-type:application/json" \
      http://URL-OF-YOUR-ROCKET-CHAT/api/v1/chat.postMessage \
      -d '{ "channel": "@NAME-OF-USER-TO-RECEIVE-DM", "text": "This is a direct message!" }'

In channel, just replace #CHANNEL for @USERNAME

All 4 comments

You can find the documentation on the direct message api here

Found the solution in another issue:

POST /api/v1/chat.postMessage
{
    "roomId": "the-room-id",
    "text": "Hello world!",
    "channel": "@destination-user-name"
}

This should be added to the documentation.

I'm sorry to re-open this but /api/v1/chat.postMessage is for channel only. I couldn't found any /api/v1/im.postMessage or equivalent for im/dm in the documentation. if it does exist ?
or maybe I should use chat.postMessage ? If yes the "channel" is set as requiered but im dot have any so what should I do ?

Yes you can. Just testes and worked with this:

      curl -H "X-Auth-Token: TAKE-YOUR-TOKEN-FROM-YOUR-LOGIN-JSON" \
      -H "X-User-Id: YOUR-USER-ID" \
      -H "Content-type:application/json" \
      http://URL-OF-YOUR-ROCKET-CHAT/api/v1/chat.postMessage \
      -d '{ "channel": "@NAME-OF-USER-TO-RECEIVE-DM", "text": "This is a direct message!" }'

In channel, just replace #CHANNEL for @USERNAME

Was this page helpful?
0 / 5 - 0 ratings

Related issues

royalaid picture royalaid  路  3Comments

ghost picture ghost  路  3Comments

tanc picture tanc  路  3Comments

zeigerpuppy picture zeigerpuppy  路  3Comments

lunitic picture lunitic  路  3Comments