-
Notifications
You must be signed in to change notification settings - Fork 3
initial logic #34
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
base: master
Are you sure you want to change the base?
initial logic #34
Conversation
Sources/Core/CoffeeManager.swift
Outdated
|
|
||
| import Foundation | ||
|
|
||
| class CoffeeManager : NSObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need NSObject here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now we don't need it. I am removing inheritance from NSObject.
|
feels like something wrong with merge, why does it contain so many old commits ? |
|
I see, it feels like it needs rebase + force push (don't worry, it is handled by github in positive way) If you have question how to do that, please feel free to come to us today |
This commit adds the initial stub for AppointingService which chooses a person to prepare the coffees from given session
This commit adds initial stub for EntityRecognitionService which parses given string to entities such as Coffee
This commit adds initial stub for SessionService which has functionalities to store and restore the session
This commit adds initial stub for SpellCheckingService which normalizes a given text
Add inital stub for TextProcessingService which processes the given text and return a result
This commit updates the description of Coffee model where now it returns all descriptions of additions as string
This commit updates coffee property to become an array instead of one Coffee since a person may request multiple coffees
This commit deletes old spell checker file since we can always restore it from .git history to use in new SpellChecker class.
makadaw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add few questions and comments
| func process(activity:Activity) | ||
| } | ||
|
|
||
| class CoffeeManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this entity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of CofeeBot as a main.m which speaks with the external modules and this CoffeeManager handles all the internal services and everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think you can merge this class to CoffeeBot. And then extend CoffeeBot with Bot protocol.
So you have entry point to your Bot and you can test it as you want and in same time extending from Bot protocol give you ability to integrate it inside BotsKit
| } | ||
|
|
||
| //MARK: Lifecycle | ||
| public init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set dependencies of this class (SessionService, Appointng, etc) as parameters for init and provide default implementations as default value
public init(sessionService: SessionService = SessionService(), ...)
With this approach it's easy to write unit tests and inject dependecies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right I will create a factory to create CoffeeBot, in this way we will be able to inject dependencies.
I would like to create own factory class because I think external classes don't necessarily know about all internal types such as EntityRecognitionService.
| weak var botDelegate : CoffeeBot? | ||
|
|
||
| //MARK: Lifecycle | ||
| init(textProcessingService:TextProcessingService, appointingService:AppointingService, sessionService:SessionService) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about close this Services by protocols?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a really good point, I will think of this. I only have one concern which is:
If I receive something like init(services:[CoffeeBotServiceProtocol]) since all services have different functionality and method signatures I am not sure if I can unify them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean create protocols for each service and then create implementation for each protocol, this can help you to tests your bot
| return currentSession.membersReplied.count == conversation.members.count | ||
| } | ||
|
|
||
| fileprivate func isTimeoutPeriodFinished() -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point I think we need to add some timer pulling into BotsKit
| class CoffeeManager { | ||
|
|
||
| //MARK: Properties | ||
| fileprivate var session : Session? = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the bot will process few session in the same time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there could be only one session at a time. Because if a second session is started before the first one is ended how will we differentiate between which coffee request came to which session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good question :) Here is the difference between mobile app and backend, one app needs to process different requests at the same time.
Let's discuss this on next meeting!
| self.sessionService.save(session: session) | ||
|
|
||
| case .error(let error): | ||
| Log.error("An error occured during processing message:\(error.localizedDescription)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think good variant will ask user repeat his message
|
|
||
| internal struct Coffee { | ||
| let amount : Int | ||
| let type : CoffeeType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about internal type in Coffee namespace? Something like:
let type: Coffee.Type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I never have done this before. Can you share an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, https://github.com/s/SwiftBot/blob/master/Sources/ChatProviders/Facebook/MessengerWebhook.swift#L72
or in your case:
internal struct Coffee {
let amount : Int
enum `Type`: String {
case espresso
case capuchino
}
let type: Type
}Then you can extend your type with this:
extension Coffee.Type {
func ...
}
In this PR, I have implemented the initial architecture and logic for CoffeeBot where we have several stubs for several methods&services.
CoffeeBot implements Bot protocol and has one main class to handle requests which is CofeeManager. Other than that there are many helper services which accomplish individual tasks such as EntityRecognitionService or SessionService etc.