Skip to content
This repository was archived by the owner on Jun 8, 2022. It is now read-only.

Commit 3905577

Browse files
authored
Add support for action of type message_action (#40)
1 parent 74d3ab8 commit 3905577

File tree

6 files changed

+65
-8
lines changed

6 files changed

+65
-8
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ Changelog
7373
dev
7474
```
7575

76+
0.4.2
77+
`````
78+
79+
* Support incoming action of type ``message_action``
80+
81+
7682
0.4.1
7783
`````
7884

slack/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Version information
22

3-
__version__ = "0.4.1"
3+
__version__ = "0.4.2"

slack/actions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class Action(MutableMapping):
1111
"""
12-
MutableMapping representing a response to an interactive message.
12+
MutableMapping representing a response to an interactive message, a dialog submission or a message action.
1313
1414
Args:
1515
raw_action: Decoded body of the HTTP request
@@ -99,12 +99,12 @@ def dispatch(self, action):
9999

100100
if action["type"] == "interactive_message":
101101
yield from self._dispatch_interactive_message(action)
102-
elif action["type"] == "dialog_submission":
103-
yield from self._dispatch_dialog_submission(action)
102+
elif action["type"] in ("dialog_submission", "message_action"):
103+
yield from self._dispatch_action(action)
104104
else:
105105
raise exceptions.UnknownActionType(action)
106106

107-
def _dispatch_dialog_submission(self, action):
107+
def _dispatch_action(self, action):
108108
yield from self._routes[action["callback_id"]].get("*", [])
109109

110110
def _dispatch_interactive_message(self, action):

slack/tests/conftest.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ def message_router():
174174

175175

176176
@pytest.fixture(
177-
params={**data.InteractiveMessage.__members__, **data.DialogSubmission.__members__}
177+
params={
178+
**data.InteractiveMessage.__members__,
179+
**data.DialogSubmission.__members__,
180+
**data.MessageAction.__members__,
181+
}
178182
)
179183
def action(request):
180184
return Action.from_http(raw_action(request))
@@ -190,15 +194,31 @@ def dialog_submission(request):
190194
return Action.from_http(raw_action(request))
191195

192196

197+
@pytest.fixture(params={**data.MessageAction.__members__})
198+
def message_action(request):
199+
return Action.from_http(raw_action(request))
200+
201+
193202
@pytest.fixture(
194-
params={**data.InteractiveMessage.__members__, **data.DialogSubmission.__members__}
203+
params={
204+
**data.InteractiveMessage.__members__,
205+
**data.DialogSubmission.__members__,
206+
**data.MessageAction.__members__,
207+
}
195208
)
196209
def raw_action(request):
197210
if isinstance(request.param, str):
198211
try:
199212
return copy.deepcopy(data.InteractiveMessage[request.param].value)
200213
except KeyError:
214+
pass
215+
216+
try:
201217
return copy.deepcopy(data.DialogSubmission[request.param].value)
218+
except KeyError:
219+
pass
220+
221+
return copy.deepcopy(data.MessageAction[request.param].value)
202222
else:
203223
return copy.deepcopy(request.param)
204224

slack/tests/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .events import Events, Messages, RTMEvents # noQa F401
2-
from .actions import DialogSubmission, InteractiveMessage # noQa F401
2+
from .actions import MessageAction, DialogSubmission, InteractiveMessage # noQa F401
33
from .methods import Methods # noQa F401
44
from .commands import Commands # noQa F401

slack/tests/data/actions.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,30 @@
4545
"response_url": "https://hooks.slack.com/actions/T000AAA0A/123456789123/YTC81HsJRuuGSLVFbSnlkJlh",
4646
}
4747

48+
message_action = {
49+
"type": "message_action",
50+
"token": "supersecuretoken",
51+
"action_ts": "987654321.000001",
52+
"team": {"id": "T000AAA0A", "domain": "team"},
53+
"user": {"id": "U000AA000", "name": "username"},
54+
"channel": {"id": "C00000A00", "name": "general"},
55+
"callback_id": "test_action",
56+
"trigger_id": "418799722116.77329528181.9c7441638716b0b9b698f3d8ae73d9c1",
57+
"message_ts": "1534605601.000100",
58+
"message": {
59+
"type": "message",
60+
"user": "U000AA000",
61+
"text": "test message",
62+
"client_msg_id": "904f281d-338e-4621-a56f-afbfc80b3c59",
63+
"ts": "1534605601.000100",
64+
},
65+
"response_url": "https://hooks.slack.com/actions/T000AAA0A/123456789123/YTC81HsJRuuGSLVFbSnlkJlh",
66+
}
67+
4868
raw_button_ok = {"payload": json.dumps(button_ok)}
4969
raw_button_cancel = {"payload": json.dumps(button_cancel)}
5070
raw_dialog_submission = {"payload": json.dumps(dialog_submission)}
71+
raw_message_action = {"payload": json.dumps(message_action)}
5172

5273

5374
class InteractiveMessage(Enum):
@@ -72,3 +93,13 @@ class DialogSubmission(Enum):
7293
"""
7394

7495
dialog_submission = raw_dialog_submission
96+
97+
98+
class MessageAction(Enum):
99+
"""
100+
List of available message action submission for testing
101+
102+
- action
103+
"""
104+
105+
action = raw_message_action

0 commit comments

Comments
 (0)