Skip to content

Conversation

@hasinaxp
Copy link
Contributor

@hasinaxp hasinaxp commented May 12, 2025

Summary by CodeRabbit

  • New Features

    • Added a configurable option to control whether a bot response is sent to users after executing an email action.
  • Tests

    • Introduced new integration and unit tests to verify email action behavior when bot response dispatch is enabled or disabled.
    • Updated existing tests to ensure consistent coverage for the new configuration option.

@coderabbitai
Copy link

coderabbitai bot commented May 12, 2025

Walkthrough

A new configuration parameter, dispatch_bot_response, was introduced across email action models, logic, and tests. This parameter controls whether the bot's response message is dispatched to the user after executing an email action. The codebase and tests were updated to support, persist, and verify this conditional dispatch behavior.

Changes

File(s) Change Summary
kairon/actions/definitions/email.py Added dispatch_bot_response parameter to control if the bot response is dispatched; moved dispatch logic inside a conditional in the finally block of the email action execution method.
kairon/shared/actions/data_objects.py, kairon/shared/data/data_models.py Added dispatch_bot_response boolean field (default True) to EmailActionConfig and EmailActionRequest models to persist and transfer the new configuration.
kairon/shared/data/processor.py Updated edit_email_action in MongoProcessor to assign the dispatch_bot_response field from input to the email action object.
tests/integration_test/action_service_test.py Added a new integration test to verify that no bot response is dispatched when dispatch_bot_response is False, and validated correct SMTP/email sending behavior.
tests/integration_test/services_test.py Updated email action test data to include the dispatch_bot_response key in all relevant configurations.
tests/unit_test/data_processor/data_processor_test.py Added and updated tests to cover adding, editing, and validating email actions with both dispatch_bot_response set to True and False.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Bot
    participant EmailAction
    participant SMTPServer

    User->>Bot: Triggers email action
    Bot->>EmailAction: Execute with config (dispatch_bot_response)
    EmailAction->>SMTPServer: Send email
    SMTPServer-->>EmailAction: Acknowledge
    alt dispatch_bot_response == True
        EmailAction->>Bot: Dispatch bot response message
    else dispatch_bot_response == False
        EmailAction-->>Bot: Skip dispatching response
    end
    Bot-->>User: (Conditional) Bot response
Loading

Poem

In the warren of code, a new flag appears,
To hush the bot’s reply, or let users hear.
Email sent swiftly, with dispatch in tow—
True or False, now the devs can know!
With tests all a-flutter, and logic precise,
This rabbit approves—oh, isn’t it nice?
🐇✉️

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (9)
tests/integration_test/services_test.py (3)

23145-23145: Maintain consistent quoting style
Currently the new key uses single quotes, whereas the surrounding dict literals use double quotes for keys. Please update to:

-            'dispatch_bot_response': True,
+            "dispatch_bot_response": True,

23165-23165: Maintain consistent quoting style
The key here also uses single quotes; switch to double quotes to match adjacent entries:

-            'dispatch_bot_response': True,
+            "dispatch_bot_response": True,

23185-23185: Maintain consistent quoting style
Please change the single-quoted key to double quotes for consistency:

-            'dispatch_bot_response': True,
+            "dispatch_bot_response": True,
kairon/shared/data/processor.py (1)

7152-7152: Consider using a default value for dispatch_bot_response

For consistency with other action types, consider using the .get() method with a default value for dispatch_bot_response, similar to how it's handled in other action types like prompt_action (line 7936) and schedule_action (line 8736).

-        email_action.dispatch_bot_response = action["dispatch_bot_response"]
+        email_action.dispatch_bot_response = action.get("dispatch_bot_response", True)

This would prevent KeyError exceptions if the parameter is missing in the request data and maintain consistent behavior across different action types.

tests/unit_test/data_processor/data_processor_test.py (2)

16337-16354: Good test coverage for the dispatch_bot_response=False scenario.

This test properly verifies that an email action can be created with the dispatch_bot_response flag set to False. The cleanup at the end is a good practice.

However, there's an unused variable in the test:

- with patch("kairon.shared.utils.SMTP", autospec=True) as mock_smtp:
+ with patch("kairon.shared.utils.SMTP", autospec=True):
🧰 Tools
🪛 Ruff (0.8.2)

