wildcodeschool / sea-chuck-bot Goto Github PK
View Code? Open in Web Editor NEWChuck Norris Chat Bot for RocketChat
Chuck Norris Chat Bot for RocketChat
Currently, the import and storage of jokes is implemented in multiple classes and without an interface/API. For other developers to be able to use the persistence of jokes, the API should be like this:
JokesPersistence
is an interface which specifies
List<Joke> loadData()
and storeData(List<Joke> jokes)
JokesFilePersistence
which provides a constructor JokesFilePersistence(File storage)
and implements the methods for files.main
method has a handling for CLI arg import FILENAME which imports jokes and prints them.JokesPersistence jokesPersistence = new JokesFilePersistence(args[1])
loadDataImportJokes()
: checks, if the program can import the jokes correctly from a fileloadDataFileExtension()
: checks, if the Jokes File has the correct file extensionloadDataEmptyLines()
: checks, if the program reacts correctly to empty lines in Jokes fileloadDataFileExists()
: checks, if the program reacts correctly, if the Joke file does not existsloadDataClearFile()
: checks, if the program reacts correctly, if the Joke file is emptyloadDataWrongDateFormat()
: checks, if the program reacts correctly, if the Joke file contains invalid date patternsloadDataSeparator()
: checks, if the program reacts correctly, if the Separator in Joke file is contained several timesstoreData()
: checks, if the program stores the Jokes correctly in Joke filestoreDataFileNotExist()
: checks, if the program reacts correctly, if the method storeData wants to write in a Joke file, which does not existcleanUp()
: Cleans up after all tests (deletes new created files during test routine)To be able to administrate currently stored jokes, on the overview http://localhost:8080/jokes
in the HTML-page, it should be possible to create
and delete
jokes (update
is excluded for now).
See https://www.baeldung.com/thymeleaf-in-spring-mvc
As a user, I don't want to see the oldest jokes, but always the newest ones first. There should be a method which sorts Jokes for their creationDate
descending.
main
method has a handling for CLI arg display_sorted FILENAME which imports jokes and prints them for their creationDate
descending.Create a Test Suite which can be started manually and executes all tests automatically. Use either IntelliJ, VSCode or Postman. The tests should simulate a complete flow: retrieving jokes, creating a new joke, retrieving again, delete, retrieving again.
To be able to test the application without a running external service, a mocked chatbot is necessary. This mocked bot should read from the database and be configurable for the tags to listen for.
The mocked bot will simulate a Chat Bot by reading commands from System.in
. Each command will ask a ChatBotServiceMock
if an action is configured for the input and if it is, execute it.
To be able to see all currently stored jokes, with opening http://localhost:8080/jokes
all jokes are queried from the database and display as HTML.
The jokes should either be sorted alphabetically or by date.
See https://www.baeldung.com/thymeleaf-in-spring-mvc
The application should be deployed on Heroku, so it can be accessed from everywhere, not just on a local environment.
Currently, the functionality is implemented in different classes. As a developer using the ChuckNorris Joke Engine, eg. from a Web application, I want to be able to use a unified API, like:
JokesPersistence persistence = new JokesFilePersistence(new File("jokes.txt"));
ChuckNorrisJokeService jokeService = new ChuckNorrisJokeService(persistence);
jokeService.initialize();
jokeService.printAllJokes();
jokeService.getNewestJoke();
jokeService.addNewJoke(Joke joke);
jokeService.shutdown();
initialize()
: Loads data from configured persistence.printAllJokes()
: Prints all imported jokes.getNewestJoke()
: Gets the most recently added (creationDate
) JokegetRandomJoke()
: Gets a random Joke from the service.addNewJoke(Joke joke)
: Adds a new Joke to the service.shutdown()
: Shutdown of the Service, the currently stored Jokes are persisted.main
method should handle everything by using the new ServiceThe currently implemented DB-Persistence should be migrated from the verbose plain JDBC to JPA.
application.properties
Currently, there are remaining classes for iterative development, eg. JokesContainer
. Check if the classes are still used and if not, delete them.
The main
method should be able to handle different command line arguments. Make sure the arguments are checked (null?, size>0?) and each new call gets an own switch
or if
branch.
All classes should be used, the main
method is well structured and robust.
The bot-adapter, which logs in to Rocket.Chat as bot
(with role bot
) and listens to channel GENERAL
should be running on a dedicated environment, not just locally.
The mocked Rocket.Chat should be replaced with a running version on localhost. As a first step, a locally running Rocket.Chat should be running. Next steps are creating a Bot which listens as a user of the Rocket.Chat instance. The implementation can/should be in JavaScript/CoffeeScript and delegate to a Spring Boot Web Service.
Our sample bot adapter
module.exports = (chuckbot) => {
chuckbot.respond(/(whataboutchuck)/gi, (res) => {
//wrap the HTTP get call as a Promise
new Promise((resolve, reject) =>
chuckbot.http("http://host.docker.internal:8080/api/jokes/random").get()((err, response, body) =>
err ? reject(err) : resolve(body)
)
)
//reply joke
.then(body => res.reply(body))
})
}
Acceptance Criteria
As a user, I can add jokes to an existing file and reimport the jokes.
After reimporting the file, the new jokes are included in the jokes storage data structure.
As a user, I can start the main method with the parameter "print" and all jokes are displayed with the introduction "These are the currently stored jokes", then the application is stopped.
After starting the main method and using "print" as a parameter, all currently stored jokes are printed.
The user (who starts the main method) can call a method to print all currently stored jokes.
There is a method to print out all jokes.
For external service, it must be possible to access the jokes via a REST API. In the first iteration, the access should be read-only.
GET /api/jokes/random
GET /api/jokes/{id}
GET /api/jokes
The jokes should either be sorted alphabetically or by date.
See https://spring.io/guides/gs/rest-service/
After a file is read with the correct format
joke1
joke2
joke3
and a joke has been added, the format changes to something like
[newjoke,[[oldjoke, oldjoke, ...]
all in one line with some many '[' characters.
As a developer, I can put a file with jokes (one joke one line) on the filesystem and those files can be imported.
If the file exists, the jokes are imported and a "import successful" or "import error" message is displayed at the end.
There should be a non-persistent list of jokes (Strings). As a developer, I can add jokes, recompile the application and the new joke has been added to the list.
As a developer I can edit a Java file, add a joke to an existing container (array or list), recompile and the joke is then included in the container.
Currently only a file-based persistence is implemented. This does not allow for more complex data structures like User
->Joke
or Joke
->Ratings
. Therefore, the file-based persistence should be deprecated for a relational database persistence.
# CREATE USER AND DATABASE
CREATE USER 'chuck'@'localhost' IDENTIFIED BY 'norris';
CREATE DATABASE chuckbot;
GRANT ALL PRIVILEGES ON chuckbot.* TO 'chuck'@'localhost';
FLUSH PRIVILEGES;
# CREATE TABLE
CREATE TABLE JOKES (
ID int NOT NULL AUTO_INCREMENT,
JOKETEXT text NOT NULL,
ADDED date,
PRIMARY KEY (ID)
);
# INSERT TEST DATA
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris kann Feuer mit einer Lupe machen – nachts!', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris läuft 100 Meter in einer Sekunde. Er kennt immer eine Abkürzung.', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris kann ein Feuer entfachen, indem er zwei Eiswürfel aneinander reibt.', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris wurde gestern geblitzt – beim Einparken.', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Wenn man Chuck Norris fragt, wie viele Liegestütze er schafft, antwortet er: "Alle."', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris kann ein Fünfeck zeichnen – mit vier Strichen.', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris entführt Aliens.', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris kann Drehtüren zuknallen.', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris kann Atom- von Ökostrom unterscheiden – und zwar am Geschmack.', NOW());
INSERT INTO JOKES (JOKETEXT, ADDED) VALUES ('Chuck Norris hat bis Unendlich gezählt. Zweimal.', NOW());
DBPersistence
implements JokePersistence
and uses a local MySQL database connection.The data structure for jokes currently is a String. However, more data has to be stored for the jokes, eg. a creationDate
which is a LocalDate
. A new class Joke
should be created which has at least a String (the joke) and a LocalDate (the creation date).
Only Users with Role "ADMIN" should be able to modify jokes. Only Users with Role "USER" can read jokes. Other Users (with no Roles) are rejected.
The Admin UI should look even greater! And more consistent.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.