A bot for Slack that can search StackOverflow questions and display UNIX fortunes.
I decided to create a Slack bot that could search StackOverflow for questions because I mostly use Slack for discussing web development with my teammates. It's handy to have a StackOverflow search available in the middle of a discussion about bugs and computer errors.
I also added a UNIX fortune functionality, just to keep the project fun and entertaining. Fortune outputs sometimes sarcastic or interesting phrases on the screen. This way you won't get bored while you're debugging your code :)
This project was featured in Career Karma as one of the top projects of the month of April, 2020!
- Ruby 2.6.5p114
- Rubocop 0.80.1
- RSpec 3.9
- Visual Studio Code 1.42.1
A live Demo is currently unavailable as it would require a Premium Heroku account.
It is possible to test Stackbot locally as well as remotely by deploying it to Heroku. You will need both a Slack and a Heroku account for this. To get a local copy up and running follow these simple example steps.
Make sure you install Ruby and have the following packages installed before continuing:
$ gem install bundler rspec foreman
In order to test Stackbot you will need to create a Slack APP. Make sure you create a Classic Slack app, otherwise the bot will not work. Once you've created the app, configure it as a bot and install it to your preferred Slack workspace. Don't forget to save it's API token somewhere. You will need the token in order to test the bot.
To test Stackbot locally, clone the repository, navigate to it's containing directory, and run:
$ bundle install
$ echo 'SLACK_API_TOKEN=your_token_here' > .env
$ foreman start
This should install all ruby gems, generate an .env
file containing the API token from the Setup, and start a local server where Stackbot will live.
Once Stackbot is running either locally or remotely in Heroku, you can log into the Slack workspace where you installed it and invite it to your channel by typing /invite @Stackbot
.
Typing @Stackbot help
will display the following message:
Give me commands by typing @Stackbot command [arguments]
Here's a complete list of my available commands:
help Display this help message.
search your search terms Search StackOverflow for relevant questions
fortune Tell a fortune from the classic UNIX gamefortune
hi Say "hi" to me!
about Display links to more details about me.Example: @Stackbot search HTML api
You may try any such commands on Slack.
Running rspec
will test the previous functionalities. You will need to be connected to the internet to run the tests. Navigate the spec
directory to find out how the tests are performed. Testing currently returns the following results:
SlackStackbot::Commands::Default
lowercase
capitalized
with about argument
SlackStackbot::Commands::Fortune
fortune is contained in fortune file
SlackStackbot::Commands::Help
help
SlackRubyBot::Commands::Hi
says hi
SlackStackbot::Commands::Search
StackOverflow search returns some results
StackOverflow search returns no results
Search terms missing
SlackStackbot
has a version
Finished in 2.09 seconds (files took 1.74 seconds to load)
10 examples, 0 failures
You may deploy Stackbot on Heroku by running the following commands in the repo directory:
$ heroku create
$ git push heroku master
$ heroku config:add SLACK_API_TOKEN=your_token_here
$ heroku ps:scale web=1
$ heroku open
This should keep Stackbot alive in your Heroku app for a while. However, if you want to keep running Stackbot for longer, you'll have to pay for a premium plan.
Oscar Mier
- Github: @voscarmv
- Twitter: @voscarmv
- Linkedin: Oscar Mier
- Extend the variety of available search engines.
- Add more games other than UNIX Fortunes.
- Make the bot sentient using AI 🤖🧠
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
- I used the Slack Ruby Bot framework to lay the code foundation for the project.
- I used parts of the code from the stackoverflow gem to query StackOverflow questions by using the StackExchange API
- I also used parts of the code from fortune_gem to build my implementation of
fortune
. - I copied the contents of the fortune files from the fortune-mod ubuntu package into my
lib/fortunes
file for myfortune
implementation. - I created a prototype before this project using git submodules of the aforementioned packages. I've left it in my repositories for reference.
This project is MIT licensed.