Skip to content

Commit ad56e0f

Browse files
lilyydulilydu
andauthored
[cards]: additional actions (#111)
closes: #57 adds in the remaining actions for cards package, matching C# --------- Co-authored-by: lilydu <[email protected]>
1 parent e6c426c commit ad56e0f

File tree

12 files changed

+162
-0
lines changed

12 files changed

+162
-0
lines changed

packages/cards/src/microsoft/teams/cards/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
Licensed under the MIT License.
44
"""
55

6+
from . import actions
7+
from .actions import * # noqa: F403
68
from .core import *
9+
10+
# Combine all exports from submodules
11+
__all__: list[str] = []
12+
__all__.extend(actions.__all__)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from .im_back_action import IMBackAction
7+
from .invoke_action import InvokeAction
8+
from .message_back_action import MessageBackAction
9+
from .sign_in_action import SignInAction
10+
from .task_fetch_action import TaskFetchAction
11+
12+
__all__ = ["IMBackAction", "MessageBackAction", "SignInAction", "InvokeAction", "TaskFetchAction"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from ..core import ImBackSubmitActionData, SubmitAction, SubmitActionData
7+
8+
9+
class IMBackAction(SubmitAction):
10+
"""Initial data that input fields will be combined with. These are essentially ‘hidden’ properties."""
11+
12+
def __init__(self, value: str):
13+
super().__init__()
14+
action_data = ImBackSubmitActionData().with_value(value)
15+
self.data = SubmitActionData(ms_teams=action_data.model_dump())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from typing import Any, Dict
7+
8+
from ..core import InvokeSubmitActionData, SubmitAction, SubmitActionData
9+
10+
11+
class InvokeAction(SubmitAction):
12+
def __init__(self, value: Dict[str, Any]):
13+
super().__init__()
14+
action_data = InvokeSubmitActionData().with_value(value)
15+
self.data = SubmitActionData(ms_teams=action_data.model_dump())
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from typing import Optional
7+
8+
from ..core import MessageBackSubmitActionData, SubmitAction, SubmitActionData
9+
10+
11+
class MessageBackAction(SubmitAction):
12+
def __init__(self, text: str, value: str, display_text: Optional[str] = None):
13+
super().__init__()
14+
action_data = MessageBackSubmitActionData().with_value(value).with_text(text)
15+
16+
if display_text:
17+
action_data = action_data.with_display_text(display_text)
18+
19+
self.data = SubmitActionData(ms_teams=action_data.model_dump())
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from ..core import SigninSubmitActionData, SubmitAction, SubmitActionData
7+
8+
9+
class SignInAction(SubmitAction):
10+
def __init__(self, value: str):
11+
super().__init__()
12+
action_data = SigninSubmitActionData().with_value(value)
13+
self.data = SubmitActionData(ms_teams=action_data.model_dump())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from typing import Any, Dict
7+
8+
from ..core import SubmitAction, SubmitActionData, TaskFetchSubmitActionData
9+
10+
11+
class TaskFetchAction(SubmitAction):
12+
def __init__(self, value: Dict[str, Any]):
13+
super().__init__()
14+
action_data = TaskFetchSubmitActionData().with_value(value)
15+
self.data = SubmitActionData(ms_teams=action_data.model_dump())
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from microsoft.teams.cards import IMBackAction, SubmitActionData
7+
8+
9+
def test_im_back_action_initialization():
10+
action = IMBackAction(value="Test Value")
11+
assert isinstance(action.data, SubmitActionData)
12+
assert action.data.ms_teams is not None
13+
assert action.data.ms_teams["value"] == "Test Value"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from microsoft.teams.cards import InvokeAction, SubmitActionData
7+
8+
9+
def test_invoke_action_initialization():
10+
action = InvokeAction({"test": "Test Value"})
11+
assert isinstance(action.data, SubmitActionData)
12+
assert action.data.ms_teams is not None
13+
assert action.data.ms_teams["value"]["test"] == "Test Value"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from microsoft.teams.cards import MessageBackAction, SubmitActionData
7+
8+
9+
def test_message_back_action_initialization():
10+
action = MessageBackAction(text="Message Back Test", value="Test Value", display_text="Test Text")
11+
assert isinstance(action.data, SubmitActionData)
12+
assert action.data.ms_teams is not None
13+
assert action.data.ms_teams["value"] == "Test Value"
14+
assert action.data.ms_teams["text"] == "Message Back Test"
15+
assert action.data.ms_teams["displayText"] == "Test Text"

0 commit comments

Comments
 (0)