Skip to content

Commit 25e78a0

Browse files
committed
Update ENV sample and generalise env variable names (#50)
1 parent 7d8f8f6 commit 25e78a0

File tree

5 files changed

+62
-16
lines changed

5 files changed

+62
-16
lines changed

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ Get Daily Puzzles delivered to your preferred server channel with a "Is it Ruby
1919
```
2020
Check the .env.sample file for information on what environment variables you will need.
2121

22-
# Run the server and bot
23-
24-
Running the server (this is not necessary to run the bot):
25-
`bundle exec rails server`
26-
-or-
27-
`bundle exec rails s`
22+
# Run the Discord bot
2823

2924
Registering and re-registering the bot commands:
3025
`bundle exec rake discord:reset_commands`
@@ -37,3 +32,41 @@ Be aware that it is possible to start the bot multiple times at once, and this c
3732
This application is using `sidekiq` to run jobs.
3833
Running sidekiq:
3934
`bundle exec sidekiq -c 2 -q default`
35+
36+
# Optional Functionality
37+
38+
The Discord bot can run without the admin panel or Slackbot, those are optional features included with the project.
39+
40+
## Admin Panel
41+
42+
The admin panel allows you to manage puzzles and is set up with Google OAuth for authentication by default.
43+
44+
To run the admin panel with google, you'll need to create a google oauth client to get the client ID and secret.
45+
46+
Go to [Google Cloud Console](https://console.cloud.google.com/apis/credentials) and create a new OAuth 2.0 client ID.
47+
Set the redirect URI to `http://localhost:3000/auth/google_oauth2/callback` for local development.
48+
Copy the client ID and secret to your `.env` file as `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`.
49+
50+
Run the Rails server:
51+
52+
`bundle exec rails server`
53+
-or-
54+
`bundle exec rails s`
55+
56+
## Slackbot
57+
58+
The Slackbot supports a slash command to suggest new puzzles and notifications when running low on puzzles (less then 5 approved puzzles).
59+
60+
To set up the Slackbot, you'll need to create a Slack app:
61+
62+
1. Go to [Slack API](https://api.slack.com/apps) and create a new app.
63+
2. Add a slash command (e.g., `/suggest_puzzle`) and set the endpoint of the request URL to `/slack/new_puzzle`.
64+
3. Configure `Interactivity & Shortcuts` to point to the `/slack/puzzle` endpoint.
65+
4. Install the Slack app to your workspace and add the bot token and secret to the `.env` file as `SLACK_TOKEN` and `SLACK_SIGNING_SECRET`.
66+
5. To use the notifications feature, also set the `SLACK_NOTIFICATIONS_CHANNEL` in the `.env` file with the channel ID where you want to receive notifications.
67+
6. Optionally, you can also tag a specific Slack user group in the notification, just set the `SLACK_GROUP_ID` in the `.env` file with the group ID.
68+
69+
Slack sends POST requests to the specified URLs, for local development, you can use a tool like [ngrok](https://ngrok.com/) to expose your local server to the internet.
70+
Use the ngrok URL as the request URL for the slash command and interactivity in your Slack app settings.
71+
72+
The Slackbot will be ready to use once you have set up the Slack app and configured the environment variables. Make sure the Rails server is running.

app/controllers/sessions_controller.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ def create
33
auth = request.env["omniauth.auth"]
44
user_email = auth.info.email
55

6-
unless user_email.end_with?("@ombulabs.com")
7-
reset_session
8-
flash[:error] = "Access denied. Please access with your @ombulabs.com email address."
9-
redirect_to root_path
10-
return
6+
domain_allowlist = ENV.fetch("DOMAIN_ALLOWLIST").split(",").map(&:strip)
7+
if domain_allowlist.present?
8+
unless domain_allowlist.any? { |domain| user_email.end_with?("@#{domain}") }
9+
reset_session
10+
flash[:error] = "Access denied. Please access with a valid email address."
11+
redirect_to root_path
12+
return
13+
end
1114
end
1215

1316
session[:user_token] = auth.credentials.token

app/controllers/slack/puzzles_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def create
1212
if puzzle.save
1313
view = SlackClient::Views::Success.new.create
1414
notification_message = SlackClient::Messages::NewPuzzleNotification.new(puzzle).create
15-
send_message(notification_message, channel_id: ENV.fetch("SHIELD_NOTIFICATIONS_CHANNEL", nil))
15+
send_message(notification_message, channel_id: ENV.fetch("SLACK_NOTIFICATIONS_CHANNEL", nil))
1616
else
1717
view = SlackClient::Views::Failure.new.create
1818
end

app/lib/slack_client/messages/new_puzzle_notification.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module SlackClient
22
module Messages
33
class NewPuzzleNotification
4-
def initialize(puzzle, shield_group_id: ENV["SHIELD_GROUP_ID"])
4+
def initialize(puzzle, slack_group_id: ENV["SLACK_GROUP_ID"])
55
@puzzle = puzzle
6-
@shield_group_id = shield_group_id
6+
@slack_group_id = slack_group_id
77
end
88

99
def create
@@ -21,7 +21,7 @@ def create
2121

2222
def body_text
2323
<<~TEXT
24-
Hey <!subteam^#{@shield_group_id}>!
24+
Hey <!subteam^#{@slack_group_id}>!
2525
2626
<@#{@puzzle.suggested_by}> has submitted a new suggestion for a puzzle:
2727

env.sample

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
DISCORD_BOT_TOKEN=<insert bot token here>
1+
APP_URL=<admin panel app URL> # optional, only if using Slackbot functionality
2+
DISCORD_BOT_TOKEN=<insert bot token here> # required
3+
DOMAIN_ALLOWLIST=<comma-separated list of allowed domains for google authentication> # optional, only if using Google OAuth and wanting to restrict access to certain domains
4+
GOOGLE_CLIENT_ID=<google client id from google cloud oauth credentials> # optional, required if using the admin panel with Google OAuth
5+
GOOGLE_CLIENT_SECRET=<google client secret from google cloud oauth credentials> # optional, required if using the admin panel with Google OAuth
6+
RAILS_EMOJI_ID=<custom emoji id> # optional, if not set, will fallback to a default emoji
7+
RUBY_EMOJI_ID=<custom emoji id> # optional, if not set, will fallback to a default emoji
8+
SLACK_GROUP_ID=<slack group id> # optional, only if using Slackbot notification functionality
9+
SLACK_NOTIFICATIONS_CHANNEL=<slack notifications channel id> # optional, only if using Slackbot notification functionality
10+
SLACK_SIGNING_SECRET=<slack signing secret> # optional, only if using Slackbot functionality
11+
SLACK_TOKEN=<slack signing secret> # optional, only if using Slackbot functionality

0 commit comments

Comments
 (0)