Skip to content

McFoggy/TodoOnFire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TodoOnFire

Build Status

Backend code for powering a Mattermost slash command that allow to create, view & perform todos/tasks.

This project has been greatly inspired by Jed Fonner work on his vote/poll application for Mattermost.

What does this do?

Watch the video:

Demo

Set up

Setting this up requires doing some initial Firebase setup, then doing some initial Mattermost setup, then wiring the two systems together.

Initial Firebase Setup

  1. Create a new project in Firebase
  2. Clone this repo to a new local folder and cd into the new folder
  3. Run cd functions && npm install
  4. Run firebase login
  5. Run firebase use --add and select the Firebase project you created in step 1.
  6. Go to your Firebase project settings and note the "Project ID". Your Functions' base url will be https://us-central1-PROJECTID.cloudfunctions.net (replace PROJECTID with your Project ID)
  7. Set the Firebase Functions base url (e.g., https://us-central1-PROJECTID.cloudfunctions.net) as a Firebase environment variable by running firebase functions:config:set functions.baseurl="your functions base url" (starting with https:// and ending without a trailing slash)

Initial Mattermost Setup

  1. Create a new Slash command in Mattermost (I suggest calling it something short, like "todo" or "task")
  2. Select "POST" for Request Method
  3. Fill in a dummy Request URL for now, we'll come back and change this in a bit.
  4. Fill out the rest of the Slash command configuration as you please, then save
  5. Mattermost will generate a unique token for your Slash command. Note that down.

Finish Firebase Setup

  1. Set the Mattermost token as a Firebase environment variable by running firebase functions:config:set mattermost.token="your Mattermost token"
  2. Check your Firebase environment config by running firebase functions:config:get - it should look like:
ᐅ firebase functions:config:get
{
  "mattermost": {
    "token": "abcdefghijklmnopqrstuvwxyz"
  },
  "functions": {
    "baseurl": "https://us-central1-myprojectid.cloudfunctions.net"
  }
}
  1. Deploy your project by running firebase deploy.
  2. When it finishes deploying, it will log the URL for each Function. Note the "Function URL" for slashTodo (e.g., https://us-central1-PROJECTID.cloudfunctions.net/slashTodo)

On a single installation, if you have multiple mattermost teams and want to use the slash command on each, then you have to register several tokens (one for each slash command created). For that you can define token to contain several command id by separating them using a comma firebase functions:config:set mattermost.token="token1,token2,token3"

The resulting Firebase environment config should look like:

ᐅ firebase functions:config:get
{
  "mattermost": {
    "token": "token1,token2,token3"
  },
  "functions": {
    "baseurl": "https://us-central1-myprojectid.cloudfunctions.net"
  }
}

Finish Mattermost Setup

  1. Edit your Mattermost Slash command and update the Request URL to be the URL of your Firebase Functions slashTodo function

🎉 ALL DONE!

Runtime configuration

Tokens: security to close tasks in a channel

One of the feature of the service is to allow to remove/close tasks even if you are not the author of the task.

This is done via the command: /todo remove | [ ID | ALL ] | TOKEN
where TOKEN is a valid token configured at:

  • channel level
  • team level
  • global level

Using a channel level token, one can close any task of the channel.
Using a team level token, one can close any task of any channel of the team. Using a global level token, one can close any task anywhere in the system.

Global tokens

Those are the ones defined previously under the key: mattermost.token

Team token

You can define one or more token per team (separate them with commas), by using the teamId

  • configuring team tokens: firebase functions:config:set mattermost.team.TEAMID="token1,token2"
  • updating the application: firebase deploy --only functions

Channel token

You can define one or more token per channel (separate them with commas), by using the teamId & channelId

  • configuring channel tokens: firebase functions:config:set mattermost.team.TEAMID.channel.CHANNELID="token1,token2"
  • updating the application: firebase deploy --only functions

Runtime Monitoring

  • You can review the logs for the functions via the Functions > Logs interface of the Firebase Console
  • You can introspect the data being generated via the Database interface of the Firebase Console

Developing

Running Locally

Tests

TODO