Bwen / slack-multi-app

Slack App to support multiple apps structure within a single one

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BUILD ExpressJs Slack API

COVERAGE Maintainability Tech Debt

Current Version

Slack Multi APPs

Supports multiple sub-apps within the same structure, governed by a centralized group ACL. The project is not meant to be published on the Slack APP directory as a standalone app. It is more geared towards bootstrapping a self-hosted enterprise Slack application after customizing it to the enterprise's needs. Such as deployment of the company's product to various internal environments (QA, Staging, Production) for example. All through the enterprise's Slack.

For more information on the Slack Module System and how it is structured.

For more information on the access restrictions you can read about the Admin Module.

The project comes with Poll Module & Agile Pulse Module, which serves as an example of how the module system works with modals, interactions, form submission, generating charts, periodic tasks, download of custom data, etc...

The libraries

At its core it is built with NodeJS on top of the HTTP framework Express. Our ORM of choice is Sequelize. We are using Mocha, Chai and mock-require for the tests. The project applies the ESLint Airbnb standard, to keep in mind when contributing to the project.

There are several custom express middleware to ease the development of the sub-apps. Also Sequelize should be used according to the following details. I encourage everyone to read both before starting development.

The Slack APP required scopes

Slack Scopes

The APP will also require to activate the following functionalities:

  • Interactive Components
  • Slash Commands
  • Bots

With the proper URLs for the environment you are setting up.

Local development environment

For development, I recommend a separate Slack Workspace than the one used for production as they both require their own callback URLs. For the local environment I strongly suggest using ngrok, which is a tool to open a tunnel to your machine so Slack can talk to it. It has a reasonable price for permanent ngrok.io sub-domain names, this way we don't have to change the Slack app URL configurations every time we restart ngrok.

The first thing to get the local development environment going is to copy .env-example to .env and changing the environment variables to the desired values. A connection to an SQL server (MySQL, MariaDb, Postgres, etc...), and an existing database which is defined in the .env under MYSQL_DATABASE. If you do not wish to use MySQL, you will have to change the variable names as well as the Sequelize config connection url which is defined in config/sequelize.js.

With Docker

The simplest way to get a MySQL server going is probably to run the official docker image like so:

docker run \
    --rm \
    --name mysql-server \
    -p 3306:3306 \
    -e MYSQL_PORT=3306 \
    -e MYSQL_DATABASE=slack_app \
    -e MYSQL_ROOT_PASSWORD=my-password \
    -e MYSQL_USER=slack \
    -e MYSQL_PASSWORD=my-password \
    -d mysql:latest

The docker run commands can be lengthy thus we have added a bash shortcuts in bin/* which points in the container. To get the app running execute the following:

// Build image
docker build -t slack-app .

// npm install node_modules in the container for its specific node version 
// which installs them in the project's root because of the -v volume
bin/npm install

// Start the server in dev mode
bin/start_app run dev

// Execute ESLint
bin/npm run lint

// Execute the tests
bin/npm run test

// Stop the server
bin/stop_app

To create new Sequelize Models & Migrations we created another shortcut in bin/sequelize. You can use it like so:

bin/sequelize 

// Check migration status
bin/sequelize migrate:status

Without Docker

You will need install NodeJS locally and the following packages globally:

sudo apt install sqlite3

npm install -g coveralls nyc nodemon sequelize-cli
npm install

// Run the linter
npm run lint

// Run the tests
npm run test

// Check migration status
sequelize db:migrate:status

// Start the server in dev mode
npm run dev

Once server running

In either case the database slack_app need to exists and be the database user need to be able to create and alter tables.

We recommend the SQL client DBeaver, you can connect to the database server (localhost ports with or without docker) to verify that everything has been created correctly and monitor results as you develop your app.

When running in dev it will first run the database migrations and seeds then starts the app with nodemon which will handle the hot reload (restart the server) when you modify files.

Referer to package section for the details of the scripts.

About

Slack App to support multiple apps structure within a single one


Languages

Language:JavaScript 98.8%Language:Shell 1.0%Language:Dockerfile 0.2%Language:Batchfile 0.0%