Skip to content

Commit

Permalink
Configure oauth installation URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
adunkman committed Sep 1, 2021
1 parent bd88c16 commit 00ac5ea
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
# - Set configuration values below, and they will be automatically used by
# Docker Compose when running commands.
#
SLACK_TOKEN=aaaa-1111111111111-2222222222222-a1A2a1A2a1A2a1A2a1A2a1A2
SLACK_SIGNING_SECRET=a1A2a1A2a1A2a1A2a1A2a1A2a1A2a1A2
SLACK_CLIENT_ID=1111111111111.2222222222222
SLACK_CLIENT_SECRET=b1B2b1B2b1B2b1B2b1B2b1B2b1B2b1B2
APP_STATE_SECRET=my-state-secret
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The Inclusion Bot is a Slack App which passively listens for language with racist, ableist, sexist, or other exclusionary histories. When it hears such words or phrases, it quietly lets the speaker know and offers some suggestions — helping nudge us all to thoughtful, inclusive language.

<a href="https://slack.com/oauth/v2/authorize?client_id=2429423712965.2439245039812&scope=channels:history,chat:write,chat:write.customize,reactions:write,reactions:read&user_scope="><img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/[email protected]"></a>
<a href="https://inclusion-bot.dunkman.me/install"><img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/[email protected]"></a>

Many thanks to [18F’s Charlie](https://github.com/18F/charlie), from which this bot was extracted and adapted.

Expand Down
26 changes: 22 additions & 4 deletions bot/app.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import { App, ExpressReceiver, LogLevel, subtype } from "@slack/bolt";
import { InstallProvider } from "@slack/oauth";
import { CLOSE_MESSAGE_ACTION_ID, handleMessageClose } from "./actions/closeMessage";
import { handleMenuClick, OVERFLOW_MENU_CLICK_ACTION_ID } from "./actions/menuClick";
import { handleMessage } from "./actions/message";
import { handleMessageEdited } from "./actions/messageEdited";
import { manifest } from "./manifest/manifest";
import { config } from "./triggers/triggers";

const {
SLACK_TOKEN,
SLACK_SIGNING_SECRET,
SLACK_CLIENT_ID,
SLACK_CLIENT_SECRET,
APP_STATE_SECRET,
PORT = "3000",
} = process.env;

const receiver = new ExpressReceiver({
signingSecret: SLACK_SIGNING_SECRET,
clientId: SLACK_CLIENT_ID,
clientSecret: SLACK_CLIENT_SECRET,
stateSecret: APP_STATE_SECRET,
scopes: manifest.oauth_config.scopes.bot,
logLevel: LogLevel.INFO,
});

const app = new App({
token: SLACK_TOKEN,
receiver,
});
// Trust and use Heroku’s X-Forwarded-* headers.
receiver.app.set("trust proxy", true);

const app = new App({ receiver });

(async () => {
await app.start(+PORT);
Expand All @@ -32,4 +41,13 @@ const app = new App({
receiver.router.get("/", async (req, res) => {
return res.redirect("https://github.com/dctech/inclusion-bot#readme");
});

// Until we can use the directInstall option, we need to use a custom handler
// to return a 302.
receiver.router.get("/install", async (req, res) => {
return res.redirect(await receiver.installer.generateInstallUrl({
scopes: manifest.oauth_config.scopes.bot,
redirectUri: `${req.protocol}://${req.hostname}/slack/oauth_redirect`,
}));
})
})();
19 changes: 19 additions & 0 deletions bot/manifest/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { readFileSync } from "fs";
import { join } from "path";
import { load } from "js-yaml";

const path = join(__dirname, "manifest.yml");
const yamlString = readFileSync(path, "utf-8");

/**
* The manifest object returned from yaml.
*/
export const manifest = load(yamlString, { json: true }) as SlackManifest;

export type SlackManifest = {
oauth_config: {
scopes: {
bot: string[];
}
}
};
File renamed without changes.
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ services:
ports:
- "3000:3000"
environment:
SLACK_TOKEN: $SLACK_TOKEN
SLACK_SIGNING_SECRET: $SLACK_SIGNING_SECRET
SLACK_CLIENT_ID: $SLACK_CLIENT_ID
SLACK_CLIENT_SECRET: $SLACK_CLIENT_SECRET
APP_STATE_SECRET: $APP_STATE_SECRET

0 comments on commit 00ac5ea

Please sign in to comment.