Skip to content

Commit 4f3c798

Browse files
committed
working version w/ all features from v1.1
1 parent 6fc2cc3 commit 4f3c798

File tree

9 files changed

+548
-0
lines changed

9 files changed

+548
-0
lines changed

webexteamssdk/cards/__init__.py

Whitespace-only changes.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from abc import ABC, abstractmethod
2+
import json
3+
4+
class Serializable:
5+
"""Parent class to
6+
7+
"""
8+
def __init__(self, serializable_properties, simple_properties):
9+
self.serializable_properties = serializable_properties
10+
self.simple_properties = simple_properties
11+
12+
def to_json(self, pretty=False):
13+
ret = None
14+
if pretty:
15+
ret = json.dumps(self.to_dict(), indent=4, sort_keys=True)
16+
else:
17+
ret = json.dumps(self.to_dict())
18+
19+
return ret
20+
21+
def to_dict(self):
22+
"""Export a dictionary representation of this card/component by
23+
parsing all simple and serializable properties.
24+
25+
A simple_component is a single-text property of the exported card
26+
(i.e. {'version': "1.2"}) while a serializable property is another
27+
subcomponent that also implements a to_dict() method.
28+
29+
Returns:
30+
dict: Dictionary representation of this component.
31+
"""
32+
export = {}
33+
34+
# Export simple properties (i.e. properties that are only single text)
35+
for sp in self.simple_properties:
36+
o = getattr(self, sp, None)
37+
38+
if o is not None:
39+
export[sp] = str(o)
40+
41+
# Export all complex properties by calling its respective serialization
42+
for cp in self.serializable_properties:
43+
o = getattr(self, cp, None)
44+
45+
if o is not None:
46+
# Check if it is a list or a single component
47+
l = []
48+
if isinstance(o, list):
49+
for i in o:
50+
l.append(i.to_dict())
51+
else:
52+
l.append(o.to_dict())
53+
export[cp] = l
54+
55+
return export
56+
57+
class Component:
58+
def __init__(self, component_type):
59+
self.component_type = component_type
60+
61+
def get_type(self):
62+
return self.component_type

webexteamssdk/cards/actions.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from .abstract_components import Serializable
2+
3+
class OpenUrl(Serializable):
4+
def __init__(self, url, title=None,
5+
iconURL=None):
6+
self.type = "Action.OpenUrl"
7+
self.title = title
8+
self.iconURL = iconURL
9+
10+
super().__init__(serializable_properties=[],
11+
simple_properties=['type', 'title', 'iconURL'])
12+
13+
class Submit(Serializable):
14+
def __init__(self, data=None,
15+
title=None,
16+
iconURL=None,
17+
):
18+
self.type = "Action.Submit"
19+
self.data = data
20+
self.title = title
21+
self.iconURL = iconURL
22+
23+
super().__init__(serializable_properties=['data'],
24+
simple_properties=['title', 'iconURL', 'type'])
25+
26+
class ShowCard(Serializable):
27+
def __init__(self, card=None,
28+
title=None,
29+
iconURL=None):
30+
self.type = "Action.ShowCard"
31+
self.card = card
32+
self.title = title
33+
self.iconURL = iconURL
34+
35+
super().__init__(serializable_properties=['card'],
36+
simple_properties=['title', 'type', 'iconURL'])

webexteamssdk/cards/card.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .abstract_components import Serializable, Component
2+
3+
class AdaptiveCard(Serializable):
4+
def __init__(self, body=None,
5+
actions=None,
6+
selectAction=None,
7+
style=None,
8+
fallbackText=None,
9+
lang=None):
10+
super().__init__(serializable_properties=['body', 'actions', 'selectAction', 'style'],
11+
simple_properties=['version', 'fallbackText', 'lang', 'schema', 'type'])
12+
13+
# Set properties
14+
self.type = "AdaptiveCard"
15+
self.version = "1.1" # This is the version currently supported in Teams
16+
self.body = body
17+
self.actions = actions
18+
self.selectAction = selectAction
19+
self.style = style
20+
self.fallbackText = fallbackText
21+
self.lang = lang
22+
self.schema = "http://adaptivecards.io/schemas/adaptive-card.json"

