在使用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正确地实现了这一点。但我似乎遗漏了什么。
因此,如果文档是真的,那么我应该能够从一个自适应卡提交操作中获得数据。这里的任何帮助都是很好的。感谢您的时间和努力。
发布于 2020-08-10 09:07:54
我也在做同样的事情,但是我有一个表单而不是按钮。我遵循了您所指出的blog和C#答案。卡片渲染的实现是正确的。但是,我们需要将活动的文本设置为提示可以视为结果的内容,而不是None或空值。
async def on_turn(self, turn_context: TurnContext):
if turn_context.activity.type == 'message':
if turn_context.activity.text == None and turn_context.activity.value != None:
turn_context.activity.text = json.dumps(turn_context.activity.value)
await super().on_turn(turn_context)
# Save any state changes that might have occurred during the turn.
await self.conversation_state.save_changes(turn_context, False)
await self.user_state.save_changes(turn_context, False)
使用来自自适应卡输入的值更新文本后,这些值将在下一步中作为step_context.result
可用。您将能够处理其中的值。请注意,在超前放置值检查的位置很重要。
https://stackoverflow.com/questions/62963036
复制相似问题