Skip to content

Commit 2ba97ae

Browse files
authored
[INTPROD-9639] Add reaction payload type support (#22)
1 parent cff469a commit 2ba97ae

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

.github/workflows/pull_request.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jobs:
55
steps:
66
- name: Checkout
77
uses: actions/checkout@v1
8-
- name: Setup python 3.8
8+
- name: Setup python 3.10.17
99
uses: actions/setup-python@v1
1010
with:
11-
python-version: 3.8
11+
python-version: 3.10.17
1212
- name: Install pre-commit
1313
run: pip install pre-commit
1414
- name: Run pre-commit
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
strategy:
1919
matrix:
20-
python-version: ['3.x']
20+
python-version: ['3.10.17']
2121
steps:
2222
- name: Checkout
2323
uses: actions/checkout@v1

.github/workflows/push.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v1
15-
- name: Setup python 3.8
15+
- name: Setup python 3.10.17
1616
uses: actions/setup-python@v1
1717
with:
18-
python-version: 3.8
18+
python-version: 3.10.17
1919
- name: Install virtualenv
2020
run: pip install virtualenv
2121
- name: Build docs
@@ -35,10 +35,10 @@ jobs:
3535
steps:
3636
- name: Checkout
3737
uses: actions/checkout@v1
38-
- name: Setup python 3.8
38+
- name: Setup python 3.10.17
3939
uses: actions/setup-python@v1
4040
with:
41-
python-version: 3.8
41+
python-version: 3.10.17
4242
- name: Add wheel dependency
4343
run: pip install wheel
4444
- name: Generate dist

omnibot_receiver/router.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def handle_event(self, event):
8585
]}
8686
"""
8787
omnibot_payload_type = event.get('omnibot_payload_type')
88-
if self.message_router and omnibot_payload_type == 'message':
88+
if (self.message_router and
89+
omnibot_payload_type in {'message', 'reaction'}):
8990
return self.message_router.handle_message(event)
9091
elif (self.interactive_router and
9192
omnibot_payload_type == 'interactive_component'):
@@ -258,7 +259,8 @@ def __init__(self, help='', help_as_default=True):
258259
self.default_route = None
259260
self.routes = {
260261
'command': [],
261-
'regex': []
262+
'regex': [],
263+
'reaction': [],
262264
}
263265

264266
@staticmethod
@@ -321,9 +323,11 @@ def add_message_rule(self, rule, match_type, route_func, help=''):
321323
match_type (str): The type of message this route should match
322324
against::
323325
324-
command -- Match against messages directed at this bot.
325-
regex -- Match against messages in a channel that have
326-
been targetted at this bot by omnibot.
326+
command -- Match against messages directed at this bot.
327+
regex -- Match against messages in a channel that have
328+
been targeted at this bot by omnibot.
329+
reaction -- Match against reactions towards items
330+
made by this bot.
327331
328332
route_func (function): The function to call when serving this route
329333
**kwargs (dict): Keyword arguments (see below for more info)

tests/unit/omnibot_receiver/router_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ def a_to_b(message, a, b):
244244
assert message_router.handle_message(message1) == 'a is 1, b is 2'
245245
assert message_router.handle_message(message2) == 'a is 1, b is 2 to 3'
246246

247+
def test_reaction_route(self):
248+
message = {'args': '+1', 'match_type': 'reaction'}
249+
message_router = OmnibotMessageRouter()
250+
251+
@message_router.route(r'\+1', match_type='reaction')
252+
def ping(message):
253+
return 'pong'
254+
255+
assert message_router.handle_message(message) == 'pong'
256+
247257

248258
class TestOmnibotInteractiveRouter(object):
249259

0 commit comments

Comments
 (0)