-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
from botbuilder.core import ActivityHandler, ConversationState, TurnContext, UserState | ||
from botbuilder.dialogs import Dialog | ||
from helpers.dialog_helper import DialogHelper | ||
|
||
|
||
class DialogBot(ActivityHandler): | ||
""" | ||
This Bot implementation can run any type of Dialog. The use of type parameterization is to allows multiple | ||
different bots to be run at different endpoints within the same project. This can be achieved by defining distinct | ||
Controller types each with dependency on distinct Bot types. The ConversationState is used by the Dialog system. The | ||
UserState isn't, however, it might have been used in a Dialog implementation, and the requirement is that all | ||
BotState objects are saved at the end of a turn. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
conversation_state: ConversationState, | ||
user_state: UserState, | ||
dialog: Dialog, | ||
): | ||
if conversation_state is None: | ||
raise TypeError( | ||
"[DialogBot]: Missing parameter. conversation_state is required but None was given" | ||
) | ||
if user_state is None: | ||
raise TypeError( | ||
"[DialogBot]: Missing parameter. user_state is required but None was given" | ||
) | ||
if dialog is None: | ||
raise Exception("[DialogBot]: Missing parameter. dialog is required") | ||
|
||
self.conversation_state = conversation_state | ||
self.user_state = user_state | ||
self.dialog = dialog | ||
|
||
async def on_turn(self, turn_context: TurnContext): | ||
await super().on_turn(turn_context) | ||
|
||
# Save any state changes that might have ocurred during the turn. | ||
await self.conversation_state.save_changes(turn_context) | ||
await self.user_state.save_changes(turn_context) | ||
|
||
async def on_message_activity(self, turn_context: TurnContext): | ||
await DialogHelper.run_dialog( | ||
self.dialog, | ||
turn_context, | ||
self.conversation_state.create_property("DialogState"), | ||
) |