🤖 A bot to play tic-tac-toe game on Slack is developed.
This is a capstone project in the Ruby course at Microverse - @microverseinc . Creating a bot for any platform for any purpose is the purpose of this capstone project.
The task is to create a bot to play a tic-tac-toe game on Slack.
This project is mainly about
Clone this repository by running git clone https://github.com/ozovalihasan/slack-tictactoe-bot.git
.
Run cd slack-tictactoe-bot
.
Install ngrok by running snap install ngrok
(I used Snap store. If you don't use Snap store, check the alternatives).
Install ruby.
Install Bundler by running gem install bundler
.
Run bundle install
.
Create a workspace to test this app.
Create a Slack App.
Open OAuth & Permissions
located under the Features
title at the left side of page. Go to Scopes
, add chat:write
, im:write
and im:history
for Bot Token Scopes
.
Go to the top of the page. Install your app to your workspace by using Install App to Workspace
button. If you change any setting, reinstall it.
Go to the top of the page and copy Bot User OAuth Access Token
.
Open the terminal, and run export SLACK_BOT_TOKEN=xoxb-000000000000-xxxxxxxxxxxxxxxxxxxxxxxx
. 'xoxb-000000000000-xxxxxxxxxxxxxxxxxxxxxxxx' part must be changed with token you copied.
Open the page of app settings and click Basic Information
on the left side of the page. Under the App Credentials
, find Verification Token
and copy it.
Open the terminal, and run export SLACK_VERIFICATION_TOKEN=xxxxxxxxxxxxxxxxxxx
. 'xxxxxxxxxxxxxxxxxxx' part must be changed with the token you copied.
Reminder: If you want to share your project, don't add this information to your project because Slack may disable your app if you share this information with the public.
App Home
under the Features
title. Check Always Show My Bot as Online
option.Steps until here are shown in the video.
Don't forget to reinstall your app.
Run Sinatra by using rackup
from the terminal. This terminal shouldn't be closed when the app is used.
Open another terminal and run ngrok http -host-header=rewrite 9292
. 9292 is default one, so if it is not working correctly, check terminal run rackup
. It is seen like Listening on tcp://localhost:9292
. Again this terminal must be open when the app is used.
When ngrok runs, there should be a link similar to https://1a2b3c4d5e.ngrok.io
. Copy this link and click 'Your apps' located at the right top of api.slack.com
. Click your app. Click Event Subscriptions
on the left side of the page. Paste copied link into Request URL
and add /slack/events
at the end of the link. It should be seen like https://1a2b3c4d5e.ngrok.io/slack/events
. Open Subscribe to bot events
part and add message.im
. Check Enable Events
. Lastly, click Save Changes
at the left bottom part of the page.
Click Interactivity & Shortcuts
on the left side of the page. Check the button of Interactivity
. Paste the same link into the box of Request URL
. And add /slack/attachments
at the end of the link. It should be seen like https://1a2b3c4d5e.ngrok.io/slack/attachments
. Lastly, click Save Changes
at the left bottom part of the page.
If ngrok is restarted, the copied link will be changed automatically. So, you need to follow the last two steps if it is restarted.
ngrok is accepting limited requests for a limited time. So, if there will be a lot of interaction between user and bot, the responding time of the bot may increase or it may not respond to the user's interaction. If this happened, ngrok can be restarted, or you may stop using the app for a while.
Go to your Workspace. Refresh the page and send a direct message to the bot from Slack. It is located under the Apps
title.
Steps until here are shown in the video.
If you want, check the demo of the app/bot.
For more information check Wikipedia.
To test the project.
Clone this repository by running git clone https://github.com/ozovalihasan/slack-tictactoe-bot.git
.
Run cd slack-tictactoe-bot
.
Install Bundler by running gem install bundler
.
Run bundle install
.
Run rspec
.
heroku create name-of-app
in the terminal. You may use any name for name of your Heroku app. You need to change 'name-of-app' with name you chose in the next steps.sudo snap install --classic heroku
. If you get any error check.heroku login
.master
branch,run git push heroku master
. If you are using another branch, run git push heroku +HEAD:master
.To configure your Heroku app
heroku config:set SLACK_BOT_TOKEN=xoxb-000000000000-xxxxxxxxxxxxxxxxxxxxxxxx
in terminal. Change bot token with one used before.heroku config:set SLACK_VERIFICATION_TOKEN=xxxxxxxxxxxxxxxxxxx
. Change verification token with one used before.heroku apps:info
.https://name-of-app.herokuapp.com/
.https://name-of-app.herokuapp.com/slack/events
into the box of 'New Request URL' under 'Enable Events' tab. Push 'Save Changes' button on the right bottom of the screen.https://name-of-app.herokuapp.com/slack/attachments
into box of 'Request URL' under 'Interactivity' tab.To play with your app
Check Gemfile. If versions of used gems are not updated, update them.
Check SLACK_VERIFICATION_TOKEN, SLACK_BOT_TOKEN. Check the link provided by ngrok and check the link used for 'Request URL's. Check the terminal run rackup
. If it shows any error, solve it.
bundle install
run, ERROR: Error installing websocket-driver:
is raising. What do I need to do?Try to run apt-get install ruby-dev
.
Run gem list
. If you have any gem whose version is greater than one given in Gemfile.lock
file, delete newer version of this gem.
👤 Hasan Özovalı
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
This project is MIT licensed.