Skip to content

Commit 3612c05

Browse files
denscollosantgr11ceciliaavila
authored
[#1670][Dialogs] Remove hardcoded InputHint for AttachmentPrompt (#1671)
* Remove input hint set in attachment prompts * Add attachment prompt input hint test * Apply black styling * Apply pylint Co-authored-by: Santiago Grangetto <santiago.grangetto@southworks.com> Co-authored-by: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com>
1 parent 85ec376 commit 3612c05

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from typing import Callable, Dict
55

6-
from botbuilder.schema import ActivityTypes, InputHints
6+
from botbuilder.schema import ActivityTypes
77
from botbuilder.core import TurnContext
88

99
from .prompt import Prompt, PromptValidatorContext
@@ -39,10 +39,8 @@ async def on_prompt(
3939
)
4040

4141
if is_retry and options.retry_prompt:
42-
options.retry_prompt.input_hint = InputHints.expecting_input
4342
await turn_context.send_activity(options.retry_prompt)
4443
elif options.prompt:
45-
options.prompt.input_hint = InputHints.expecting_input
4644
await turn_context.send_activity(options.prompt)
4745

4846
async def on_recognize(

libraries/botbuilder-dialogs/tests/test_attachment_prompt.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
import copy
45
import aiounittest
56
from botbuilder.dialogs.prompts import (
67
AttachmentPrompt,
78
PromptOptions,
89
PromptValidatorContext,
910
)
10-
from botbuilder.schema import Activity, ActivityTypes, Attachment
11+
from botbuilder.schema import Activity, ActivityTypes, Attachment, InputHints
1112

1213
from botbuilder.core import (
1314
TurnContext,
@@ -71,6 +72,42 @@ async def exec_test(turn_context: TurnContext):
7172
step3 = await step2.send(attachment_activity)
7273
await step3.assert_reply("some content")
7374

75+
async def test_attachment_prompt_with_input_hint(self):
76+
prompt_activity = Activity(
77+
type=ActivityTypes.message,
78+
text="please add an attachment.",
79+
input_hint=InputHints.accepting_input,
80+
)
81+
82+
async def exec_test(turn_context: TurnContext):
83+
dialog_context = await dialogs.create_context(turn_context)
84+
85+
results = await dialog_context.continue_dialog()
86+
87+
if results.status == DialogTurnStatus.Empty:
88+
options = PromptOptions(prompt=copy.copy(prompt_activity))
89+
await dialog_context.prompt("AttachmentPrompt", options)
90+
elif results.status == DialogTurnStatus.Complete:
91+
attachment = results.result[0]
92+
content = MessageFactory.text(attachment.content)
93+
await turn_context.send_activity(content)
94+
95+
await convo_state.save_changes(turn_context)
96+
97+
# Initialize TestAdapter.
98+
adapter = TestAdapter(exec_test)
99+
100+
# Create ConversationState with MemoryStorage and register the state as middleware.
101+
convo_state = ConversationState(MemoryStorage())
102+
103+
# Create a DialogState property, DialogSet and AttachmentPrompt.
104+
dialog_state = convo_state.create_property("dialog_state")
105+
dialogs = DialogSet(dialog_state)
106+
dialogs.add(AttachmentPrompt("AttachmentPrompt"))
107+
108+
step1 = await adapter.send("hello")
109+
await step1.assert_reply(prompt_activity)
110+
74111
async def test_attachment_prompt_with_validator(self):
75112
async def exec_test(turn_context: TurnContext):
76113
dialog_context = await dialogs.create_context(turn_context)

0 commit comments

Comments
 (0)