All Projects → JSzaszvari → rocketchat-ddp-listener

JSzaszvari / rocketchat-ddp-listener

Licence: other
Subscribes and listens to the Real Time stream of all messages happening in a Rocket.Chat Channel/Room

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to rocketchat-ddp-listener

mmb
Set of Dockerfiles and assets related to them for building Docker images with different services
Stars: ✭ 34 (-24.44%)
Mutual labels:  rocketchat
rocket.chat.app-poll
Rocket.Chat App for creating polls.
Stars: ✭ 46 (+2.22%)
Mutual labels:  rocketchat
rocketchat-gitlab-hook
Add GitLab notifications via a new WebHook in Rocket.Chat
Stars: ✭ 80 (+77.78%)
Mutual labels:  rocketchat
st2chatops
Packaging environment for building StackStorm chatops native packages
Stars: ✭ 26 (-42.22%)
Mutual labels:  rocketchat
notify
推送通知 sdk(Bark、Chanify、钉钉群机器人、Discord、邮件、飞书群机器人、Gitter、Google Chat、iGot、Logger、Mattermost、Now Push、PushBack、Push、PushDeer、PushPlus、QQ 频道机器人、Rocket Chat、Server 酱、Showdoc Push、Slack、Telegram、Webhook、企业微信群机器人、息知、Zulip)。
Stars: ✭ 335 (+644.44%)
Mutual labels:  rocketchat
platform-services
Collection of platform related tools and configurations
Stars: ✭ 11 (-75.56%)
Mutual labels:  rocketchat
docker-rocketchat
🚢📦My `docker-compose.yml` file/setup to run Rocket.Chat in production
Stars: ✭ 47 (+4.44%)
Mutual labels:  rocketchat
Rocket.Chat.Java.SDK
[DEPRECATED, NOT MAINTAINED] Java/Android SDK for Rocket.Chat
Stars: ✭ 27 (-40%)
Mutual labels:  rocketchat
Rocket.Chat.PWA.React
React Implementation of Rocket.Chat.PWA
Stars: ✭ 36 (-20%)
Mutual labels:  rocketchat
rocketchat-uptimerobot
Uptime Robot integration for Rocket.Chat
Stars: ✭ 34 (-24.44%)
Mutual labels:  rocketchat
Matterbridge
bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Stars: ✭ 4,452 (+9793.33%)
Mutual labels:  rocketchat

Rocket.Chat DDP Listener Example

ezgif-2-eb541d6666

Summary

This is a example script written using NodeJS that connects to Rocket.Chat's Real Time API using Meteor's DDP (Distributed Data Protocol) and listens to a Channel/Room.

With the Rocket.Chat Real Time API you can "Subscribe" to events to get a "Real Time Stream" of actions/messages.

The following example subscribes to a private or public channel and listens for all messages posted and displays them in real time.

The DDP protocol is commonly used to write custom chat clients for Meteor based apps (Or anything that requires a real time stream of messages to be received)

node-ddp-client

This script utilises the node-ddp-client package and ddp-login package to talk to Rocket.Chat using it's Real-Time API.

Please see those repositories on how to expand/build on what I have provided as this is just a simple example.

Getting Started with this script

First, We need a valid authToken so we can authenticate and we will also need the '_id' of the channel/group that we want to listen into.

Obtaining the authToken

First, obtain a authToken from the standard Rocket.Chat API.

These do not expire, So once generated you are good for as long as you need it for - You can get a authToken using the Standard (Not Real-time API) using the following curl command:

    curl -X "POST" "https://chat.myserver.com/api/v1/login" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d $'{
    "username": "my_username",
    "password": "my_password"
    }'

You will get a response like this. Take note of the authToken and userId as we will need this:

    {
    "status": "success",
    "data": {
    "authToken": "HSus82-hkmVAy-gECPS-QT5G0sCISSWzEEpfA7JybCv",
    "userId": "uJK8DarWEz4KXywZrJ"
    }

Take note of the authToken and userID as we will use these to obtain the ID of the Group/Channel we are going to subscribe too.

Obtaining the ID of a Group/Channel

We need the obtain the "_id" of the Group or Channel that we want to subscribe too. This is also done through the standard Rocket.Chat REST API.

A Channel is a private/locked room that is invite only and a Room is a public channel that anyone can join.

You can get the "_id" for a Channel with the API 'channels.list' API call, and for a Room with the API 'rooms.list' API call.

Use the curl commands below to get a list of the Channels/Room and find the '_id' parameter for the one you need

Get Full Channel List

Request:

curl "https://chat.myserver.com/api/v1/channels.list" \
     -H "X-User-Id: uJK8DarWEz4KXywZrJJ" \
     -H "X-Auth-Token: HSus82-hkmVAy-gECPS-QT5G0sCISSWzEEpfA7JybCv" \
     -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8"

Response:

{
  "channels": [
    {
      "_id": "LakQFGoB7FuTm8Fm5",
      "name": "channel-name",
      "t": "c",
      "msgs": 354,
      ....
}

Get Full Group List

Request:

curl "https://chat.myserver.com/api/v1/groups.list" \
     -H "X-User-Id: uJK8DarWEz4KXywZrJJ" \
     -H "X-Auth-Token: HSus82-hkmVAy-gECPS-QT5G0sCISSWzEEpfA7JybCv" \
     -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8"

Response:

 {
      "_id": "CYSvXNdL7BxKncB4S",
      "name": "my-super-group",
      "t": "p",
      "msgs": 7335,
      .....
 }

Running the script

  1. Clone the git repo

     git clone https://github.com/jszaszvari/rocketchat-ddp-listener.git
    
  2. Go into the repo we just cloned

     cd rocketchat-ddp-listener
    
  3. Use NPM to install any needed dependancies that the script requires:

     npm install
    
  4. Edit the 'listen_to_room.js' script and fill in the 'authToken' and 'subscription' variables (See the 'Getting a authToken and roomId' section above if you need help with this) as well as your server's connection details.

More info on the Rocket.Chat Real-time API

Note: The Real Time API in Rocket.Chat is based on a unreleased version of the API.

The Real-time API is composed of two elements: Method Calls and Subscriptions.

Method calls are used to trigger actions based on the passed data.

Streams are the way to plug into a continuous source of updates (changes). Any subscriber registered will receive the latest changes as they happen in real-time.

See more info on the RealTime API at the following

https://rocket.chat/docs/developer-guides/realtime-api/

https://rocket.chat/docs/developer-guides/realtime-api/method-calls/

https://rocket.chat/docs/developer-guides/realtime-api/subscriptions/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].