Skip to content

Commit 1764762

Browse files
committed
pre-hactober preptember work
1 parent 150627b commit 1764762

File tree

6 files changed

+74
-36
lines changed

6 files changed

+74
-36
lines changed

README.md

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ to login to the new workspace, make sure you go ahead and do that.
8080
If you're having a hard time figuring this out, try checking out the following
8181
Slack article [Create a Slack Workspace](https://slack.com/intl/en-ca/help/articles/206845317-Create-a-Slack-workspace).
8282

83+
#### Create expected channels
84+
Several of Pybot's features involve sending messages to specific channels - in order
85+
for this to work in your personal Slack workspace you'll need to create the following channels:
86+
- mentors-internal
87+
- greetings
88+
- moderators
89+
- oc-tech
90+
91+
8392
### 2 - Create a pybot App in Your Slack Workspace
8493

8594
The next step is to create a new bot application in your workspace. While still
@@ -91,6 +100,14 @@ following this, follow the guidelines for creating a bot app as laid out in the
91100
you get to the stage of creating the bot user, make sure to write down the bot
92101
user OAuth access token that is presented, as you'll need to use it later.
93102

103+
On the `OAuth & Permissions` page configure the Pybot app with the following scopes
104+
105+
- channels:manage
106+
- chat:write
107+
- chat:write.public
108+
- commands
109+
- users:read
110+
94111
### 3 - Launch pybot Locally, Passing in Your Signing Secret
95112

96113
With your Slack workspace, app and bot user created, and your app signing secret
@@ -108,7 +125,7 @@ Here's an example of configuring these through the _pybot.env_ file:
108125

109126
```bash
110127
SLACK_BOT_SIGNING_SECRET=APP-SIGNING-SECRET
111-
BOT_OATH_TOKEN=BOT-USER-OAUTH-TOKEN
128+
BOT_USER_OAUTH_ACCESS_TOKEN=BOT-USER-OAUTH-TOKEN
112129
```
113130

114131
**NOTE**: More configuration settings than these may be specified. Please see
@@ -118,24 +135,34 @@ for details on other settings that can be set.
118135
### 4 - Attach Your pybot Instance to the Public Internet
119136

120137
With an instance of pybot running, you now need to expose this instance to the
121-
public internet so Slack can send in API requests. You can easily utilize serveo
122-
for this purpose if you wish. To do so; run the following command from your UNIX
123-
like workstation to setup an SSH port tunnel to serveo:
138+
public internet so Slack can send in API requests. You can easily utilize ngrok
139+
for this purpose if you wish. To do so; download ngrok from https://ngrok.com/download
140+
and set up a tunnel like so:
124141

125142
```bash
126-
ssh -R 80:localhost:5000 serveo.net
143+
ngrok http 5000
127144
```
128145

129146
Pay attention to copy out the response you get and keep this command running.
130147
Here's an example output from the command:
131148

132-
```text
133-
Forwarding HTTP traffic from https://supersecret.serveo.net
134-
Press g to start a GUI session and ctrl-c to quit.
149+
```bash
150+
ngrok by @inconshreveable (Ctrl+C to quit)
151+
Session Status online
152+
Session Expires 7 hours, 56 minutes
153+
Version 2.3.35
154+
Region United States (us)
155+
Web Interface http://127.0.0.1:4040
156+
Forwarding http://9d73595a7aac.ngrok.io -> http://localhost:5000
157+
Forwarding https://9d73595a7aac.ngrok.io -> http://localhost:5000
158+
Connections ttl opn rt1 rt5 p50 p90
159+
0 1 0.00 0.00 0.00 0.00
160+
HTTP Requests
135161
```
136162

137-
With this done, serveo will now expose the instance of pybot running locally
138-
on port 5000 on port 443 via the Base-URI it returns.
163+
With this done, ngrok will now expose the instance of pybot running locally
164+
on port 5000 via the "Forwarding" address it returns. Be sure to use the URL
165+
beginning with http**s**.
139166

140167
### 5 - Point Slack at Your Running pybot Instance
141168

@@ -166,7 +193,7 @@ subscriptions. When configuring your events URI; make sure you pass in the
166193
Base-URI that pybot is listening on followed by the text _/slack/events_. For
167194
example:
168195

169-
https://supersecret.serveo.net/slack/events
196+
https://123_random_code_321.ngrok.io/slack/events
170197

171198
#### Slash Commands
172199

@@ -176,7 +203,7 @@ page on Slack to setup pybot slash commands. When configuring a Slash command,
176203
make sure you configure the request URL to match the Base-URI that pybot is
177204
listening on followed by the text _/slack/commands_. For example:
178205

179-
https://supersecret.serveo.net/slack/commands
206+
https://123_random_code_321.ngrok.io/slack/commands
180207

181208
You'll use the same URI for each command. Here's a table listing of currently
182209
supported commands along with some suggested configuration text:
@@ -191,6 +218,16 @@ Command | Description | Usage Hint
191218
/roll | roll x dice with y sides | <XdY>
192219
/ticket | submit ticket to admins | (text of ticket)
193220

221+
222+
**👋 IMPORTANT!**
223+
224+
The `/lunch` command requires a valid Yelp API token stored in the `YELP_TOKEN`
225+
environment variable. See https://www.yelp.com/developers/faq
226+
227+
Similarly, the `/mentor` and `/mentor-volunteer` commands require access to an Airtable
228+
environment with a specific configuration. If you're planning on working with the mentor
229+
functionality please reach out to the `#oc-python-projects` channel for help getting set up.
230+
194231
#### Interactive Components
195232

196233
You can follow the instructions (and read helpful related information) on the
@@ -199,7 +236,7 @@ page on Slack to setup Slack interactive component configuration. When
199236
configuring the request URL, you'll want to set it to the Base-URI that pybot
200237
is listening on followed by the text _/slack/actions_. For example:
201238

202-
https://supersecret.serveo.net/slack/actions
239+
https://123_random_code_321.ngrok.io/slack/actions
203240

204241
You'll also want to make sure to configure the report message action with the
205242
following parameters:
@@ -218,8 +255,7 @@ list with more details via a PR:
218255
Name | Description | Example
219256
---- | ----------- | -------
220257
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
221-
BOT_OATH_TOKEN | The bot user specific OAuth token used to authenticate the bot when making API requests to Slack | xoxb-800506043194-810119867738-vRvgSc3rslDUgQakFbMy3wAt
222-
MENTOR_CHANNEL | Slack unique identifier (not the same as the channel name) for a workspace channel that mentors should be added to | G1DRT62UC
258+
BOT_USER_OAUTH_ACCESS_TOKEN | The bot user specific OAuth token used to authenticate the bot when making API requests to Slack | xoxb-800506043194-810119867738-vRvgSc3rslDUgQakFbMy3wAt
223259

224260
## License
225261
This package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

docker/example.env

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
# --------------------------- #
22
### pybot.env ###
33

4-
# BOT_OAUTH_TOKEN=<Bot User OAuth Access Token>
54
# SLACK_BOT_SIGNING_SECRET=<Client Secret>
6-
# VERIFICATION_TOKEN=<Verification Token>
7-
# SLACK_BOT_ID=<Not necessary in many cases, see the below warning>
8-
9-
##~~ "`SLACK_BOT_USER_ID` not set. It is required for `on mention` routing and discarding "
10-
##~~ "message coming from Sir Bot-a-lot to avoid loops."
5+
# BOT_USER_OAUTH_ACCESS_TOKEN=<Bot User OAuth Access Token>
116

127

138
#~~ These are only needed if you want to override the default channel names ~~#

pybot/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
bot.load_plugin(slack)
4343

4444
admin_configs = dict(**slack_configs)
45-
admin_token = os.environ.get("APP_ADMIN_OAUTH_TOKEN")
45+
admin_token = os.environ.get("APP_ADMIN_OAUTH_TOKEN", "FAKE_ADMIN_TOKEN")
4646
if admin_token:
4747
admin_configs["token"] = admin_token
4848
admin_slack = SlackPlugin(**admin_configs)

pybot/endpoints/slack/actions/mentor_request.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def mentor_details_submit(action: Action, app: SirBot):
4545
ts = state["ts"]
4646
search = {"inclusive": True, "channel": channel, "oldest": ts, "latest": ts}
4747

48-
history = await slack.query(methods.IM_HISTORY, search)
48+
history = await slack.query(methods.CONVERSATIONS_HISTORY, search)
4949
request["message"] = history["messages"][0]
5050
request.details = action["submission"]["details"]
5151

@@ -56,7 +56,10 @@ async def open_details_dialog(action: Action, app: SirBot):
5656
request = MentorRequest(action)
5757
cur_details = request.details
5858
trigger_id = action["trigger_id"]
59-
response = {"trigger_id": trigger_id, "dialog": mentor_details_dialog(action, cur_details)}
59+
response = {
60+
"trigger_id": trigger_id,
61+
"dialog": mentor_details_dialog(action, cur_details),
62+
}
6063
await app.plugins["slack"].api.query(methods.DIALOG_OPEN, response)
6164

6265

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import os
22

3-
MENTOR_CHANNEL = os.environ.get("MENTOR_CHANNEL") or "mentors-internal"
4-
COMMUNITY_CHANNEL = os.environ.get("COMMUNITY_CHANNEL") or "greetings"
5-
MODERATOR_CHANNEL = os.environ.get("MODERATOR_CHANNEL") or "moderators"
6-
TICKET_CHANNEL = os.environ.get("TICKET_CHANNEL") or "oc-project-leads"
7-
YELP_TOKEN = os.environ.get("YELP_TOKEN") or "token"
3+
BOT_USER_OAUTH_ACCESS_TOKEN = os.environ.get("BOT_USER_OAUTH_ACCESS_TOKEN")
4+
BOT_OAUTH_TOKEN = os.environ.get("BOT_OAUTH_TOKEN")
5+
BOT_OATH_TOKEN = os.environ.get("BOT_OATH_TOKEN")
6+
MENTOR_CHANNEL = os.environ.get("MENTOR_CHANNEL", "mentors-internal")
7+
COMMUNITY_CHANNEL = os.environ.get("COMMUNITY_CHANNEL", "greetings")
8+
MODERATOR_CHANNEL = os.environ.get("MODERATOR_CHANNEL", "moderators")
9+
TICKET_CHANNEL = os.environ.get("TICKET_CHANNEL", "oc-tech")
10+
SLACK_BOT_USER_ID = os.environ.get("SLACK_BOT_USER_ID", "ABC123")
11+
SLACK_BOT_ID = os.environ.get("SLACK_BOT_ID", "ABC123")
12+
YELP_TOKEN = os.environ.get("YELP_TOKEN", "token")
813
PORT = os.environ.get("SIRBOT_PORT", 5000)
914
HOST = os.environ.get("SIRBOT_ADDR", "0.0.0.0")
1015
PYBOT_ENV = os.environ.get("PYBOT_ENV", "dev")
@@ -15,12 +20,11 @@
1520
BOT_URL = "https://github.com/OperationCode/operationcode-pybot"
1621

1722
slack_configs = {
18-
"token": os.environ.get(
19-
"BOT_OAUTH_TOKEN",
20-
os.environ.get('BOT_OATH_TOKEN') # fallback using old typo value
21-
),
23+
"token": BOT_USER_OAUTH_ACCESS_TOKEN
24+
or BOT_OAUTH_TOKEN
25+
or BOT_OATH_TOKEN, # fallback for old values
2226
"signing_secret": os.environ.get("SLACK_BOT_SIGNING_SECRET"),
2327
"verify": os.environ.get("VERIFICATION_TOKEN"),
24-
"bot_id": os.environ.get("SLACK_BOT_ID"),
25-
"bot_user_id": os.environ.get("SLACK_BOT_USER_ID"),
28+
"bot_id": SLACK_BOT_ID,
29+
"bot_user_id": SLACK_BOT_USER_ID,
2630
}

pybot/endpoints/slack/utils/action_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def mentor_details_dialog(action, cur_details):
269269
"name": "details",
270270
"placeholder": "",
271271
"required": False,
272-
"value": cur_details
272+
"value": cur_details,
273273
}
274274
],
275275
}

0 commit comments

Comments
 (0)