Skip to content

Instantly share code, notes, and snippets.

@mikaelmello
Last active July 16, 2018 19:07
Show Gist options
  • Save mikaelmello/d553935f472250b21c9b77a5ce4d4e4c to your computer and use it in GitHub Desktop.
Save mikaelmello/d553935f472250b21c9b77a5ce4d4e4c to your computer and use it in GitHub Desktop.

This PR consists of the addition of two features (and packages) to Rocket.Chat

1. ClientCommands

Client Commands is the name given to a solution created to allow the Rocket.Chat server to trigger actions in subscriber clients (bots and possibly other websocket clients). This is handled at the adapter and/or SDK level, not by final users (e.g. normal bot developers).

They are better explained here

1.1. customClientData

Some features depend on which adapter the bot is running on, a bot that does not use the JS SDK might not support a few or all ClientCommands. That's why before showing any of the features, a check is made to see if the account currently supports such feature.

The client sets the customClientData field with information about its custom client. A client that can reply to getStatistics and pauseBot sets customClientData = { canGetStatistics: true, canBePaused: true }, for example.

This field can be used to store any information about the client, such as text commands implemented by the bot.

2. Bot Management Admin Panel

The package rocketchat-bot-manager consists of adding a new section on the administration panel to manage bot accounts, that is, accounts with the type attribute set as 'bot', as discussed here.

2.1. List view

The list view is a list of all the existing bot accounts. It is accessible from the admin sidenav and shows the following information about an account:

  • Status (online/away/busy/offline)
  • Name
  • Username
  • Framework used by the account

Screenshot

2.2. Creation of a bot account

To create a bot account, the admin must first go to the list view and then click on the plus button on the right sidetab, opening a form similar to the one used to create a normal account, except for all e-mail related fields that have been removed.

Screenshot

2.3. Visualizing general info about an account

In the list view, the admin can click on any listed account and a flextab will be opened on the right side, displaying some information about the clicked account. Currently, it is displayed:

  • Roles of the account
  • Last login
  • Framework/Adapter used by the account
  • (Optional) Button to pause or resume the bot

If the admin clicks on the 'More Details' button, it will be taken to the Details page.

Screenshot 1 - Offline account. Screenshot 2 - Online account

2.4. Overview of the newly implemented management features

The features listed here were created using ClientCommands.

2.4.1. Pausing or resuming a bot

Pausing or resuming a bot is handled at the JS SDK, not handled by the bot developer. Therefore any bot that uses the SDK can be paused.

Paused here means that the SDK will unsubscribe itself from the message stream until it is told to resume or is restarted.

2.4.2. Pinging a bot

As it has been previously requested, whenever the admin is visiting a bot's details page, the server pings the bot each second to check if it is still alive and to also know the response time of the bot.

2.4.3. Getting statistics from a bot

Besides statistics that can be retrieved from the server, the total number of messages sent by the account for example, the bot client can also have meaningful data to be displayed in the management view. Therefore the admin can choose to load statistics provided by the bot client. What data is retrieved is specific to each Framework/Adapter.

2.5. Bot Details view

The main management page of a bot is its details page. It displays:

  • Status (offline/online/pauseOrResume) - Pause of Resume is displayed when the bot is online and can be paused
  • Editable field displaying the account name
  • Editable field displaying the account username
  • Editable field to be filled with a new password, if it is to bechanged
  • Framework/Adapter used by the bot
  • Connection status displaying the bot's IP address and its response time (ping)
  • Uptime of how long the bot has been online and another for how long the bot has been active (not paused)
  • Roles and the possibility to add or remove them

Screenshot 1 - Offline. Screenshot 2 - Online

The admin can also delete the account and convert the account to the user type. Converting it to the user type will simply edit the type attribute and ask for an e-mail if the account does not have one.

Regarding the statistics view, it is displayed when the admin clicks on 'Load' and currently shows:

  • Total number of messages sent by the bot
  • Total number of messages in which the bot is mentioned
  • [L] - How many times the bot had to reconnect to the server
  • [L] - How many messages the bot has read
  • [L] - Time when the last message was read
  • [L] - How many users are stored in the Hubot brain (Hubot only).

Items with starting with [L] are retrieved live from the bot client. Note that different adapters can display different information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment