[英]Microsoft Bot Framework Python During a WaterfallStepContext using adaptive card attachment get submit value from adaptive card action
在使用 WaterfallDialog 的對話框期間,我希望通過允許用戶從選擇器中進行選擇來提示用戶輸入日期時間。 DateTimePrompt 的提示只等待用戶提交代表 DateTime 的字符串。 :(
我寧願擁有一個 DateTimePickerPrompt ,其中 Bot 發送日歷,用戶可以從中獲取 select 。 那是不存在的。
閱讀后: 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={})
這將返回相同的上下文活動。
我看到一個非常相似的問題: 如何在后續瀑布步驟中檢索自適應卡的表單提交
C# 中的這個邏輯似乎是文檔中描述的內容。 我相信我在 python 中實現了這一權利。 但我似乎錯過了一些東西。
因此,如果文檔屬實,那么我應該能夠從自適應卡片提交操作中獲取數據。 這里的任何幫助都會很棒。 感謝您的時間和精力。
我正在做同樣的事情,但我有一個表單而不是按鈕。 我已經關注了您指出的博客和 C# 答案。 卡片渲染的實現是正確的。 但是,我們需要將活動的文本設置為 Prompt 可以查看的結果,而不是 None 或 Blank 值。
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
提供。 您將能夠處理其中的值。 請注意,position 的放置前的超值檢查很重要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.