|
1 | 1 | # Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | 2 | # Licensed under the MIT License.
|
3 | 3 |
|
| 4 | +import copy |
4 | 5 | import aiounittest
|
5 | 6 | from botbuilder.dialogs.prompts import (
|
6 | 7 | AttachmentPrompt,
|
7 | 8 | PromptOptions,
|
8 | 9 | PromptValidatorContext,
|
9 | 10 | )
|
10 |
| -from botbuilder.schema import Activity, ActivityTypes, Attachment |
| 11 | +from botbuilder.schema import Activity, ActivityTypes, Attachment, InputHints |
11 | 12 |
|
12 | 13 | from botbuilder.core import (
|
13 | 14 | TurnContext,
|
@@ -71,6 +72,42 @@ async def exec_test(turn_context: TurnContext):
|
71 | 72 | step3 = await step2.send(attachment_activity)
|
72 | 73 | await step3.assert_reply("some content")
|
73 | 74 |
|
| 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 | + |
74 | 111 | async def test_attachment_prompt_with_validator(self):
|
75 | 112 | async def exec_test(turn_context: TurnContext):
|
76 | 113 | dialog_context = await dialogs.create_context(turn_context)
|
|
0 commit comments