Skip to content

yelkeew/EnigmaBot

Repository files navigation

EnigmaBot

Java-based Slack Bot that responds to a few simple commands

Requirements

  1. Integrate with Slack
  2. Provide a list of commands
  3. Retrieve answers to at least four commands
  4. Have a name and avatar
  5. Provide a README file for the project
  6. Implement unit tests
  7. Integrate Travis CI

Design

A UML class diagram of the EnigmaBot source code is shown below:

UML (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

Build

EnigmaBot uses Maven. Run mvn package to build the project.

Test

Unit Tests

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.

Manual Testing

  1. Populate "*-token" properties files in the project directory
  2. Populate the local CVE database by installing and intializing the CVE Search application
  3. Ensure Mongo is running on the same system as the bot to support CVE lookups
  4. Add a bot to your Slack channel
  5. Upload the robot.jpg file as the bot's avatar
  6. Run the bot: java -cp "target\deps\*;target\enigmabot-0.0.1.jar" com.instavector.slackbot.EnigmaBotMain
  7. Create Slack channel for testing, e.g., "bot-testing" or direct-message the bot
  8. Invite bot to channel, /invite @enigma-bot
  9. 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.

TODO

  1. Add environment variable support for base directory in which to look for property files
  2. Better regular expression handling for command arguments
  3. JavaDoc comments
  4. CVE command property file to allow non-default parameters for Mongo DB connection

About

Example of a Slack bot written in Java

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages