Skip to content

[#1670][Dialogs] Remove hardcoded InputHint for AttachmentPrompt #1671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Callable, Dict

from botbuilder.schema import ActivityTypes, InputHints
from botbuilder.schema import ActivityTypes
from botbuilder.core import TurnContext

from .prompt import Prompt, PromptValidatorContext
Expand Down Expand Up @@ -39,10 +39,8 @@ async def on_prompt(
)

if is_retry and options.retry_prompt:
options.retry_prompt.input_hint = InputHints.expecting_input
await turn_context.send_activity(options.retry_prompt)
elif options.prompt:
options.prompt.input_hint = InputHints.expecting_input
await turn_context.send_activity(options.prompt)

async def on_recognize(
Expand Down
39 changes: 38 additions & 1 deletion libraries/botbuilder-dialogs/tests/test_attachment_prompt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import copy
import aiounittest
from botbuilder.dialogs.prompts import (
AttachmentPrompt,
PromptOptions,
PromptValidatorContext,
)
from botbuilder.schema import Activity, ActivityTypes, Attachment
from botbuilder.schema import Activity, ActivityTypes, Attachment, InputHints

from botbuilder.core import (
TurnContext,
Expand Down Expand Up @@ -71,6 +72,42 @@ async def exec_test(turn_context: TurnContext):
step3 = await step2.send(attachment_activity)
await step3.assert_reply("some content")

async def test_attachment_prompt_with_input_hint(self):
prompt_activity = Activity(
type=ActivityTypes.message,
text="please add an attachment.",
input_hint=InputHints.accepting_input,
)

async def exec_test(turn_context: TurnContext):
dialog_context = await dialogs.create_context(turn_context)

results = await dialog_context.continue_dialog()

if results.status == DialogTurnStatus.Empty:
options = PromptOptions(prompt=copy.copy(prompt_activity))
await dialog_context.prompt("AttachmentPrompt", options)
elif results.status == DialogTurnStatus.Complete:
attachment = results.result[0]
content = MessageFactory.text(attachment.content)
await turn_context.send_activity(content)

await convo_state.save_changes(turn_context)

# Initialize TestAdapter.
adapter = TestAdapter(exec_test)

# Create ConversationState with MemoryStorage and register the state as middleware.
convo_state = ConversationState(MemoryStorage())

# Create a DialogState property, DialogSet and AttachmentPrompt.
dialog_state = convo_state.create_property("dialog_state")
dialogs = DialogSet(dialog_state)
dialogs.add(AttachmentPrompt("AttachmentPrompt"))

step1 = await adapter.send("hello")
await step1.assert_reply(prompt_activity)

async def test_attachment_prompt_with_validator(self):
async def exec_test(turn_context: TurnContext):
dialog_context = await dialogs.create_context(turn_context)
Expand Down