Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions automator/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,28 @@ reactions:
Don't ask to ask: https://dontasktoask.com/

- reaction: thread
types:
- REMOVE_BROADCAST
- SLACK_POST
type: SLACK_POST
message: >
Please use threads to keep the discussion more organized:
https://datatalks.club/slack/guidelines.html#taking-part-in-discussions

- reaction: thread_please
type: DELETE_MESSAGE
message: |
Hi <@{user}>!

You posted this message in <#{channel}>:

> {user_message}

Please don't use the "Also send to channel" (broadcast) functionality when replying in threads. This is against our community guidelines:

https://datatalks.club/slack/guidelines.html#taking-part-in-discussions

Your message was removed from the channel. Feel free to repost it in the thread without using the broadcast functionality.

Thank you for helping us keep the community organized!

- reaction: faq
type: SLACK_POST
placeholders:
Expand Down
41 changes: 24 additions & 17 deletions tests/test_automator_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ def test_to_welcome_has_thread_message(self):
self.assertEqual(reaction_config['type'], 'DELETE_MESSAGE')
self.assertIn('thread_message', reaction_config)

def test_thread_please_reaction_exists(self):
"""Verify that 'thread_please' reaction is configured"""
reaction_config = lambda_function.reaction_configs.get('thread_please')
self.assertIsNotNone(reaction_config)
self.assertEqual(reaction_config['type'], 'DELETE_MESSAGE')
self.assertIn('message', reaction_config)
# Verify the message contains expected text
message = reaction_config['message']
self.assertIn('broadcast', message.lower())
self.assertIn('guidelines', message.lower())

def test_action_handlers_has_delete_message(self):
"""Verify that DELETE_MESSAGE handler is registered"""
self.assertIn('DELETE_MESSAGE', lambda_function.action_handlers)
Expand All @@ -261,12 +272,14 @@ def test_action_handlers_has_remove_broadcast(self):
lambda_function.handle_remove_broadcast
)

def test_thread_reaction_uses_multiple_handlers(self):
"""Verify that 'thread' reaction uses multiple handlers"""
def test_thread_reaction_uses_single_handler(self):
"""Verify that 'thread' reaction uses single SLACK_POST handler"""
reaction_config = lambda_function.reaction_configs.get('thread')
self.assertIsNotNone(reaction_config)
self.assertIn('types', reaction_config)
self.assertEqual(reaction_config['types'], ['REMOVE_BROADCAST', 'SLACK_POST'])
self.assertIn('type', reaction_config)
self.assertEqual(reaction_config['type'], 'SLACK_POST')
# Should not have 'types' (multiple handlers)
self.assertNotIn('types', reaction_config)


class TestRemoveBroadcast(unittest.TestCase):
Expand Down Expand Up @@ -401,15 +414,9 @@ class TestMultipleHandlers(unittest.TestCase):

@patch('automator_lambda_function.slack')
@patch('automator_lambda_function.util')
def test_thread_reaction_executes_both_handlers(self, mock_util, mock_slack):
"""Test that thread reaction executes both REMOVE_BROADCAST and SLACK_POST"""
# Setup mocks - broadcasted thread reply
mock_slack.get_message_content.return_value = {
'user': 'U123456',
'text': 'Reply sent to channel',
'ts': '1234567890.123457',
'thread_ts': '1234567890.123456'
}
def test_thread_reaction_executes_single_handler(self, mock_util, mock_slack):
"""Test that thread reaction executes only SLACK_POST"""
# Setup mocks
mock_util.format_message.return_value = None

# Create event
Expand All @@ -429,11 +436,11 @@ def test_thread_reaction_executes_both_handlers(self, mock_util, mock_slack):
# Execute the full reaction processing
lambda_function.process_reaction(body, event)

# Verify both handlers were called:
# 1. REMOVE_BROADCAST called get_message_content
mock_slack.get_message_content.assert_called()
# 2. SLACK_POST called post_message_thread
# Verify only SLACK_POST handler was called:
# SLACK_POST called post_message_thread
mock_slack.post_message_thread.assert_called_once()
# REMOVE_BROADCAST should NOT be called (no get_message_content for removal)
mock_slack.remove_message.assert_not_called()


class TestChannelConfig(unittest.TestCase):
Expand Down