webexteamssdk/cards/components.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
from .abstract_components import Serializable
2+
3+
class MediaSource(Serializable):
4+
def __init__(self,
5+
mimeType,
6+
url):
7+
self.mimeType = mimeType
8+
self.url = url
9+
10+
super().__init__(serializable_properties=[],
11+
simple_properties=['mimeType', 'url'])
12+
13+
class Media(Serializable):
14+
def __init__(self,
15+
sources,
16+
poster=None,
17+
altText=None,
18+
height=None,
19+
separator=None,
20+
spacing=None,
21+
id=None):
22+
self.type = "Media"
23+
self.sources = sources #Needs to be a list of media sources
24+
self.poster = poster
25+
self.altText = altText
26+
self.height = height
27+
self.separator = separator
28+
self.spacing = spacing
29+
self.id = id
30+
31+
super().__init__(serializable_properties=['sources'],
32+
simple_properties=[
33+
'type', 'poster', 'altText', 'height',
34+
'separator', 'spacing', 'id'
35+
])
36+
class Image(Serializable):
37+
def __init__(self,
38+
url,
39+
altText=None,
40+
backgroundColor=None,
41+
height=None,
42+
horizontalAlignment=None,
43+
selectAction=None,
44+
size=None,
45+
style=None,
46+
width=None,
47+
seperator=None,
48+
spacing=None,
49+
id=None):
50+
51+
self.type = "Image"
52+
self.url = url
53+
self.altText = altText
54+
self.backgroundColor = backgroundColor
55+
self.height = height
56+
self.horizontalAlignment = horizontalAlignment
57+
self.selectAction = selectAction
58+
self.size = size
59+
self.style = style
60+
self.width = width
61+
self.seperator = seperator
62+
self.spacing = spacing
63+
self.id = id
64+
65+
super().__init__(serializable_properties=[],
66+
simple_properties=[
67+
'type', 'url', 'altText', 'backgroundColor',
68+
'height', 'horizontalAlignment', 'selectAction',
69+
'size', 'style', 'width', 'separator', 'spacing',
70+
'id'
71+
])
72+
class TextBlock(Serializable):
73+
def __init__(self,
74+
text,
75+
color=None,
76+
horizontalAlignment=None,
77+
isSubtle=None,
78+
maxLines=None,
79+
size=None,
80+
weight=None,
81+
wrap=None,
82+
separator=None,
83+
spacing=None,
84+
id=None):
85+
86+
87+
#ToDo(mneiding): Type check
88+
self.type = "TextBlock"
89+
self.text = text
90+
self.color = color
91+
self.horizontalAlignment = horizontalAlignment
92+
self.isSubtle = isSubtle
93+
self.maxLines = maxLines
94+
self.size = size
95+
self.weight = weight
96+
self.wrap = wrap
97+
self.separator = separator
98+
self.spacing = spacing
99+
self.id = id
100+
101+
super().__init__(serializable_properties=[],
102+
simple_properties=[
103+
'type', 'text', 'color', 'horizontalAlignment',
104+
'isSubtle', 'maxLines', 'size', 'weight', 'wrap',
105+
'spacing', 'id', 'separator'
106+
])
107+
class Column(Serializable):
108+
def __init__(self, items=None,
109+
separator=None,
110+
spacing=None,
111+
selectAction=None,
112+
style=None,
113+
verticalContentAlignment=None,
114+
width=None,
115+
id=None):
116+
self.type = "Column"
117+
self.items = items
118+
self.separator = separator
119+
self.spacing = spacing
120+
self.selectAction = selectAction
121+
self.style = style
122+
self.verticalContentAlignment = verticalContentAlignment
123+
self.width = width
124+
self.id = id
125+
126+
super().__init__(serializable_properties=['items'],
127+
simple_properties=[
128+
'type', 'separator', 'spacing', 'selectAction',
129+
'style', 'verticalContentAlignment', 'width', 'id'
130+
])
131+
132+
class Fact(Serializable):
133+
def __init__(self, title, value):
134+
self.title = title
135+
self.value = value
136+
137+
super().__init__(serializable_properties=[],
138+
simple_properties=['title', 'value'])
139+
140+
class Choice(Serializable):
141+
def __init__(self, title, value):
142+
self.title = title
143+
self.value = value
144+
145+
super().__init__(serializable_properties=[],
146+
simple_properties=['title', 'value'])

webexteamssdk/cards/container.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from .abstract_components import Serializable
2+
3+
class Container(Serializable):
4+
def __init__(self, items, selectAction=None,
5+
style=None,
6+
verticalContentAlignment=None,
7+
height=None,
8+
separator=None,
9+
spacing=None,
10+
id=None):
11+
self.type = "Container"
12+
self.items = items
13+
self.selectAction = selectAction
14+
self.style = style
15+
self.verticalContentAlignment = verticalContentAlignment
16+
self.height = height
17+
self.separator = separator
18+
self.spacing = spacing
19+
self.id = id
20+
21+
super().__init__(serializable_properties=['items'],
22+
simple_properties=[
23+
'selectAction', 'style', 'verticalContentAlignment',
24+
'height', 'separator', 'spacing', 'id', 'type'
25+
])
26+
27+
class ColumnSet(Serializable):
28+
def __init__(self, columns=None,
29+
selectAction=None,
30+
height=None,
31+
separator=None,
32+
spacing=None,
33+
id=None):
34+
self.type = "ColumnSet"
35+
self.columns = columns
36+
self.selectAction = selectAction
37+
self.height = height
38+
self.separator = separator
39+
self.spacing = spacing
40+
self.id = id
41+
42+
super().__init__(serializable_properties=['columns'],
43+
simple_properties=[
44+
'selectAction', 'height', 'separator', 'spacing',
45+
'id', 'type'
46+
])
47+
48+
class FactSet(Serializable):
49+
def __init__(self, facts, height=None,
50+
separator=None,
51+
spacing=None,
52+
id=None):
53+
self.type = "FactSet"
54+
self.facts = facts
55+
self.height = height
56+
self.separator = separator
57+
self.spacing = spacing
58+
self.id = id
59+
60+
super().__init__(serializable_properties=['facts'],
61+
simple_properties=[
62+
'type', 'height', 'separator', 'id', 'spacing'
63+
])
64+
65+
class ImageSet(Serializable):
66+
def __init__(self, images, imageSize=None,
67+
height=None,
68+
separator=None,
69+
spacing=None,
70+
id=None):
71+
self.type = "ImageSet"
72+
self.images = images
73+
self.imageSize = imageSize
74+
self.height = height
75+
self.separator = separator
76+
self.spacing = spacing
77+
self.id = id
78+
79+
super().__init__(serializable_properties=['images'],
80+
simple_properties=[
81+
'imageSize', 'height', 'separator', 'spacing', 'id',
82+
'type'
83+
])

0 commit comments

Comments
 (0)