|
1 | | -<div align="center"> |
2 | | - <br /> |
3 | | - <a href="https://operationcode.org"> |
4 | | - <img |
5 | | - alt="Operation Code Hacktoberfest Banner" |
6 | | - src="https://operation-code-assets.s3.us-east-2.amazonaws.com/operation_code_hacktoberfest_2019.jpg" |
7 | | - > |
8 | | - </a> |
9 | | - <br /> |
10 | | - <br /> |
11 | | -</div> |
12 | | - |
13 | | -# 🎃 Hacktoberfest 🎃 |
14 | | - |
15 | | -[All the details you need](https://github.com/OperationCode/START_HERE/blob/master/README.md#-hacktoberfest-) before participating with us. |
16 | | - |
17 | | -<br /> |
18 | | - |
19 | 1 | [](https://opensource.org/licenses/MIT) |
20 | 2 | [](https://twitter.com/operation_code) |
21 | 3 | [](https://github.com/ambv/black) |
@@ -69,6 +51,176 @@ poetry run flake8 |
69 | 51 | poetry run isort -rc . |
70 | 52 | ``` |
71 | 53 |
|
| 54 | +## How to Test Integration With Slack |
| 55 | + |
| 56 | +After having developed some new feature, or having in hand what you believe is |
| 57 | +a fix for an existing bug, how do you test it out in a real system in order to |
| 58 | +make sure that your changes do all that you hope they do? The answer; bring up |
| 59 | +the application in your own environment and hook it up to Slack! |
| 60 | + |
| 61 | +In order to do this, you'll want to tackle the following items in order: |
| 62 | + |
| 63 | +1. Setup your own Slack workspace. |
| 64 | +2. Grab a signing secret from Slack that pybot can utilize. |
| 65 | +3. Launch pybot locally, passing it your Slack signing secret. |
| 66 | +4. Attach your pybot instance to the public internet so that Slack can speak |
| 67 | + with it. |
| 68 | +5. Point Slack at your running pybot instance, and properly configure it. |
| 69 | + |
| 70 | +The following sections will guide you through each of these stages. |
| 71 | + |
| 72 | +### 1 - Setup Your Own Slack Workspace |
| 73 | + |
| 74 | +To start, you'll want to visit Slack's [Getting |
| 75 | +Started](https://slack.com/get-started) page. From this page, follow the steps |
| 76 | +required to create a new workspace. The names/options you configure during |
| 77 | +creation don't matter so much, but make sure you associate it with an email |
| 78 | +address you have access to. Once complete it should present you with an option |
| 79 | +to login to the new workspace, make sure you go ahead and do that. |
| 80 | + |
| 81 | +If you're having a hard time figuring this out, try checking out the following |
| 82 | +Slack article [Create a Slack Workspace](https://slack.com/intl/en-ca/help/articles/206845317-Create-a-Slack-workspace). |
| 83 | + |
| 84 | +### 2 - Create a pybot App in Your Slack Workspace |
| 85 | + |
| 86 | +The next step is to create a new bot application in your workspace. While still |
| 87 | +logged in, visit the [App Management](https://api.slack.com/apps) page and |
| 88 | +choose to create a new app. During this process, make sure to copy down the |
| 89 | +signing secret key that gets generated for your app, as you'll need it later, |
| 90 | +following this, follow the guidelines for creating a bot app as laid out in the |
| 91 | +[Enabling interactions with bots](https://api.slack.com/bot-users) article. When |
| 92 | +you get to the stage of creating the bot user, make sure to write down the bot |
| 93 | +user OAuth access token that is presented, as you'll need to use it later. |
| 94 | + |
| 95 | +### 3 - Launch pybot Locally, Passing in Your Signing Secret |
| 96 | + |
| 97 | +With your Slack workspace, app and bot user created, and your app signing secret |
| 98 | +and bot user OAuth access token in hand, you should now be ready to configure |
| 99 | +pybot to integrate with your new Slack workspace. To do this, you'll first want |
| 100 | +to setup the proper configuration in pybot. |
| 101 | + |
| 102 | +pybot configuration is specified completely through environment variables. When |
| 103 | +running locally, you can configure the _./docker/pybot.env_ file with the |
| 104 | +environment variable name/value pairings, which will get evaluated on |
| 105 | +application start. Otherwise, make sure to export or pass in the correct |
| 106 | +environment variables through your shell when launching pybot. |
| 107 | + |
| 108 | +Here's an example of configuring these through the _pybot.env_ file: |
| 109 | + |
| 110 | +```bash |
| 111 | +SLACK_BOT_SIGNING_SECRET=APP-SIGNING-SECRET |
| 112 | +BOT_OATH_TOKEN=BOT-USER-OAUTH-TOKEN |
| 113 | +``` |
| 114 | + |
| 115 | +**NOTE**: More configuration settings than these may be specified. Please see |
| 116 | +the _Known Configuration Settings_ section near the bottom of this document |
| 117 | +for details on other settings that can be set. |
| 118 | + |
| 119 | +### 4 - Attach Your pybot Instance to the Public Internet |
| 120 | + |
| 121 | +With an instance of pybot running, you now need to expose this instance to the |
| 122 | +public internet so Slack can send in API requests. You can easily utilize serveo |
| 123 | +for this purpose if you wish. To do so; run the following command from your UNIX |
| 124 | +like workstation to setup an SSH port tunnel to serveo: |
| 125 | + |
| 126 | +```bash |
| 127 | +ssh -R 80:localhost:5000 serveo.net |
| 128 | +``` |
| 129 | + |
| 130 | +Pay attention to copy out the response you get and keep this command running. |
| 131 | +Here's an example output from the command: |
| 132 | + |
| 133 | +```text |
| 134 | +Forwarding HTTP traffic from https://supersecret.serveo.net |
| 135 | +Press g to start a GUI session and ctrl-c to quit. |
| 136 | +``` |
| 137 | + |
| 138 | +With this done, serveo will now expose the instance of pybot running locally |
| 139 | +on port 5000 on port 443 via the Base-URI it returns. |
| 140 | + |
| 141 | +### 5 - Point Slack at Your Running pybot Instance |
| 142 | + |
| 143 | +With the initial Slack configuration complete and your instance of pybot |
| 144 | +running on the public internet, it is now the perfect time to fully configure |
| 145 | +Slack to interact with your bot. Depending on the interactions you're wanting to |
| 146 | +play with, there are various configurations you can specify, which can be |
| 147 | +broken down into the following parts: |
| 148 | + |
| 149 | +* Event Subscriptions - this allows pybot to respond to various events that may |
| 150 | + occur in your Slack workspace. |
| 151 | +* Slash Commands - this allows a user to invoke various commands from any |
| 152 | + channel in your workspace to interact with pybot. |
| 153 | +* Interactive Components - this allows various options to be exposed when |
| 154 | + right clicking on a message, or, when the bot presents various user |
| 155 | + elements that can be interacted with, instructs Slack on where to send the |
| 156 | + results for such interactions. |
| 157 | + |
| 158 | +High level steps for configuring each of these can be found in the following |
| 159 | +sub-sections; note that you don't need to necessarily configure all of these, |
| 160 | +it all depends on what areas of pybot you're wanting to play with. |
| 161 | + |
| 162 | +#### Event Subscriptions |
| 163 | + |
| 164 | +You can follow the instructions (and read helpful related information) on the |
| 165 | +[Events API](https://api.slack.com/events-api) page on Slack to setup event |
| 166 | +subscriptions. When configuring your events URI; make sure you pass in the |
| 167 | +Base-URI that pybot is listening on followed by the text _/slack/events_. For |
| 168 | +example: |
| 169 | + |
| 170 | + https://supersecret.serveo.net/slack/events |
| 171 | + |
| 172 | +#### Slash Commands |
| 173 | + |
| 174 | +You can follow the instructions (and read helpful relation information) on the |
| 175 | +[Enabling interactivity with Slash Commands](https://api.slack.com/interactivity/slash-commands) |
| 176 | +page on Slack to setup pybot slash commands. When configuring a Slash command, |
| 177 | +make sure you configure the request URL to match the Base-URI that pybot is |
| 178 | +listening on followed by the text _/slack/commands_. For example: |
| 179 | + |
| 180 | + https://supersecret.serveo.net/slack/commands |
| 181 | + |
| 182 | +You'll use the same URI for each command. Here's a table listing of currently |
| 183 | +supported commands along with some suggested configuration text: |
| 184 | + |
| 185 | +Command | Description | Usage Hint |
| 186 | +------- | ----------- | ---------- |
| 187 | +/lunch | find lunch suggestions nearby | <zip code> <distance in miles> |
| 188 | +/mentor | request mentoring | |
| 189 | +/mentor-volunteer | offer to mentor others | |
| 190 | +/repeat | parrot canned messages | <10000|ask|ldap|merge|firstpr|channels|resources> |
| 191 | +/report | report something to the admins | <text of message> |
| 192 | +/roll | roll x dice with y sides | <XdY> |
| 193 | +/ticket | submit ticket to admins | (text of ticket) |
| 194 | + |
| 195 | +#### Interactive Components |
| 196 | + |
| 197 | +You can follow the instructions (and read helpful related information) on the |
| 198 | +[Handling user interaction in your Slack apps](https://api.slack.com/interactivity/handling) |
| 199 | +page on Slack to setup Slack interactive component configuration. When |
| 200 | +configuring the request URL, you'll want to set it to the Base-URI that pybot |
| 201 | +is listening on followed by the text _/slack/actions_. For example: |
| 202 | + |
| 203 | + https://supersecret.serveo.net/slack/actions |
| 204 | + |
| 205 | +You'll also want to make sure to configure the report message action with the |
| 206 | +following parameters: |
| 207 | + |
| 208 | +Name | Description | Callback ID |
| 209 | +---- | ----------- | ----------- |
| 210 | +Report Message | Report this message to admins | report_message |
| 211 | + |
| 212 | +## Known Configuration Settings |
| 213 | + |
| 214 | +This application has a number of environment variables that can be set when |
| 215 | +launching to alter the behaviour of the application. The list below is an |
| 216 | +incomplete description of a number of them. Please feel free to update this |
| 217 | +list with more details via a PR: |
| 218 | + |
| 219 | +Name | Description | Example |
| 220 | +---- | ----------- | ------- |
| 221 | +SLACK_BOT_SIGNING_SECRET | The unique signing secret used by Slack for a specific app that will be validated by pybot when inspecting an inbound API request | f3b4d774b79e0fb55af624c3f376d5b4 |
| 222 | +BOT_OATH_TOKEN | The bot user specific OAuth token used to authenticate the bot when making API requests to Slack | xoxb-800506043194-810119867738-vRvgSc3rslDUgQakFbMy3wAt |
| 223 | +MENTOR_CHANNEL | Slack unique identifier (not the same as the channel name) for a workspace channel that mentors should be added to | G1DRT62UC |
72 | 224 |
|
73 | 225 | ## License |
74 | 226 | This package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). |
0 commit comments