8000 Merge branch 'master' into Zerryth/QnaParity · baruchiro/botbuilder-python@66e6a21 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66e6a21

Browse files
authored
Merge branch 'master' into Zerryth/QnaParity
2 parents 5a8a857 + 5f9ef03 commit 66e6a21

37 files changed

+148
-107
lines changed

libraries/botbuilder-applicationinsights/tests/test_telemetry_waterfall.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
DialogContext,
3131
DialogTurnStatus
3232
)
33-
from unittest.mock import patch, Mock
33+
from unittest.mock import patch
3434
from unittest import skip
3535

3636
begin_message = Activity()
@@ -46,7 +46,6 @@ def test_none_telemetry_client(self):
4646
# assert
4747
self.assertEqual(type(dialog.telemetry_client), NullTelemetryClient)
4848

49-
5049
@patch('botbuilder.applicationinsights.ApplicationInsightsTelemetryClient')
5150
async def test_execute_sequence_waterfall_steps(self, MockTelemetry):
5251
# arrange
@@ -71,7 +70,7 @@ async def step2(step) -> DialogTurnResult:
7170

7271
mydialog = WaterfallDialog('test', [ step1, step2 ])
7372
mydialog.telemetry_client = telemetry
74-
await dialogs.add(mydialog)
73+
dialogs.add(mydialog)
7574

7675
# Initialize TestAdapter
7776
async def exec_test(turn_context: TurnContext) -> None:
@@ -101,7 +100,6 @@ async def exec_test(turn_context: TurnContext) -> None:
101100
('WaterfallStep', {'DialogId':'test', 'StepName':'Step2of2'})
102101
]
103102
self.assert_telemetry_calls(telemetry, telemetry_calls)
104-
105103

106104
@patch('botbuilder.applicationinsights.ApplicationInsightsTelemetryClient')
107105
async def test_ensure_end_dialog_called(self, MockTelemetry):
@@ -127,7 +125,7 @@ async def step2(step) -> DialogTurnResult:
127125

128126
mydialog = WaterfallDialog('test', [ step1, step2 ])
129127
mydialog.telemetry_client = telemetry
130-
await dialogs.add(mydialog)
128+
dialogs.add(mydialog)
131129

132130
# Initialize TestAdapter
133131
async def exec_test(turn_context: TurnContext) -> None:
@@ -153,7 +151,8 @@ async def exec_test(turn_context: TurnContext) -> None:
153151
('WaterfallComplete', {'DialogId':'test'}),
154152
('WaterfallStart', {'DialogId':'test'}),
155153
('WaterfallStep', {'DialogId':'test', 'StepName':'Step1of2'}),
156-
]
154+
]
155+
print(str(telemetry.track_event.call_args_list))
157156
self.assert_telemetry_calls(telemetry, telemetry_calls)
158157

159158

libraries/botbuilder-core/botbuilder/core/activity_handler.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ async def on_turn(self, turn_context: TurnContext):
1818
if hasattr(turn_context.activity, 'type') and turn_context.activity.type is None:
1919
raise TypeError('ActivityHandler.on_turn(): turn_context activity must have a non-None type.')
2020

21-
return {
22-
ActivityTypes.message: await self.on_message_activity(turn_context),
23-
ActivityTypes.conversation_update: await self.on_conversation_update_activity(turn_context),
24-
ActivityTypes.event: await self.on_event_activity(turn_context)
25-
}.get(turn_context.activity.type, await self.on_unrecognized_activity_type(turn_context))
21+
if turn_context.activity.type == ActivityTypes.message:
22+
await self.on_message_activity(turn_context)
23+
elif turn_context.activity.type == ActivityTypes.conversation_update:
24+
await self.on_conversation_update_activity(turn_context)
25+
elif turn_context.activity.type == ActivityTypes.event:
26+
await self.on_event_activity(turn_context)
27+
else:
28+
await self.on_unrecognized_activity_type(turn_context)
2629

2730
async def on_message_activity(self, turn_context: TurnContext):
2831
return

libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async def send_activities(self, context: TurnContext, activities: List[Activity]
194194
await asyncio.sleep(delay_in_ms)
195195
else:
196196
client = self.create_connector_client(activity.service_url)
197-
await client.conversations.send_to_conversation(activity.conversation.id, activity)
197+
client.conversations.send_to_conversation(activity.conversation.id, activity)
198198
except Exception as e:
199199
raise e
200200

libraries/botbuilder-core/botbuilder/core/memory_storage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ async def write(self, changes: Dict[str, StoreItem]):
3434
try:
3535
# iterate over the changes
3636
for (key, change) in changes.items():
37-
#import pdb; pdb.set_trace()
3837
new_value = change
3938
old_state = None
4039
old_state_etag = None

libraries/botbuilder-dialogs/botbuilder/dialogs/choices/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
from .choice import Choice
1010
from .choice_factory_options import ChoiceFactoryOptions
1111
from .choice_factory import ChoiceFactory
12+
from .list_style import ListStyle
1213

13-
__all__ = ["Channel", "Choice", "ChoiceFactory", "ChoiceFactoryOptions"]
14+
__all__ = ["Channel", "Choice", "ChoiceFactory", "ChoiceFactoryOptions", "ListStyle"]

libraries/botbuilder-dialogs/botbuilder/dialogs/choices/choice_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def inline(
107107
)
108108

109109
@staticmethod
110-
def list(
110+
def list_style(
111111
choices: List[Choice],
112112
text: str = None,
113113
speak: str = None,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from enum import Enum
5+
6+
7+
class ListStyle(str, Enum):
8+
none = 0
9+
auto = 1
10+
in_line = 2
11+
list_style = 3
12+
suggested_action = 4
13+
hero_card = 5

libraries/botbuilder-dialogs/botbuilder/dialogs/component_dialog.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, dialog_id: str):
2626
raise TypeError('ComponentDialog(): dialog_id cannot be None.')
2727

2828
self._dialogs = DialogSet()
29+
self._initial_dialog_id = None
2930

3031
# TODO: Add TelemetryClient
3132

@@ -37,7 +38,7 @@ def initial_dialog_id(self) -> str:
3738
:param:
3839
:return str:ID of the dialog this instance is for.
3940
"""
40-
return self._id
41+
return self._initial_dialog_id
4142

4243
@initial_dialog_id.setter
4344
def initial_dialog_id(self, value: str) -> None:
@@ -46,7 +47,7 @@ def initial_dialog_id(self, value: str) -> None:
4647
:param value: ID of the dialog this instance is for.
4748
:return:
4849
"""
49-
self._id = value
50+
self._initial_dialog_id = value
5051

5152
async def begin_dialog(self, outer_dc: DialogContext, options: object = None) -> DialogTurnResult:
5253
if outer_dc is None:
@@ -131,10 +132,10 @@ def find_dialog(self, dialog_id: str ) -> Dialog:
131132

132133

133134
async def on_begin_dialog(self, inner_dc: DialogContext, options: object) -> DialogTurnResult:
134-
return inner_dc.begin_dialog(self.initial_dialog_id, options)
135+
return await inner_dc.begin_dialog(self.initial_dialog_id, options)
135136

136137
async def on_continue_dialog(self, inner_dc: DialogContext) -> DialogTurnResult:
137-
return inner_dc.continue_dialog()
138+
return await inner_dc.continue_dialog()
138139

139140
async def on_end_dialog(self, context: TurnContext, instance: DialogInstance, reason: DialogReason) -> None:
140141
return
@@ -143,4 +144,4 @@ async def on_reprompt_dialog(self, turn_context: TurnContext, instance: DialogIn
143144
return
144145

145146
async def end_component(self, outer_dc: DialogContext, result: object) -> DialogTurnResult:
146-
return outer_dc.end_dialog(result)
147+
return await outer_dc.end_dialog(result)

libraries/botbuilder-dialogs/botbuilder/dialogs/dialog.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .dialog_reason import DialogReason
77
from .dialog_turn_status import DialogTurnStatus
88
from .dialog_turn_result import DialogTurnResult
9+
from .dialog_instance import DialogInstance
910

1011

1112
class Dialog(ABC):
@@ -40,15 +41,15 @@ def telemetry_client(self, value: BotTelemetryClient) -> None:
4041
self._telemetry_client = value
4142

4243
@abstractmethod
43-
async def begin_dialog(self, dc, options: object = None):
44+
async def begin_dialog(self, dc: 'DialogContext', options: object = None):
4445
"""
4546
Method called when a new dialog has been pushed onto the stack and is being activated.
4647
:param dc: The dialog context for the current turn of conversation.
4748
:param options: (Optional) additional argument(s) to pass to the dialog being started.
4849
"""
4950
raise NotImplementedError()
5051

51-
async def continue_dialog(self, dc):
52+
async def continue_dialog(self, dc: 'DialogContext'):
5253
"""
5354
Method called when an instance of the dialog is the "current" dialog and the
5455
user replies with a new activity. The dialog will generally continue to receive the user's
@@ -60,7 +61,7 @@ async def continue_dialog(self, dc):
6061
# By default just end the current dialog.
6162
return await dc.end_dialog(None)
6263

63-
async def resume_dialog(self, dc, reason: DialogReason, result: object):
64+
async def resume_dialog(self, dc: 'DialogContext', reason: DialogReason, result: object):
6465
"""
6566
Method called when an instance of the dialog is being returned to from another
6667
dialog that was started by the current instance using `begin_dialog()`.
@@ -76,15 +77,15 @@ async def resume_dialog(self, dc, reason: DialogReason, result: object):
7677
return await dc.EndDialog(result)
7778

7879
# TODO: instance is DialogInstance
79-
async def reprompt_dialog(self, context: TurnContext, instance):
80+
async def reprompt_dialog(self, context: TurnContext, instance: DialogInstance):
8081
"""
8182
:param context:
8283
:return:
8384
"""
8485
# No-op by default
8586
return
8687
# TODO: instance is DialogInstance
87-
async def end_dialog(self, context: TurnContext, instance):
88+
async def end_dialog(self, context: TurnContext, instance: DialogInstance, reason: DialogReason):
8889
"""
8990
:param context:
9091
:return:

libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def begin_dialog(self, dialog_id: str, options: object = None):
103103
instance.id = dialog_id
104104
instance.state = {}
105105

106-
self._stack.append(instance)
106+
self._stack.insert(0,(instance))
107107

108108
# Call dialog's begin_dialog() method
109109
return await dialog.begin_dialog(self, options)
@@ -138,7 +138,7 @@ async def continue_dialog(self):
138138
# Look up dialog
139139
dialog = await self.find_dialog(self.active_dialog.id)
140140
if not dialog:
141-
raise Exception("DialogContext.continue_dialog(): Can't continue dialog. A dialog with an id of '%s' wasn't found." % active_dialog.id)
141+
raise Exception("DialogContext.continue_dialog(): Can't continue dialog. A dialog with an id of '%s' wasn't found." % self.active_dialog.id)
142142

143143
# Continue execution of dialog
144144
return await dialog.continue_dialog(self)
@@ -196,7 +196,7 @@ async def find_dialog(self, dialog_id: str) -> Dialog:
196196
dialog = await self.dialogs.find(dialog_id)
197197

198198
if (dialog == None and self.parent != None):
199-
dialog = self.parent.find_dialog(dialog_id)
199+
dialog = await self.parent.find_dialog(dialog_id)
200200
return dialog
201201

202202
async def replace_dialog(self, dialog_id: str, options: object = None) -> DialogTurnResult:
@@ -238,4 +238,4 @@ async def end_active_dialog(self, reason: DialogReason):
238238
await dialog.end_dialog(self.context, instance, reason)
239239

240240
# Pop dialog off stack
241-
self._stack.pop()
241+
self._stack.pop(0)

0 commit comments

Comments
 (0)
0