16351-16351: Local variable mock_smtp is assigned to but never used

Remove assignment to unused variable mock_smtp

(F841)


16334-16334: Fix unused variables in tests.

There are several instances of unused mock_smtp variables throughout the test file. While this doesn't affect functionality, it triggers linter warnings.

Consider updating these instances to:

- with patch("kairon.shared.utils.SMTP", autospec=True) as mock_smtp:
+ with patch("kairon.shared.utils.SMTP", autospec=True):

Or if you need to verify the mock was called:

with patch("kairon.shared.utils.SMTP", autospec=True) as mock_smtp:
    # Test code
    mock_smtp.assert_called_once()  # Or appropriate assertion

Also applies to: 16351-16351, 16410-16410, 16472-16472, 16491-16491, 16509-16509, 16514-16514, 16531-16531

🧰 Tools
🪛 Ruff (0.8.2)

16334-16334: Local variable mock_smtp is assigned to but never used

Remove assignment to unused variable mock_smtp

(F841)

tests/integration_test/action_service_test.py (3)

6150-6150: Fix typo in function name

There's a typo in the function name: "dispaatch" has an extra "a". This should be corrected for clarity and consistency.

-def test_email_action_execution_dispaatch_false(mock_smtp, mock_action_config, mock_action):
+def test_email_action_execution_dispatch_false(mock_smtp, mock_action_config, mock_action):

6151-6158: Use context managers for file operations

File operations should use context managers (with statements) to ensure proper resource cleanup.

-    Utility.email_conf['email']['templates']['conversation'] = open('template/emails/conversation.html',
-                                                                    'rb').read().decode()
-    Utility.email_conf['email']['templates']['bot_msg_conversation'] = open(
-        'template/emails/bot_msg_conversation.html', 'rb').read().decode()
-    Utility.email_conf['email']['templates']['user_msg_conversation'] = open(
-        'template/emails/user_msg_conversation.html', 'rb').read().decode()
-    Utility.email_conf['email']['templates']['button_template'] = open('template/emails/button.html',
-                                                                       'rb').read().decode()
+    with open('template/emails/conversation.html', 'rb') as f:
+        Utility.email_conf['email']['templates']['conversation'] = f.read().decode()
+    with open('template/emails/bot_msg_conversation.html', 'rb') as f:
+        Utility.email_conf['email']['templates']['bot_msg_conversation'] = f.read().decode()
+    with open('template/emails/user_msg_conversation.html', 'rb') as f:
+        Utility.email_conf['email']['templates']['user_msg_conversation'] = f.read().decode()
+    with open('template/emails/button.html', 'rb') as f:
+        Utility.email_conf['email']['templates']['button_template'] = f.read().decode()
🧰 Tools
🪛 Ruff (0.8.2)

6151-6151: Use a context manager for opening files

(SIM115)


6153-6153: Use a context manager for opening files

(SIM115)


6155-6155: Use a context manager for opening files

(SIM115)


6157-6157: Use a context manager for opening files

(SIM115)


6275-6275: Consider using conventional comparison order

While Yoda conditions ({} == kwargs) are valid, the standard Python style is to place the variable before the constant.

-    assert {} == kwargs
+    assert kwargs == {}

Also applies to: 6282-6282, 6290-6290

🧰 Tools
🪛 Ruff (0.8.2)

6275-6275: Yoda condition detected

Rewrite as kwargs == {}

(SIM300)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 221ca2d and d3f258d.

