You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 24, 2019. It is now read-only.
This adapter enhances and simplifies Slack's Events API by incorporating useful best practices,
7
-
patterns, and opportunities to abstract out common tasks.
6
+
Build your Slack apps by reacting to messages, emojis, files, and many more types of interesting
7
+
events in the [Events API](https://api.slack.com/events-api). This package will help you start
8
+
with sensible and secure defaults.
8
9
9
-
We wrote a blog that [explains how](https://medium.com/@SlackAPI/enhancing-slacks-events-api-7535827829ab)
10
-
the Events API can help you, why we built these tools, and how you can use them to build
11
-
production-ready Slack apps.
10
+
The adapter gives you a simple and highly configurable Node-style [EventEmitter](https://nodejs.org/dist/latest/docs/api/events.html#events_class_eventemitter) to attach functions
Get started by [creating a Slack App](https://api.slack.com/apps/new) if you haven't already.
31
+
On the **Basic Information** page, in the section for **App Credentials**, note the
32
+
**Signing Secret**. You will need it to initialize the adapter.
33
+
34
+
> ⚠️ As of `v2.0.0`, the Events API adapter no longer accepts legacy verification tokens.
35
+
You must pass a signing secret [to verify requests from Slack](https://api.slack.com/docs/verifying-requests-from-slack).
36
+
37
+
Select the **Event Subscriptions** feature, and enable it. Input a **Request URL**.
38
+
39
+

40
+
41
+
<details>
42
+
<summary><strong>What's a request URL? How can I get one for development?</strong></summary>
43
+
44
+
Slack will send requests to your app server each time an event from a subscription is triggered.
45
+
In order to reach your server, you have to tell Slack where your app is listening for those
46
+
requests. This location is the request URL.
24
47
25
-
In order to complete the subscription, you will need a **Request URL** that can already respond to a
26
-
verification request. This module, combined with the use of a development proxy, can make this
27
-
easier for you.
48
+
If you're just getting started with development, you may not have a publicly accessible URL for
49
+
your app. We recommend using a development proxy, such as [ngrok](https://ngrok.com/) or
50
+
[localtunnel](https://localtunnel.github.io/www/), to generate a URL that can forward requests to
51
+
your local machine. Once you've installed the development proxy of your choice, run it to begin
52
+
forwarding requests to a specific port (for example, 3000).
28
53
29
-
0. Force the generation of a Signing Secret: If you just created your Slack App, the Basic
30
-
Information section of your configuration will not yet have a Signing Secret under App
31
-
Credentials. By visiting the Event Subscriptions section and putting a dummy URL into Request
32
-
URL, you will get a verification failure, but also there will now be a **Signing Secret**
33
-
available in the Basic Information section.
54
+
> ngrok: `ngrok http 3000`
34
55
35
-
> ⚠️ As of `v2.0.0`, the Events API adapter no longer accepts legacy verification tokens. You must pass a signing secret [to verify requests from Slack](https://api.slack.com/docs/verifying-requests-from-slack).
56
+
> localtunnel: `lt --port 3000`
36
57
37
-
1. Start the verification tool:
38
-
`./node_modules/.bin/slack-verify --token <signing-secret> [--path=/slack/events] [--port=3000]`. You will
39
-
need to substitute your own Verification Token for `<signing-secret>`. You may also want to choose your own
40
-
`path` and/or `port`.
58
+

41
59
42
-
2. Start your development proxy. We recommend using [ngrok](https://ngrok.com/) for its stability,
43
-
but using a custom subdomain will require a paid plan. Otherwise,
44
-
[localtunnel](https://localtunnel.github.io/www/) is an alternative that gives you custom subdomains
45
-
for free.
60
+
The output should show you a newly generated URL that you can use (ngrok will actually show you two
61
+
and we recommend the one that begins with "https"). Let's call this the base URL (for example,
62
+
`https://e0e88971.ngrok.io`)
46
63
47
-
> With ngrok: `ngrok http -subdomain=<projectname> 3000`
64
+
To create the request URL, we add the path where our app listens for events onto the end of
65
+
the base URL. If you are using the built-in HTTP server it is set to `/slack/events`. In this
66
+
example the request URL would be `https://e0e88971.ngrok.io/slack/events`. If you are using the
67
+
Express middlware, you can set whichever path you like, just remember to make the path you mount the
68
+
middleware into the application the same as the one you configure in Slack.
69
+
</details>
48
70
49
-
> With localtunnel: `lt --port 3000 --subdomain <projectname>`
71
+
<br/>
50
72
51
-
3. Input your Request URL into the Slack App configuration settings, in the Event Subscriptions
52
-
section. This URL depends on how you used the previous two commands. For example, using the
53
-
default path and the subdomain name "mybot":
73
+
<details>
74
+
<summary><strong>I'm getting an error about the `challenge` parameter. Help?</strong></summary>
54
75
55
-
> With ngrok: `https://mybot.ngrok.io/slack/events`
76
+
Before you can save the subscription, your app will need to respond to a challenge at your chosen
77
+
request URL. I know what you're thinking: 🤔 _How can I respond if I haven't written my app yet?_
78
+
This package comes with a command line tool which starts a server that can properly respond to the
79
+
challenge. If you're using the development proxy as described above, you can run the tool from
80
+
inside your project directory (after this package has been installed) with the following command:
56
81
57
-
> With localtunnel: `https://mybot.localtunnel.me/slack/events`
> ⚠️ As of `v2.0.0`, the Events API adapter parses raw request bodies while performing request signing verification. This means developers no longer need to use `body-parser` middleware to parse JSON-encoded requests.
170
+
> ⚠️ As of `v2.0.0`, the Events API adapter parses raw request bodies while performing request signing verification. This means apps no longer need to use `body-parser` middleware to parse JSON-encoded requests.
129
171
130
172
**NOTE**: To use the example above, you need to add a Team Event such as `message.im` in the Event
131
173
Subscriptions section of your Slack App configuration settings.
132
174
133
-
## Documentation
175
+
## Examples
176
+
177
+
*[Greet And React](examples/greet-and-react) - A ready to run sample app that listens for messages and
178
+
emoji reactions, and responds to them. It is built on top of the [Express](https://expressjs.com) web framework. It also implements [OAuth](https://api.slack.com/docs/oauth) to demonstate how an app can handle
179
+
installation to additional workspaces and be structured to handle events from multiple workspaces.
180
+
181
+
## Reference Documentation
134
182
135
183
To learn more, see the [reference documentation](docs/reference.md).
136
184
137
185
## Support
138
186
139
-
Need help? Join the [Bot Developer Hangout](http://dev4slack.xoxco.com/) team and talk to us in
187
+
Need help? Join the [Bot Developer Hangout](https://community.botkit.ai) team and talk to us in
0 commit comments