Skip to content

Commit

Permalink
Data model for room reservation implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Joffreybvn committed Feb 6, 2021
1 parent 9ca5192 commit 692e843
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 38 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from botbuilder.core.integration import aiohttp_error_middleware
from botbuilder.schema import Activity, ActivityTypes

from src.dialogs import UserProfileDialog
from src.dialogs import RoomReservationDialog
from src import Bot
from config import Config

Expand Down Expand Up @@ -64,7 +64,7 @@ async def on_error(context: TurnContext, error_: Exception):
USER_STATE = UserState(MEMORY)

# Create main dialog and bot
DIALOG = UserProfileDialog(USER_STATE)
DIALOG = RoomReservationDialog(USER_STATE)
bot = Bot(CONVERSATION_STATE, USER_STATE, DIALOG)


Expand Down
2 changes: 1 addition & 1 deletion src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from botbuilder.core import ActivityHandler, TurnContext, ConversationState, UserState
from botbuilder.dialogs import Dialog

from .dialogs import DialogHelper
from .dialogs.helpers import DialogHelper
from .nlu import NLU

nlu = NLU()
Expand Down
5 changes: 2 additions & 3 deletions src/dialogs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

from .dialogs_helper import DialogHelper
from .example import UserProfileDialog
from .room_reservation_dialog import RoomReservationDialog

__all__ = ["DialogHelper", "UserProfileDialog"]
__all__ = ["RoomReservationDialog"]
4 changes: 2 additions & 2 deletions src/dialogs/data_models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from .user_profile import UserProfile
from .room_reservation import RoomReservation

__all__ = ["UserProfile"]
__all__ = ["RoomReservation"]
9 changes: 9 additions & 0 deletions src/dialogs/data_models/room_reservation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

class RoomReservation:
"""Hotel's room reservation state."""

def __init__(self, people: int = None, duration: int = None, breakfast: bool = None):

self.people: int = people # Number of people
self.duration: int = duration # Number of nights
self.breakfast: bool = breakfast # If they take breakfast
14 changes: 0 additions & 14 deletions src/dialogs/data_models/user_profile.py

This file was deleted.

4 changes: 4 additions & 0 deletions src/dialogs/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

from .dialogs_helper import DialogHelper

__all__ = ["DialogHelper"]
File renamed without changes.
Empty file.
32 changes: 16 additions & 16 deletions src/dialogs/example.py → src/dialogs/room_reservation_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from botbuilder.dialogs.choices import Choice
from botbuilder.core import MessageFactory, UserState

from .data_models import UserProfile
from .data_models import RoomReservation


class UserProfileDialog(ComponentDialog):
class RoomReservationDialog(ComponentDialog):

def __init__(self, user_state: UserState):
super(UserProfileDialog, self).__init__(UserProfileDialog.__name__)
super(RoomReservationDialog, self).__init__(RoomReservationDialog.__name__)

# Load the UserProfile class
self.user_profile_accessor = user_state.create_property("UserProfile")
self.room_reservation_accessor = user_state.create_property("RoomReservation")

# Setup the waterfall dialog
self.add_dialog(WaterfallDialog(WaterfallDialog.__name__, [
Expand Down Expand Up @@ -50,14 +50,14 @@ async def people_step(step_context: WaterfallStepContext) -> DialogTurnResult:
async def nights_step(step_context: WaterfallStepContext) -> DialogTurnResult:

# Save the number of people
step_context.values["peoples"] = step_context.result.value
step_context.values["people"] = step_context.result.value

# Confirm the number of people
await step_context.context.send_activity(
MessageFactory.text(f"Okay, for {step_context.result.value}")
)

# NumberPrompt - How many nights ?
# NumberPrompt - How many nights ? (duration)
return await step_context.prompt(
NumberPrompt.__name__,
PromptOptions(
Expand All @@ -69,7 +69,7 @@ async def nights_step(step_context: WaterfallStepContext) -> DialogTurnResult:
async def breakfast_step(step_context: WaterfallStepContext) -> DialogTurnResult:

# Save the number of nights
step_context.values["nights"] = step_context.result
step_context.values["duration"] = step_context.result

# ConfirmPrompt - Is taking breakfast ?
return await step_context.prompt(
Expand All @@ -81,7 +81,10 @@ async def breakfast_step(step_context: WaterfallStepContext) -> DialogTurnResult

async def summary_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:

# If the user said True:
# Save if the user take the breakfast (bool)
step_context.values["breakfast"] = step_context.result

# If the user said "Yes":
if step_context.result:

# Confirm breakfast hour
Expand All @@ -90,16 +93,13 @@ async def summary_step(self, step_context: WaterfallStepContext) -> DialogTurnRe
)

# Save information to Reservation object
user_profile = await self.user_profile_accessor.get(
step_context.context, UserProfile
room_reservation = await self.room_reservation_accessor.get(
step_context.context, RoomReservation
)

"""
user_profile.transport = step_context.values["transport"]
user_profile.name = step_context.values["name"]
user_profile.age = step_context.values["age"]
user_profile.picture = step_context.values["picture"]
"""
room_reservation.people = step_context.values["people"]
room_reservation.duration = step_context.values["duration"]
room_reservation.breakfast = step_context.values["breakfast"]

# End the dialog
await step_context.context.send_activity(
Expand Down

0 comments on commit 692e843

Please sign in to comment.