The Ramblings of a Linux admin with his head in the clouds

Trimming RocketChat

This functionality was added to newer versions of rocketchat, this same way WILL work, but it’s easier to do it in the room interface.

We switched from a paid slack account last year, to rocketchat.

I’ve written bots in the past to alert coworkers of system issues in a more public place, but some of my rooms were getting upwards of 10,000 messages and the browser and phones would be extremely slow pulling the room up as message counts were growing.

Sending messages to a chat in a controlled manor is a great way to alert a lot of people to issues, or log something. This should make it super easy to clean the rooms out when they grow larger than you thought they would!

python to the rescue!

My client can do the following:

  1. test connection to server (–whoami)
  2. send a message to a user. (–send –user justin –text “hi there!”)
  3. send a message to a group. (–send –group groupname –text “Hi there!”)
  4. send a message to a channel. (–send –channel channelname –text “Hi there!”
  5. delete all messages in a group. (–delete –group roomname –iknow)
  6. delete all messages in a channel. (–delete –channel roomname –iknow)
  7. install saved rocketchat credentials. (–install –rcuser user –rcpass pass –rchost hostname)
  8. spam a group with test messages (–trash –iknow –group groupname)
  9. spam a channel with test messages (–trash –iknow –channel channelname)

What are these groups and channels?

On rocketchat it gets a little confusing sometimes. If you have a room, where everyone is allowed to view and post, it’s considered a “channel”.

If you have a private channel, it’s considered a “group”.

Cosmicray-rocketchat

I found a newer api, as my last client was using rocket-python, which didnt seem to allow me to delete messages in a somewhat controlled manor.

The api can be installed like so

to use the software paste the following in a file, name it rc-client.py

you might want to install python3:

it’s in the repo for centos, and fedora, and pretty much any operating system, since I use rpm based distros, these instructions are for CentOS.

once saved, use the following examples:

first install example:

delete messages from channel:

delete messages from room:

send a message to a group:

send a message to a channel:

send a message to a user:

fill a channel with test messages:

file a group with test messages: