Home

Awesome

Mattermost logo

Downloads Version Licence

hubot-mattermost

Hubot adapter for Mattermost. Enables to add a Hubot bot to Mattermost.

Getting your bot connected to Mattermost

Here is a sample run:

picture of a sample interaction with mattermost

Installation

Example Installation

npm install -g yo generator-hubot
yo hubot --adapter mattermost

Environment variables

The adapter requires the following environment variables to be defined prior to run a Hubot instance:

In addition, the following optional variables can be set:

Example for Environment variables

export MATTERMOST_ENDPOINT=/hubot/incoming # listen endpoint
export MATTERMOST_CHANNEL=town-square # optional: if you want to override your channel
export MATTERMOST_INCOME_URL=http://<your mattermost instance>:<port>/hooks/ncwc66caqf8d7c4gnqby1196qo # your mattermost income url
export MATTERMOST_TOKEN=oqwx9d4khjra8cw3zbis1w6fqy # your mattermost token
export MATTERMOST_ICON_URL=https://s3-eu-west-1.amazonaws.com/renanvicente/toy13.png # optional: if you want to override hubot icon
export MATTERMOST_HUBOT_USERNAME="matterbot" # optional: if you want to override hubot name
export MATTERMOST_SELFSIGNED_CERT=true # optional: if you want to ignore self signed certificate

Example with Hubot sending to multiple specific channels only

Although Mattermost doesn't allow multiple channels on a single Incoming/Outgoing hook you can do the following in order to allow Hubot to listen to multiple channels:

Example:

export MATTERMOST_ENDPOINT=/hubot/incoming # listen endpoint
export MATTERMOST_INCOME_URL=http://localhost:8065/hooks/3eo1wjwyxibnmd5rsusk4h4pgh # your mattermost income url
export MATTERMOST_TOKEN="epboqd78ufyi58nxktgzq9zpho,7ftco7zg5fdkixw7j3okmuo3eo" # your mattermost token for **each Channel**
export MATTERMOST_ICON_URL=https://s3-eu-west-1.amazonaws.com/renanvicente/toy13.png # optional: if you want to override hubot icon
export MATTERMOST_HUBOT_USERNAME="matterbot" # optional: if you want to override hubot name

Note that there is no need to create multiple Incoming Hooks as we can use a single Incoming Hook but specify what channel we want to send the message to as described in the documentation.

Run hubot with mattermost adapter.

bin/hubot -a mattermost

Example with Hubot sending to ANY public channel

As pointed out by Andre there's a new Giphy implementation that leverages an Outgoing hook with no channel set, in which Mattermost allows us to send messages to any channel based on Trigger Words feature only.

Therefore, if all you want to do is to have Hubot to send/reply to all public channels, all you will need to do is:

Example of a hook created using this pattern:

URLs: http://localhost:8080/hubot/incoming
Trigger Words: matterbot
Token: 15r8ybrxhpgifc3rycdjrf6m8e

Example of global variables set that will send to any public channel if message starts with matterbot:

export MATTERMOST_ENDPOINT=/hubot/incoming # listen endpoint
export MATTERMOST_INCOME_URL=http://localhost:8065/hooks/3eo1wjwyxibnmd5rsusk4h4pgh # your mattermost income url
export MATTERMOST_TOKEN="epboqd78ufyi58nxktgzq9zpho,7ftco7zg5fdkixw7j3okmuo3eo" # your mattermost token
export MATTERMOST_ICON_URL=https://s3-eu-west-1.amazonaws.com/renanvicente/toy13.png # optional: if you want to override hubot icon
export MATTERMOST_HUBOT_USERNAME="matterbot" # optional: if you want to override hubot name

Known issues

With this approach Hubot.hear method will be invalidated, since a POST message will only be sent from Mattermost if Hubot name (MATTERMOST_HUBOT_USERNAME="matterbot") is mentioned.

So, if you have the following in any of your custom scripts -- that will no longer work:

robot.hear /HEY$/i, (msg) ->
	msg.reply "Yo!"

Workaround

In order to have both working (send messages to any public channel + hubot actively listening to certain messages) you would need to:

Example of Outgoing Hook created using option A:

URLs: http://localhost:8080/hubot/incoming
Trigger Words: hey
Token: 9r8i6s86hbgc8r57hqc5ywijac

By simply typing: "hey" in any channel Hubot should be able to respond with "Yo!" as Mattermost now sends a POST to Hubot.

License

The MIT License. See LICENSE file.