Git Product home page Git Product logo

mattermostonfire's Introduction

MattermostOnFire

Build Status

Backend code for powering a Mattermost slash command that creates an interactive poll. Contains Firebase Cloud Functions that connect Mattermost Interactive Buttons with the Firebase Realtime Database.

What does this do?

Watch the video:

Demo

How does it work?

Diagram

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 "poll" or "survey")
  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 slashStart (e.g., https://us-central1-PROJECTID.cloudfunctions.net/slashStart)

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 specify multiple tokens in the mattermost.token environment configuration variable, separating them using a comma like: firebase functions:config:set mattermost.token="token1,token2,token3"

The resulting Firebase environment config would 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 slashStart function

🎉 ALL DONE!

Internationalization

If you want to use a different language other than English, do the following:

  1. Specify the desired language using the 2-letter ISO language code by running firebase functions:config:set mattermost.language="YOUR CODE".
    • Example: running firebase functions:config:set mattermost.language="es" would configure MattermostOnFire to use Spanish instead of English.
    • This should be done prior to running firebase deploy
  2. Check your Firebase environment config by running firebase functions:config:get. For example, if specifying Spanish then your config would look like:
ᐅ firebase functions:config:get
{
  "mattermost": {
    "token": "abcdefghijklmnopqrstuvwxyz",
    "language": "es"
  },
  "functions": {
    "baseurl": "https://us-central1-myprojectid.cloudfunctions.net"
  }
}

Make sure that the language you specify is supported. Check that there is a top-level key in translations for your desired 2 letter language code.

Please help expand this project's support for more languages by opening a pull request to add a new language to the translations file.

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

  1. Run npm run test in the functions directory to ensure that your changes haven't broken any of the functions.

mattermostonfire's People

Contributors

darckcrystale avatar jedfonner avatar mcfoggy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mattermostonfire's Issues

Double-encoding in vote confirmation message

Observed
An apostrophe in a vote option label gets double-encoded in the vote confirmation message. See screenshot.

image pasted at 2018-3-21 11-24

Expected
All characters should be displayed the same in the confirmation message as in the option label.

Multiple choices?

After using MattermostOnFire for some weeks, some users asked for a flag to allow multiple answers per vote. As an example:

/poll Anyone for lunch today? | Pizza | Pasta | Burger | Vegan | multiple=true

or a second shash command /pollsingle and /pollmutiple

would allow the user to vote for Pizza and Burger. As before, the answer with the most votes wins.

Just an idea for a future version...

Cannot deploy project

Hi, @jedfonner !

Thanks for this, I´d really like to try it out but I wasn´t able to deploy the project to Firebase. Do you have any idea what´s going wrong here?

I just edited .firebasrc, set my project name and tried to deploy with firebase deploy.
The firebase login was ok. My Node version is 8.9.3 on Windows.

=== Deploying to 'mattermostonfire-13513'...

i  deploying database, storage, firestore, functions, hosting
i  database: checking rules syntax...
+  database: rules syntax for database mattermostonfire-13513 is valid
i  storage: checking storage.rules for compilation errors...
+  storage: rules file storage.rules compiled successfully
i  firestore: checking firestore.rules for compilation errors...
+  firestore: rules file firestore.rules compiled successfully
i  functions: ensuring necessary APIs are enabled...
+  functions: all necessary APIs are enabled
i  storage: uploading rules storage.rules...
i  firestore: uploading rules firestore.rules...
i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'token' of undefined
    at Object.<anonymous> (C:\Users\xxx\AppData\Local\Temp\fbfn_9072E2sI87dyCPBP\utils.js:3:59)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\xxx\AppData\Local\Temp\fbfn_9072E2sI87dyCPBP\index.js:3:15)
    at Module._compile (module.js:635:30)

Regards,
Markus

Internationalisation?

Hi Jed,

I would like to translate this into German language and thought, the easiest approach would be a forked translated project (as I don´t see any localisation structures in the source code). For my demands, this would be sufficient.

If there would be any demand for other localized versions, it would probably be a better idea to prepare the project to support multiple languages... Perhaps, the user´s language from the Mattermost client could even be transferred to MattermostOnFire?

Regards,
Markus

Firebase Node

If I want to run the command firebase login, the command does not exist.
All the dependencies are installed, I run node version 10.7.0 and npm 6.1.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.