Go-Wiki is a Slack Bot written in Golang that retrieves Wikipedia information.
Dependencies
- You will need
docker
anddocker-compose
installed. https://docs.docker.com/install/
Configuration
- Export Environment Variables to be used. If you do not have a Slack Token, please follow the steps in 'How to acquire a Slack Token' π
export GOWIKI_SLACK_TOKEN='xoxb-123456789012-123456789012-50rQ8TcaSdUoZDyAbHb0hjqs'
export GOWIKI_DB_CONFIG="user=postgres dbname=bot host=db port=5432 sslmode=disable"
Build
- Once your environment variables are properly configured, go to your terminal and run
docker-compose up
This will enable your server to run with a postgres db. You will beable to see the logs.
Optionally if you prefer to use Docker swarm you can run this using
docker swarm init
docker build -t go-wiki .
docker stack deploy --compose-file=docker-compose.yml go-wiki
Go to your slack channel and click on + Add App
Search go-wiki and add to channel
Use the command gowiki
to search a topic you would like to share with your team! π
gowiki Toronto
go-wiki stores each call to a database for caching so the next time around it will show up without the need to call Wikipedia. :squirrel:
Below are steps to aquire a slack token necessary for this golang application to work.
- Create a Slack App https://api.slack.com/apps?new_app=1
- Create a bot user
- Install your app to your workplace
- Now go to OAuth & Permissions and copy the Bot User OAuth Access Token
π Congratulations! π Now you have your Slack Token! Now go back up to Setup!
I have left the entire struct of a wikipedia page in main.go. Please feel free to call anything that your heart desires from Wikipedia to your Slack Channel β€οΈ. Just remember to add the rows to the pages table in the database, update the db query and response!
- Creating struct using https://mholt.github.io/json-to-go/