Skip to content

Commit

Permalink
Update auth workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinbuss committed Sep 16, 2024
1 parent be09f26 commit 2127647
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
18 changes: 16 additions & 2 deletions code/backend/bots/assistant_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
TurnContext,
UserState,
)
from botbuilder.dialogs import Dialog
from botbuilder.schema import (
ActionTypes,
Attachment,
Expand All @@ -18,6 +19,7 @@
SuggestedActions,
)
from core.config import settings
from dialogs.dialog_helper import DialogHelper
from llm.assisstant import assistant_handler
from models.assistant_bot_models import ConversationData, FileInfo, UserData
from models.assistant_models import AttachmentResult
Expand All @@ -29,7 +31,10 @@
class AssistantBot(ActivityHandler):

def __init__(
self, conversation_state: ConversationState, user_state: UserState
self,
conversation_state: ConversationState,
user_state: UserState,
dialog: Dialog,
) -> None:
"""Initailizes the Bot with states.
Expand All @@ -46,6 +51,7 @@ def __init__(
"Missing user state parameter. 'user_state' is required but None was given."
)

self.dialog = dialog
self.conversation_state = conversation_state
self.user_state = user_state
self.conversation_state_accessor = self.conversation_state.create_property(
Expand Down Expand Up @@ -79,6 +85,7 @@ async def on_members_added_activity(
"Hello and welcome! I am your personal joke assistant."
)
await turn_context.send_activity(welcome_message)
await turn_context.send_activity("Type any message to get logged in.")

# Respond with suggested actions
suggested_topics_message = (
Expand Down Expand Up @@ -136,7 +143,14 @@ async def on_message_activity(self, turn_context: TurnContext) -> None:
turn_context (TurnContext): The turn context.
RETURNS (None): No return value.
"""
logger.info(f"Received input from user.")
logger.info(f"Received input from user. Starting dialog to handle login.")
await DialogHelper.run_dialog(
dialog=self.dialog,
turn_context=turn_context,
accessor=self.conversation_state_accessor,
)

logger.info(f"Handle message from user.")
if (
turn_context.activity.attachments
and len(turn_context.activity.attachments) > 0
Expand Down
1 change: 0 additions & 1 deletion code/backend/bots/auth_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async def on_members_added_activity(
await super(AuthBot, self).on_members_added_activity(
members_added, turn_context
)
await turn_context.send_activity("Type any message to get logged in.")

async def on_turn(self, turn_context: TurnContext) -> None:
"""Called by the adapter to handle activities.
Expand Down
11 changes: 6 additions & 5 deletions code/backend/dialogs/login_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, connection_name: str) -> None:
super(LoginDialog, self).__init__(
dialog_id=LoginDialog.__name__, connection_name=connection_name
)
self.dialog_id = "WaterfallDialog"

self.add_dialog(
dialog=OAuthPrompt(
Expand All @@ -43,18 +44,18 @@ def __init__(self, connection_name: str) -> None:

self.add_dialog(
dialog=WaterfallDialog(
dialog_id="WaterfallDialog",
dialog_id=self.dialog_id,
steps=[
self.prompt_step,
self.login_step,
],
)
)

async def on_begin_dialog(
self, inner_dc: DialogContext, options: object
) -> DialogTurnResult:
return await super().on_begin_dialog(inner_dc=inner_dc, options=options)
# async def on_begin_dialog(
# self, inner_dc: DialogContext, options: object
# ) -> DialogTurnResult:
# return await super().on_begin_dialog(inner_dc=inner_dc, options=options)

async def prompt_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
"""Handles the prompt step of the login dialog.
Expand Down

0 comments on commit 2127647

Please sign in to comment.