Coder Social home page Coder Social logo

reddit-slackbot's Introduction

Reddit Slack bot

MIT License

Browse through the most popular safe-for-work subreddits directly from any the Ghst Solutions Slack Workspace. This application is licensed under MIT. All 3rd party data is sourced directly from Reddit.

This application was built to experiment with Slacks Bolt library. It is simply a fun proof of concept.

Preview live @ Ghst Solutions Slack Workspace

Slash Commands

Command Name Optional parameters Description
/reddit r/any-subreddit The quickest way to browse is via the /reddit command. If no parameters are passed, the bot will display the reddit home page. If a valid parameter is passed, the bot will attempt to fetch or throw "Whoops. Something went wrong".

Local Setup

This app runs locally on ngrok. Let's summarize what we will need to do to get started.

Set environmental variables

Create the .env.local file. We can start by renaming the .env.example to match the dotenv declaration.

# rename .env.example to .env.local
mv .env.example .env.local

Start ngrok server

~/ngrok http 3009

Once the ngrok server is online we will need to update the URLs we plan on using via https://api.slack.com/apps. We are going to refer to https://e6829b5713d5.ngrok.io as the base URL for this example. Keep in mind you will be assigned a unique temporary ngrok URL when running the above command

Let's also take a moment to verify the credentials used here also match the local database url used in the .env.example file. Once we've built the local database, we are ready to start the Bolt app.

Start the Bolt app

What is Bolt? For our understanding and general context, Bolt is a wrapper that sits on top of an Express server, used to Slack applications.

Now we are ready to set up our source code. Assuming we have set our environmental variables this should be a quick and painless process.

# install project dependencies
npm install

# we ignore /dist by default
# let's build that
npm run build 

# start the Bolt app
npm run start

At this point we should be presented with the standard app listening on http://localhost:3009 message in the terminal. This is a great point to begin testing your Slack connections.

Frequent reasons this process might fail

Frequent reasons this process might fail

  • Your environmental variables aren't being read by dotenv.

Check out the ./lib/index.ts file and verify that your .env.local file matches the absolute path specified in the dotenv.config() method.

const path = require('path');
// ...
// Configures local environment
require('dotenv').config({path: path.resolve(__dirname, "../.env.local")});

// DEBUGGING
console.log(path.resolve(__dirname, "../.env.local"));
  • Slack App does not have required permissions
  • Ngrok server shut down and needs to be restarted By default the ngrok URL is active for 2 hours at which point it will automatically timeout. When we reset the ngrok server we will need to update the base URL as defined in the Start ngrok server section.

This can be easily identify as the root issue to most unexpected errors. Be sure to keep an eye on your ngrok server throughout development.

  • [Slash Commands] Reddit Bot needs to be invited to the channel Found this to be the case when migrating to @slack/bolt. This thread on Stack Overflow helped provide a solution.

reddit-slackbot's People

Contributors

matthewbub avatar

Watchers

 avatar  avatar

reddit-slackbot's Issues

migrate oauth to @slack/bolt

As mentioned in #3. Everything was pretty easy to read in the initial commit but we are no longer capable of hitting the /oauth endpoint without some undocumented workaround slackapi/bolt-js#283 (comment) which certainly cannot be the right way to go about this.

With the migration to @slack/bolt we have shifted from various endpoints to what is now, all pointing towards /slack/events but it looks like this particular method might bounce off a /slack/oauth endpoint so we will need to be sure we have set that. https://slack.dev/bolt-js/concepts#authenticating-oauth

We still have the @slack/oauth package installed, if we don't need it let's remove it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.