📒 Files selected for processing (7)
  • kairon/actions/definitions/email.py (2 hunks)
  • kairon/shared/actions/data_objects.py (1 hunks)
  • kairon/shared/data/data_models.py (1 hunks)
  • kairon/shared/data/processor.py (1 hunks)
  • tests/integration_test/action_service_test.py (1 hunks)
  • tests/integration_test/services_test.py (3 hunks)
  • tests/unit_test/data_processor/data_processor_test.py (7 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
tests/integration_test/action_service_test.py

6151-6151: Use a context manager for opening files

(SIM115)


6153-6153: Use a context manager for opening files

(SIM115)


6155-6155: Use a context manager for opening files

(SIM115)


6157-6157: Use a context manager for opening files

(SIM115)


6275-6275: Yoda condition detected

Rewrite as kwargs == {}

(SIM300)


6282-6282: Yoda condition detected

Rewrite as kwargs == {}

(SIM300)


6290-6290: Yoda condition detected

Rewrite as kwargs == {}

(SIM300)

tests/unit_test/data_processor/data_processor_test.py

16334-16334: Local variable mock_smtp is assigned to but never used

Remove assignment to unused variable mock_smtp

(F841)


16351-16351: Local variable mock_smtp is assigned to but never used

Remove assignment to unused variable mock_smtp

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Python CI
🔇 Additional comments (15)
kairon/shared/data/data_models.py (1)

1004-1004: Looks good! New parameter adds flexibility for email actions.

The addition of dispatch_bot_response parameter with a default value of True provides a good way to control whether the bot should send a response message to the user after executing an email action. The default value ensures backward compatibility with existing behavior.

kairon/shared/actions/data_objects.py (1)

447-447: LGTM! Field added consistently with request model.

The addition of the dispatch_bot_response field to the EmailActionConfig class matches the corresponding change in the request model. Setting the default to True maintains backward compatibility with existing database records.

kairon/actions/definitions/email.py (2)

57-57: Good addition of the dispatch control flag with a default value.

This change adds a new configuration parameter dispatch_bot_response with a sensible default value of True, ensuring backward compatibility with existing configurations. The naming clearly indicates the purpose of this flag.


91-92: Good implementation of conditional response dispatch.

The modification makes the bot response dispatch conditional based on the dispatch_bot_response flag, allowing flexibility in whether responses are sent to the user after email actions. The placement inside the finally block ensures this logic runs regardless of whether the email action succeeds or fails.

tests/unit_test/data_processor/data_processor_test.py (8)

16331-16331: Properly added dispatch_bot_response parameter.

This addition correctly implements the new dispatch_bot_response parameter with a default value of True, which aligns with the PR objective to make mail channel dispatch optional.


16366-16367: Proper configuration of dispatch_bot_response parameter.

The addition of the dispatch_bot_response parameter set to True is consistent with the PR objectives and other test updates.


16406-16407: Consistently added dispatch_bot_response parameter.

The parameter has been consistently added across test cases, which ensures thorough test coverage for the new feature.


16468-16469: Properly added dispatch_bot_response parameter.

The addition maintains consistency with other test cases.


16487-16488: Properly added dispatch_bot_response parameter.

The parameter has been properly added with a value of True.


16506-16506: Good test coverage for the False case in edit action.

Testing the edit functionality with dispatch_bot_response set to False ensures comprehensive coverage of the new feature.


16513-16513: Properly updating dispatch_bot_response in the edit test.

This correctly tests changing the parameter value during an edit operation, which is an important test case.


16528-16528: Consistently implemented dispatch_bot_response parameter.

All the relevant test cases have been updated to include the new parameter.

tests/integration_test/action_service_test.py (3)

6161-6174: LGTM! Good implementation of the new dispatch_bot_response parameter

The test properly configures the email action with dispatch_bot_response=False, which is the key feature being introduced in this PR.


6264-6266: Good validation of the dispatch behavior

This section correctly verifies that when dispatch_bot_response=False:

  1. The action successfully completes (status code 200)
  2. The slot is updated with the expected value
  3. No responses are sent to the user (len(response_json['responses']) == 0)

This effectively validates the core functionality introduced in this PR.


6147-6297: Great test coverage for the new feature

This comprehensive test properly validates that:

  1. Email actions can be configured with dispatch_bot_response=False
  2. The email is still sent correctly via SMTP with all expected parameters
  3. The bot doesn't dispatch a response to the user when this flag is disabled
  4. The action logic still updates the slot with the response message

This provides good coverage for the new conditional dispatch feature.

🧰 Tools
🪛 Ruff (0.8.2)

6151-6151: Use a context manager for opening files

(SIM115)


6153-6153: Use a context manager for opening files

(SIM115)


6155-6155: Use a context manager for opening files

(SIM115)


6157-6157: Use a context manager for opening files

(SIM115)


6275-6275: Yoda condition detected

Rewrite as kwargs == {}

(SIM300)


6282-6282: Yoda condition detected

Rewrite as kwargs == {}

(SIM300)


6290-6290: Yoda condition detected

Rewrite as kwargs == {}

(SIM300)

Copy link
Collaborator

@hiteshghuge hiteshghuge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants