From 504d2b9b1e9971256c3739283d6af2cceacc0207 Mon Sep 17 00:00:00 2001 From: David Marchuk Date: Wed, 28 May 2025 16:27:01 -0700 Subject: [PATCH 1/3] [INTPROD-9639] Add reaction payload type support --- omnibot_receiver/router.py | 12 +++++++----- tests/unit/omnibot_receiver/router_test.py | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/omnibot_receiver/router.py b/omnibot_receiver/router.py index e98a51c..e826d92 100644 --- a/omnibot_receiver/router.py +++ b/omnibot_receiver/router.py @@ -85,7 +85,7 @@ def handle_event(self, event): ]} """ omnibot_payload_type = event.get('omnibot_payload_type') - if self.message_router and omnibot_payload_type == 'message': + if self.message_router and omnibot_payload_type == 'message' or omnibot_payload_type == 'reaction': return self.message_router.handle_message(event) elif (self.interactive_router and omnibot_payload_type == 'interactive_component'): @@ -258,7 +258,8 @@ def __init__(self, help='', help_as_default=True): self.default_route = None self.routes = { 'command': [], - 'regex': [] + 'regex': [], + 'reaction': [], } @staticmethod @@ -321,9 +322,10 @@ def add_message_rule(self, rule, match_type, route_func, help=''): match_type (str): The type of message this route should match against:: - command -- Match against messages directed at this bot. - regex -- Match against messages in a channel that have - been targetted at this bot by omnibot. + command -- Match against messages directed at this bot. + regex -- Match against messages in a channel that have + been targeted at this bot by omnibot. + reaction -- Match against reactions towards items made by this bot. route_func (function): The function to call when serving this route **kwargs (dict): Keyword arguments (see below for more info) diff --git a/tests/unit/omnibot_receiver/router_test.py b/tests/unit/omnibot_receiver/router_test.py index dd9a53e..edded32 100644 --- a/tests/unit/omnibot_receiver/router_test.py +++ b/tests/unit/omnibot_receiver/router_test.py @@ -244,6 +244,15 @@ def a_to_b(message, a, b): assert message_router.handle_message(message1) == 'a is 1, b is 2' assert message_router.handle_message(message2) == 'a is 1, b is 2 to 3' + def test_reaction_route(self): + message = {'args': '+1', 'match_type': 'reaction'} + message_router = OmnibotMessageRouter() + + @message_router.route(r'\+1', match_type='reaction') + def ping(message): + return 'pong' + + assert message_router.handle_message(message) == 'pong' class TestOmnibotInteractiveRouter(object): From f41558b87012e54ad1a2df2cb5e169c214541e08 Mon Sep 17 00:00:00 2001 From: David Marchuk Date: Wed, 28 May 2025 16:35:14 -0700 Subject: [PATCH 2/3] pre-commit --- .github/workflows/pull_request.yml | 6 +++--- .github/workflows/push.yml | 8 ++++---- omnibot_receiver/router.py | 6 ++++-- tests/unit/omnibot_receiver/router_test.py | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index bf346d9..ce4d151 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,10 +5,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.8 + - name: Setup python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Install pre-commit run: pip install pre-commit - name: Run pre-commit @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.x'] + python-version: ['3.10'] steps: - name: Checkout uses: actions/checkout@v1 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index dea2c34..1b20a4e 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -12,10 +12,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.8 + - name: Setup python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Install virtualenv run: pip install virtualenv - name: Build docs @@ -35,10 +35,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.8 + - name: Setup python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Add wheel dependency run: pip install wheel - name: Generate dist diff --git a/omnibot_receiver/router.py b/omnibot_receiver/router.py index e826d92..76794e6 100644 --- a/omnibot_receiver/router.py +++ b/omnibot_receiver/router.py @@ -85,7 +85,8 @@ def handle_event(self, event): ]} """ omnibot_payload_type = event.get('omnibot_payload_type') - if self.message_router and omnibot_payload_type == 'message' or omnibot_payload_type == 'reaction': + if (self.message_router and + omnibot_payload_type in {'message', 'reaction'}): return self.message_router.handle_message(event) elif (self.interactive_router and omnibot_payload_type == 'interactive_component'): @@ -325,7 +326,8 @@ def add_message_rule(self, rule, match_type, route_func, help=''): command -- Match against messages directed at this bot. regex -- Match against messages in a channel that have been targeted at this bot by omnibot. - reaction -- Match against reactions towards items made by this bot. + reaction -- Match against reactions towards items + made by this bot. route_func (function): The function to call when serving this route **kwargs (dict): Keyword arguments (see below for more info) diff --git a/tests/unit/omnibot_receiver/router_test.py b/tests/unit/omnibot_receiver/router_test.py index edded32..708b211 100644 --- a/tests/unit/omnibot_receiver/router_test.py +++ b/tests/unit/omnibot_receiver/router_test.py @@ -254,6 +254,7 @@ def ping(message): assert message_router.handle_message(message) == 'pong' + class TestOmnibotInteractiveRouter(object): def test_interactive_route(self): From de3f40cc9a88dfb21802c7ee7c5683d9db9d0331 Mon Sep 17 00:00:00 2001 From: David Marchuk Date: Wed, 28 May 2025 16:37:26 -0700 Subject: [PATCH 3/3] python version --- .github/workflows/pull_request.yml | 6 +++--- .github/workflows/push.yml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ce4d151..681b91b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,10 +5,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.10 + - name: Setup python 3.10.17 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: 3.10.17 - name: Install pre-commit run: pip install pre-commit - name: Run pre-commit @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + python-version: ['3.10.17'] steps: - name: Checkout uses: actions/checkout@v1 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 1b20a4e..d054fdc 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -12,10 +12,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.10 + - name: Setup python 3.10.17 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: 3.10.17 - name: Install virtualenv run: pip install virtualenv - name: Build docs @@ -35,10 +35,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.10 + - name: Setup python 3.10.17 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: 3.10.17 - name: Add wheel dependency run: pip install wheel - name: Generate dist