Skip to content
This repository was archived by the owner on Jul 23, 2019. It is now read-only.

Commit e559ed2

Browse files
authored
Merge pull request #39 from aoberoi/docs-and-example
README rewrite and initial version of express-all-interactions example
2 parents 69e5bc2 + 385c515 commit e559ed2

File tree

16 files changed

+1123
-180
lines changed

16 files changed

+1123
-180
lines changed

.github/maintainers_guide.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ All you need to work with this project is a recent version of Node.js (current L
1111

1212
## Tasks
1313

14+
### Debugging
15+
16+
This package uses [`debug`](https://github.com/visionmedia/debug) to log interesting data while
17+
running. This is a good first step in trying to diagnose an issue. To enable the output, set the
18+
following environment variable: `DEBUG=@slack/interactive-messages:*`.
19+
1420
### Building
1521

1622
The source of this project is written in ES2016, a modern JavaScript syntax. In order to allow the
@@ -40,8 +46,12 @@ using the following command: `./node_modules/.bin/mocha test/unit/{test-name}.js
4046

4147
### Generating Documentation
4248

43-
There is no generated documentation for this project. The README serves as a guide and the reference
44-
documentation is written manually in markdown in `docs/reference.md`.
49+
The documentation is generated using the `npm run build:docs` task and output as a single file in
50+
`docs/reference.md`. The documentation is generated from [JSDoc](http://usejsdoc.org) markup syntax
51+
(with slight variation for support of the underlying
52+
[`jsdoc2md`](https://github.com/jsdoc2md/jsdoc-to-markdown) tool). This means that anytime an API
53+
changes (new methods or changes to existing methods) you must run the above command to output
54+
changes and commit those changes in git.
4555

4656
### Releasing
4757

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ coverage
44
.nyc_output
55
*.lcov
66
*.log
7+
package-lock.json
8+
.env

README.md

Lines changed: 285 additions & 148 deletions
Large diffs are not rendered by default.

docs/reference.md

Lines changed: 290 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Required
2+
SLACK_VERIFICATION_TOKEN=
3+
SLACK_ACCESS_TOKEN=
4+
5+
# Optional
6+
PORT=
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/carbon
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Express All Interacttions Example
2+
3+
This example shows a fully functioning app using the
4+
[Slack Interactive Messages](https://github.com/slackapi/node-slack-interactive-messages) package.
5+
6+
## Setup
7+
8+
### Create a Slack app
9+
10+
1. Create an app at <https://api.slack.com/apps> (don't close this window, you'll need it later).
11+
12+
### Run the code
13+
14+
1. Choose where you want to run:
15+
* Either clone this repo, navigate to this directory, and run `npm install`
16+
* Or, <a href="https://glitch.com/edit/#!/remix/slack-express-all-interactions-example"><img src="https://cdn.glitch.com/2bdfb3f8-05ef-4035-a06e-2043962a3a13%2Fremix%402x.png?1513093958726" alt="remix button" aria-label="remix" height="33"></a>
17+
18+
2. Set the following environment variables
19+
* `SLACK_VERIFICATION_TOKEN`: Available on your app's _Basic Information_ page in Slack.
20+
* `SLACK_ACCESS_TOKEN`: Available on your app's _Install App_ page in Slack (after installing on your Development Workspace).
21+
* `PORT`: _ONLY_ if you are running locally
22+
23+
3. _ONLY_ If you're running the app locally:
24+
* Make sure you're on a supported version of node (see `.nvmrc` or if you have nvm run `nvm use`)
25+
* Start the app (`npm start`)
26+
* In another terminal window, start ngrok on the same port as the webserver (`ngrok http $PORT`)
27+
28+
### Enable Interactive Components
29+
30+
1. Open your app's _Interactive Components_ page in Slack.
31+
2. Enable interactive components and enter the Request URL and Options URL (use the same URL for both)
32+
* ngrok URL or Glitch URL + '/slack/actions'
33+
34+
### Create a Slash Command
35+
36+
1. Open your app's _Slash Commands_ page in Slack.
37+
2. Click "Create New Command"
38+
* In command use: `/interactive-example`
39+
* In request URL use: ngrok URL or Glitch URL + `/slack/commands`
40+
* Click Save
41+
3. On the _Install App_ page, reinstall in your Development Workspace.
42+
43+
## Usage
44+
45+
The slash command can be triggered in three ways:
46+
* `/interactive-example button`: Creates a message with message butons. When you click one, the message updates.
47+
* `/interactive-example menu`: Creates a message with a dynamic menu. When you begin typing, the options are narrowed down. Selecting an option updates the message.
48+
* `/interactive-exmaple dialog`: Creates a dialog with a user menu input and text input. Sends a confirmation message after submission.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const axios = require('axios');
2+
3+
// Create a Promise that resolves after a full turn of the event loop
4+
// Used since Promise.resolve() will resolve too early
5+
function resolveLater(value, ms = 0) {
6+
return new Promise((resolve) => setTimeout(() => resolve(value), ms));
7+
}
8+
9+
// A fake users model that resembles what you might have for a database-backed application
10+
exports.users = {
11+
staticUser: {
12+
agreedToPolicy: false,
13+
setPolicyAgreementAndSave(isAgreed) {
14+
this.agreedToPolicy = isAgreed;
15+
return resolveLater(this);
16+
},
17+
kudosCount: 0,
18+
incrementKudosAndSave(reason) {
19+
this.kudosCount += 1;
20+
return resolveLater(this);
21+
}
22+
},
23+
findBySlackId() {
24+
return resolveLater(this.staticUser, 50);
25+
}
26+
}
27+
28+
exports.neighborhoods = {
29+
apiUrl: 'https://data.sfgov.org/resource/6ia5-2f8k.json',
30+
fuzzyFind(text) {
31+
return axios({
32+
url: this.apiUrl,
33+
params: {
34+
'$query': `SELECT name WHERE lower(name) LIKE '%${text.toLowerCase()}%'`,
35+
},
36+
}).then(response => response.data);
37+
},
38+
find(name) {
39+
return axios({
40+
url: this.apiUrl,
41+
params: {
42+
'name': name,
43+
},
44+
})
45+
.then((response) => {
46+
const result = response.data[0];
47+
if (!result.link) {
48+
result.link = `http://www.google.com/search?q=${encodeURIComponent(result.name)}`;
49+
}
50+
return result;
51+
});
52+
}
53+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "express-all-interactions",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "An example of using Slack Interactive Messages for Node",
6+
"main": "index.js",
7+
"scripts": {
8+
"start": "node -r dotenv/config server",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": "Ankur Oberoi <[email protected]>",
12+
"license": "MIT",
13+
"dependencies": {
14+
"@slack/client": "^4.1.0",
15+
"@slack/interactive-messages": "*",
16+
"axios": "^0.18.0",
17+
"body-parser": "^1.18.2",
18+
"dotenv": "^5.0.1",
19+
"express": "^4.16.3"
20+
}
21+
}

0 commit comments

Comments
 (0)