Java-based Slack Bot that responds to a few simple commands
- Integrate with Slack
- Provide a list of commands
- Retrieve answers to at least four commands
- Have a name and avatar
- Provide a README file for the project
- Implement unit tests
- Integrate Travis CI
A UML class diagram of the EnigmaBot source code is shown below:
(Class diagram generated from source using the OjbectAid Eclipse Plugin.)
The classes represented in the diagram above:
- EnigmaBotMain is the application entry point, handling bot startup & shutdown.
- EnigmaBot uses the jSlack library for Slack integration. This class listens for Slack messages (direct or on a channel to which the bot has been invited), parses the message content, and executes commands found in the messages.
- SlackMessage Java bean class used to deserialize received slack messages from JSON. Deserialization uses the Google GSON library.
- SlackMessageFactory Used for SlackMessage object.
- ISlackBotCommand is the interface implemented by all supported commands. The main EnigmaBot class uses the Reflections library to locate commands within the "com.instavector.slackbot_command" package at runtime.
- CveCommand searches a database of CVE records for CVE identifier or keyword (returns up to 10 matching results).
- JokeCommand tells you a random joke from the jokes.txt file.
- PictureCommand retrieves a random picture from Flickr having the specified tag
- WeatherCommand provides a weather forecast for a zip code or city name
EnigmaBot uses Maven. Run mvn package
to build the project.
Unit tests are disabled by default. Unless external service API keys are populated in the properties files the tests will fail. As the API keys should be kept secret, the properties files are not committed to source control. To use unit tests, populate the properties files as described in the first step of the manual testing section below and run mvn -DskipTests=false test
.
- Populate "*-token" properties files in the project directory
- .api-token: Slack API token,
apiToken = xxxxxxxxxx
- .weather-token: Open Weather Map token,
appId = xxxxxxxxxx
- .flickr-token: Flickr API token,
key = xxxxxxxxxx, secret = xxxxxxxxxx
- .api-token: Slack API token,
- Populate the local CVE database by installing and intializing the CVE Search application
- Ensure Mongo is running on the same system as the bot to support CVE lookups
- Add a bot to your Slack channel
- Upload the
robot.jpg
file as the bot's avatar - Run the bot:
java -cp "target\deps\*;target\enigmabot-0.0.1.jar" com.instavector.slackbot.EnigmaBotMain
- Create Slack channel for testing, e.g., "bot-testing" or direct-message the bot
- Invite bot to channel,
/invite @enigma-bot
- Send a
list
message to see a list of commands supported by the bot
Beware - when using the "picture" command to retrieve images from Flickr, you are reliant upon the tags placed on the images by photographers. You may receive images you believe to be irrelevant or inappropriate. While this bot does request "safe" images, it has no control over the actual content of those images.
- Add environment variable support for base directory in which to look for property files
- Better regular expression handling for command arguments
- JavaDoc comments
- CVE command property file to allow non-default parameters for Mongo DB connection