forked from OfficeDev/Microsoft-Teams-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adaptive_card_helper.py
118 lines (113 loc) · 3.85 KB
/
adaptive_card_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from botbuilder.core import CardFactory
from botbuilder.schema import Attachment
def create_adaptive_card_editor(
user_text: str = None,
is_multi_select: bool = False,
option1: str = None,
option2: str = None,
option3: str = None,
) -> Attachment:
return CardFactory.adaptive_card(
{
"actions": [
{
"data": {"submitLocation": "messagingExtensionFetchTask"},
"title": "Submit",
"type": "Action.Submit",
}
],
"body": [
{
"text": "This is an Adaptive Card within a Task Module",
"type": "TextBlock",
"weight": "bolder",
},
{"type": "TextBlock", "text": "Enter text for Question:"},
{
"id": "Question",
"placeholder": "Question text here",
"type": "Input.Text",
"value": user_text,
},
{"type": "TextBlock", "text": "Options for Question:"},
{"type": "TextBlock", "text": "Is Multi-Select:"},
{
"choices": [
{"title": "True", "value": "true"},
{"title": "False", "value": "false"},
],
"id": "MultiSelect",
"isMultiSelect": "false",
"style": "expanded",
"type": "Input.ChoiceSet",
"value": "true" if is_multi_select else "false",
},
{
"id": "Option1",
"placeholder": "Option 1 here",
"type": "Input.Text",
"value": option1,
},
{
"id": "Option2",
"placeholder": "Option 2 here",
"type": "Input.Text",
"value": option2,
},
{
"id": "Option3",
"placeholder": "Option 3 here",
"type": "Input.Text",
"value": option3,
},
],
"type": "AdaptiveCard",
"version": "1.0",
}
)
def create_adaptive_card_preview(
user_text: str = None,
is_multi_select: bool = False,
option1: str = None,
option2: str = None,
option3: str = None,
) -> Attachment:
return CardFactory.adaptive_card(
{
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"data": {"submitLocation": "messagingExtensionSubmit"},
}
],
"body": [
{
"text": "Adaptive Card from Task Module",
"type": "TextBlock",
"weight": "bolder",
},
{"text": user_text, "type": "TextBlock", "id": "Question"},
{
"id": "Answer",
"placeholder": "Answer here...",
"type": "Input.Text",
},
{
"choices": [
{"title": option1, "value": option1},
{"title": option2, "value": option2},
{"title": option3, "value": option3},
],
"id": "Choices",
"isMultiSelect": is_multi_select,
"style": "expanded",
"type": "Input.ChoiceSet",
},
],
"type": "AdaptiveCard",
"version": "1.0",
}
)