-
-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify MVC/Command and multiple matching using regex with MVC #165
Comments
@chuckremes care to pitch in? |
@Startouf: Basically I ran into the same problem when employing the MVC feature for a small test project. Regarding the list of what you are expecting:
This is my dirty POC code:
Would this come close to what you expect an MVC approach to look like? |
Everyone should be making PRs! |
Missed the ping a week ago (on vacation!). Let me look at this in the morning and chime in. |
Here are my thoughts on a couple of different topics. In no particular order... Model@m-kind and @Startouf are correct that Model isn't really necessary. It was added as a convenience so that the magic variables of If @Startouf wants to refer to his Models as Service objects, I have no objection. For other programmers who are coming to this with a background in MVC, I think renaming these common elements is a mistake since it undermines their previous knowledge. MVC Name@Startouf references something he calls What I implemented here is model-view-controller pattern similar to Rails (but not identical). Rails is a huge beast of a system and I had no need for all of its functionality for my use-case. So I implemented the bare minimum aspects and borrowed a little bit from Rails. I am not a big fan of all the meta-programming magic that Rails uses so I didn't copy any of it. The point of the MVC exercise was to allow for bot commands to be testable. Whenever I create a command with any complexity beyond Regex MatchingThe original use-case that inspired the creation of the MVC code did not include this feature. However, I think that would be a fantastic feature to add. I'm definitely in favor of this. It would make MVC bots just as powerful as their regular Command bot brothers. Confusion on how to apply MVC for a botI included a full example of a bot using the MVC classes. Look at the I'll watch this thread for additional replies. |
@chuckremes |
I'm going to think out loud here for a minute. Follow along! The way the controller works now is that it creates a When a bot receives a message, the regular route lookup logic is invoked (literally in Commands::Base#invoke). The command string is converted into a method name according to certain rules (spaces are replaced with underscores, caps are downcased, etc). We then Our dilemma is now to figure out how to support Since we 1-to-1 map methods defined with
I'm sure there are other ways to skin this cat (see @m-kind's ideas for example... my first suggestion is very similar to his). I kind of like the first approach. It reduces some of the magic but makes class definitions more verbose. Here's how it might look in practice.
Thoughts? |
Oh, and we need to handle |
Hello I am a bit confused regarding your MVC + Command definition.
I haven seen a forum/irc so I hope it's Ok to discuss in an issue.
Maybe I am mistaken, but when comparing my experience with rails and other MVC frameworks, I had the understanding of slack-ruby-bot as a
Command-Controller-Service-Model-View
approach. I'd like to clear up my understandingTo begin with I don't understand how can Commands be separated into Controller-Model-View while preserving custom regex matches. Suppose I want to use custom regex matching on the user input and route several regex to the same action, how would I do that with MVC ? it is not clear if
alternate_names
accepts something else than string. For example, what if I wanted bothcall
and呼び出し
to route to my #call action ?I am actually missing some sort of
Routes
component/naming in the design, ie. a place/file where the expression matching is performed the user sentence to determine the controller/action to be used. I was hoping to be able to register severalmatch()
regex and they would all be redirected to the samecontroller#action
. Actually at some point I thought this was what you actually calledCommand
s, and I would rather have seen a command implement something like thisfollowing the
Rails
way I'd have even imagined something likeRegarding controllers, I have not much to say the name fits well. Maybe I'd say that together Routing + Controller would form the NLP (Natural Language Processing) component for the slack-ruby-bot" responsible for understanding user input
But then, I don't understand what's the
Model
for you. For people coming from MVC frameworksModel
usually refers to objects resolved in the controllers that are then passed to the view, eventually with an intermediateService
steps that helps collecting data needed to build thoseModels
. I would have rather written my controller like thisWith a different concrete example, assume my chatbot is responsible for finding information about people. Assume a user asks
I'm expecting
SlackRubyBot::Commands::Base
recognizeswhois
command as it matches/who is (.*) \?.*
, and should route to...UsersController#show
downcase
, etc.) and eventually retrieve special options (like scanning for "give me his birth date"). Based on that the controller calls services likeMyOwnInformationDatabaseService
,WikipediaService
, etc. that are responsible for gathering required material to answer a user query. those info are used to buildUser
models that structure the dataSlackRubyBot::MVC::Model::Base
but I usually talk about service since this is where the business logic takes place.Objects
with nice accessors so we can call@user.name
@user.linkedin_url
What do you think about this ?
I'm actually trying to implement an information chatbot using your MVC design, but at some points names feel wrong, and I'm stuck since I don't understand how to have a MVC with additional
match
(is it only possible to use regex as alternate names ? how are they transformed ?)Otherwise your bot engine feels great and I hope I can build some nice bots and contribute to your repo :-)
The text was updated successfully, but these errors were encountered: