【发布时间】:2020-11-07 19:04:51
【问题描述】:
在使用 WaterfallDialog 的对话框期间,我希望通过允许用户从选择器中进行选择来提示用户输入 DateTime。 DateTimePrompt 的提示只等待用户提交代表 DateTime 的字符串。 :(
我宁愿拥有一个 DateTimePickerPrompt,机器人在其中发送日历,用户可以从中选择。那根本不存在。
阅读后:https://blog.botframework.com/2019/07/02/using-adaptive-cards-with-the-microsoft-bot-framework/。我希望这是一种能力。特别是部分:“对话框中的自适应卡片”。
这是我尝试过的: 自适应卡片json
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Select Start Date and Time."
},
{
"type": "Input.Date",
"id": "start_date",
"placeholder": "Enter a date"
},
{
"type": "Input.Time",
"id": "start_time",
"placeholder": "Enter a time"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK",
"data": {
"key": "still replies with nothing given document says only object types can be returned"
}
}
]
}
瀑布日期时间步长法
def _create_adaptive_card_attachment(self) -> Attachment:
"""
Load a random adaptive card attachment from file.
:return:
"""
card_path = os.path.join(os.getcwd(), 'resources/datetime_picker.json')
with open(card_path, "rb") as in_file:
card_data = json.load(in_file)
return CardFactory.adaptive_card(card_data)
async def waterfall_start_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
prompt_options = PromptOptions(
prompt=MessageFactory.attachment(
self._create_adaptive_card_attachment()
),
choices=[Choice("0"), Choice("1")],
style=ListStyle.none
)
return await step_context.prompt(
TextPrompt.__name__,
prompt_options
)
由于 DialogTurnResult.result == None,这被设置为无限循环。
此外,step_context.context.activity 确实表示有响应,但值为 None。
{
'additional_properties': {},
'type': 'message',
'id': '68c3f2f0-c881-11ea-827f-25034e37bd5f',
'timestamp': datetime.datetime(2020, 7, 17, 23, 1, 12, 223000, tzinfo=<isodate.tzinfo.Utc object at 0x10b39b9e8>),
'local_timestamp': datetime.datetime(2020, 7, 17, 18, 1, 12, tzinfo=<FixedOffset '-09:00'>),
'local_timezone': None,
'service_url': 'http://localhost:60945',
'channel_id': 'emulator',
'from_property': <botbuilder.schema._models_py3.ChannelAccount object at 0x10c0d9b38>,
'conversation': <botbuilder.schema._models_py3.ConversationAccount object at 0x10c0d9ac8>,
'recipient': <botbuilder.schema._models_py3.ChannelAccount object at 0x10c0fc240>,
'text_format': 'plain',
'attachment_layout': None,
'members_added': None,
'members_removed': None,
'reactions_added': None,
'reactions_removed': None,
'topic_name': None,
'history_disclosed': None,
'locale': 'en-US',
'text': 'asdg',
'speak': None,
'input_hint': None,
'summary': None,
'suggested_actions': None,
'attachments': None,
'entities': None,
'channel_data':
{
'clientActivityID': '1595026872220mnbwlxl2k5',
'clientTimestamp': '2020-07-17T23:01:12.220Z'
},
'action': None,
'reply_to_id': None,
'label': None,
'value_type': None,
'value': None,
'name': None,
'relates_to': None,
'code': None,
'expiration': None,
'importance': None,
'delivery_mode': None,
'listen_for': None,
'text_highlights': None,
'semantic_action': None,
'caller_id': None
}
我的“第二次”尝试使用相同的 _create_adaptive_card_attachment 方法:
async def waterfall_start_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
message = Activity(
text = "Here is an Adaptive Card:",
type = ActivityTypes.message,
attachments = [self._create_adaptive_card_attachment()],
)
await step_context.context.send_activity(message)
return DialogTurnResult(status=DialogTurnStatus.Empty,result={})
这会返回相同的上下文活动。
我看到一个非常相似的问题:How to retrieve Adaptive Card's form submission in subsequent waterfall step
C# 中的这个逻辑似乎是文档中描述的内容。我相信我在 python 中实现了这一点。但我似乎遗漏了什么。
因此,如果文档属实,那么我应该能够从自适应卡片提交操作中获取数据。这里的任何帮助都会很棒。感谢您的时间和精力。
【问题讨论】:
-
欢迎来到 Stack Overflow。你的问题是什么?请查看方便的指南,了解您可以采取哪些步骤来更快地获得更好的答案:stackoverflow.com/help/how-to-ask
-
另外,你用的是什么渠道?
-
你还在做这个吗?
标签: python botframework