Sends notification to Slack about new Reddit posts. The motivation was that we are using with a private subreddit as a forum but we lacked notifications about new posts.
It can send notifications into multiple channels specified by tags in the reddit post's title. Some examples:
- Reddit post title: "[ruby] Ruby is awesome" -> posts it to the
ruby
channel - Reddit post title: "[elixir][kotlin] What to learn next?" -> posts it to the
elixir
andkotlin
channels - Reddit post title: "What to do on our next team building?" -> posts it to the channel set as default
It does not check for channel existence on Slack therefore posts tagged with non-existent channels will be ignored.
Refer to .ruby-version.
The application uses environment variables for configuration:
LOG_LEVEL
: level supported by Ruby Logger
. It logs to STDOUT so you might want to redirect the output of the script to a file.
Default: info
.
SLACK_INCOMING_WEBHOOK_URL
: Slack webhook url, something like: https://hooks.slack.com/services/XXXXXYYYYZZ
Specify your slack bot settings here: name, avatar, etc.
SLACK_DEFAULT_CHANNEL
: If no tags found or the tag is not in the whitelist, the notification will be sent here.
Default: random
SLACK_CHANNELS_WHITELIST
: Comma separated lists of channels where the notifier allowed to send messages. Add defualt channel explicitly if you want to allow that in a multiple tags scenario.
For example: ruby,elixir,dev-ops,r_lang
REDDIT_USER
, REDDIT_PASSWORD
: The credentials of your or your bot's user on Reddit
REDDIT_SUBREDDIT
: The subreddit will be polled for new posts.
Default: aww
REDDIT_APP_CLIENT_ID
, REDDIT_APP_SECRET
: Create an app on Reddit with script
type. Fill redirect uri
with some bogus value, it's not used.
REDDIT_APP_USER_AGENT
: Set your User-Agent for Reddit, you can read about this in their API rules
Default: Redd:RedditToSlack-rb:v1.0.0 (by /u/$YOUR_REDDIT_USER)
STORE
: At the moment just a YAML file is supported to store "last_run" information between executions. You can specify a file path without the extension.
Default: $app_dir/db
bundle install
Use your favourite tools and methods, for example with cron:
*/1 * * * * source ~/env.sh && cd ~/app && bundle exec run.rb >> logs/app.log 2>>logs/stderr.log
Notice Don't set the interval too short because the script runs might overlap and you will have a bad time (probably duplicated slack notifications). Also, watch out for reddit API rate limits.