Skip to content

Conversation

@s
Copy link
Owner

@s s commented Jun 7, 2017

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.

@s s requested review from BogdanSr, atkit, goudsmit and makadaw June 7, 2017 16:02

import Foundation

class CoffeeManager : NSObject {
Copy link
Collaborator

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?

Copy link
Owner Author

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.

@atkit
Copy link
Contributor

atkit commented Jun 28, 2017

feels like something wrong with merge, why does it contain so many old commits ?

@atkit
Copy link
Contributor

atkit commented Jun 28, 2017

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

Said Ozcan added 17 commits June 28, 2017 15:31
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.
@s s force-pushed the initial_logic branch from 334e5f3 to 4686a88 Compare June 28, 2017 13:32
Copy link
Collaborator

@makadaw makadaw left a 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 {
Copy link
Collaborator

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?

Copy link
Owner Author

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.

Copy link
Collaborator

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() {
Copy link
Collaborator

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.

Copy link
Owner Author

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) {
Copy link
Collaborator

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?

Copy link
Owner Author

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.

Copy link
Collaborator

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 {
Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Owner Author

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?

Copy link
Collaborator

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)")
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Owner Author

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?

Copy link
Collaborator

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 ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants