Skip to content

Commit

Permalink
Fix slackapi#1358 Expose common utilities for building HTTP module ba…
Browse files Browse the repository at this point in the history
…sed receivers
  • Loading branch information
seratch committed Mar 25, 2022
1 parent 8ab3105 commit 60eb6fe
Show file tree
Hide file tree
Showing 20 changed files with 963 additions and 335 deletions.
4 changes: 4 additions & 0 deletions examples/custom-receiver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
dist/
node_modules/
package-lock.json
53 changes: 53 additions & 0 deletions examples/custom-receiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Bolt for JavaScript Koa Receiver Example App

This is a quick example app to demonstrate how to implement a custom receiver to integrate `App` with 3rd party web framework, which allows developers to directly access Node.js http package interface.

## Install Dependencies

To link to latest source code, you can run the following script:

```
./link.sh
```

## Setup Environment Variables

This app requires you setup a few environment variables. You can find these values in your [app configuration](https://api.slack.com/apps).

```bash
export SLACK_CLIENT_ID=YOUR_SLACK_CLIENT_ID
export SLACK_CLIENT_SECRET=YOUR_SLACK_CLIENT_SECRET
export SLACK_SIGNING_SECRET=YOUR_SLACK_SIGNING_SECRET
```

## Run the App

Start the app with the following command:

```
npm start
```

### Running with OAuth

Only implement OAuth if you plan to distribute your application across multiple workspaces. Uncomment out the OAuth specific comments in the code. If you are on dev instance, you will have to uncomment out those options as well.

Start `ngrok` so we can access the app on an external network and create a redirect URL for OAuth.

```
ngrok http 3000
```

This output should include a forwarding address for `http` and `https` (we'll use the `https` one). It should look something like the following:

```
Forwarding https://3cb89939.ngrok.io -> http://localhost:3000
```

Then navigate to **OAuth & Permissions** in your app configuration and click **Add a Redirect URL**. The redirect URL should be set to your `ngrok` forwarding address with the `slack/oauth_redirect` path appended. ex:

```
https://3cb89939.ngrok.io/slack/oauth_redirect
```

Start the OAuth flow from https://{your own subdomain}.ngrok.io/slack/install
11 changes: 11 additions & 0 deletions examples/custom-receiver/link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

current_dir=`dirname $0`
cd ${current_dir}
npm unlink @slack/bolt \
&& npm i \
&& cd ../.. \
&& npm link \
&& cd - \
&& npm i \
&& npm link @slack/bolt
26 changes: 26 additions & 0 deletions examples/custom-receiver/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "bolt-oauth-example",
"version": "1.0.0",
"description": "Example app using OAuth",
"main": "app.js",
"scripts": {
"lint": "eslint --fix --ext .ts src",
"build": "npm run lint && tsc -p .",
"build:watch": "npm run lint && tsc -w -p .",
"start": "npm run build && node dist/app.js"
},
"license": "MIT",
"dependencies": {
"@koa/router": "^10.1.1",
"@slack/logger": "^3.0.0",
"@slack/oauth": "^2.5.0-rc.1",
"dotenv": "^8.2.0",
"koa": "^2.13.4"
},
"devDependencies": {
"@types/koa__router": "^8.0.11",
"@types/node": "^14.14.35",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
}
}
Loading

0 comments on commit 60eb6fe

Please sign in to comment.