Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resend Broadcast #1318

Conversation

maheshsattala
Copy link
Contributor

@maheshsattala maheshsattala commented Jul 4, 2024

Added code related to Resend Broadcast.
Fixed and added test cases related to the same.

Summary by CodeRabbit

  • New Features

    • Added the ability to resend a scheduled message broadcast.
  • Bug Fixes

    • Improved error handling and retry logic for message broadcasting.
  • Tests

    • Added comprehensive tests for broadcasting functionalities, including resending and retry limits.
  • Configuration

    • Updated system.yaml to include new error codes for 360Dialog configuration.
  • Documentation

    • Updated documentation to reflect new retry broadcasting limits and resend functionality.

Copy link

coderabbitai bot commented Jul 4, 2024

Walkthrough

The updates introduce the ability to resend message broadcasts and enforce retry limits. New endpoints and methods have been added for managing broadcast retries, validating limits, and handling resends. Alterations include new fields for retry counts, additional parameters in broadcast methods, and enhanced logging. Unit tests were also updated to cover the new functionalities and configuration changes.

Changes

Files/Paths Change Summary
kairon/api/app/routers/bot/channels.py Added endpoint and logic for resending scheduled message broadcasts.
kairon/events/definitions/message_broadcast.py Introduced methods to validate retry limits and handle resending broadcasts.
kairon/events/definitions/scheduled_base.py Added abstract method and enqueue logic for resending broadcasts.
kairon/shared/channels/broadcast/whatsapp.py Added retry_count and resend_broadcast method for WhatsApp broadcasts.
kairon/shared/chat/broadcast/constants.py Added resend value to MessageBroadcastLogType enum.
kairon/shared/chat/broadcast/data_objects.py Added retry_count field to MessageBroadcastSettings.
kairon/shared/chat/broadcast/processor.py Added methods and parameters for retry handling and log updates.
kairon/shared/constants.py Added resend_broadcast to EventRequestType enum.
kairon/shared/data/data_objects.py Added retry_broadcasting_limit field to BotSettings.
system.yaml Added error_codes field for 360Dialog configuration in channels section.
tests/integration_test/services_test.py Added integration tests for broadcasting messages, including retry-related tests.
tests/testing_data/system.yaml Added error_codes field under the channels section for 360_dialog.
tests/unit_test/action/action_test.py Updated tests to include retry_broadcasting_limit in the bot action dictionary.
tests/unit_test/channels/broadcast_processor_test.py Added retry_count field to settings dictionaries in unit tests.
tests/unit_test/events/definitions_test.py Added retry_count field to config dictionaries in message broadcast event tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant Processor
    participant Queue
    participant Broadcast

    User ->> API: Resend broadcast request
    API ->> Processor: Validate request
    Processor ->> API: Validation result
    API ->> Queue: Enqueue resend task
    Queue ->> Processor: Process resend task
    Processor ->> Broadcast: Resend broadcast
    Broadcast ->> Processor: Broadcast status
    Processor ->> API: Update log with status
    API ->> User: Confirmation response
Loading

Poem

In the realm where code takes flight,
Broadcasts now can retry their might.
With limits set, and resends clear,
A fail-safe way this rabbit rears.
🎉 So cheers to messages that don't yet quit,
With resilience, they'll sure transmit! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 14

Outside diff range and nitpick comments (1)
kairon/shared/chat/broadcast/processor.py (1)

Line range hint 161-185:
Replace deprecated Text with str.

The Text type from the typing module is deprecated. Replace it with str.

-    def __add_broadcast_logs_status_and_errors(reference_id: Text, campaign_name: Text,
-                                               broadcast_logs: Dict[Text, Document], retry_count: int = 0):
+    def __add_broadcast_logs_status_and_errors(reference_id: str, campaign_name: str,
+                                               broadcast_logs: Dict[str, Document], retry_count: int = 0):
Tools
Ruff

188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


198-198: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


201-201: typing.Text is deprecated, use str

Replace with str

(UP019)


201-201: typing.Text is deprecated, use str

Replace with str

(UP019)


209-209: typing.Text is deprecated, use str

Replace with str

(UP019)


209-209: typing.Text is deprecated, use str

Replace with str

(UP019)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a03df16 and 38252b8.

Files selected for processing (16)
  • kairon/api/app/routers/bot/channels.py (1 hunks)
  • kairon/events/definitions/message_broadcast.py (4 hunks)
  • kairon/events/definitions/scheduled_base.py (2 hunks)
  • kairon/shared/channels/broadcast/whatsapp.py (3 hunks)
  • kairon/shared/chat/broadcast/constants.py (1 hunks)
  • kairon/shared/chat/broadcast/data_objects.py (1 hunks)
  • kairon/shared/chat/broadcast/processor.py (5 hunks)
  • kairon/shared/constants.py (1 hunks)
  • kairon/shared/data/data_objects.py (1 hunks)
  • system.yaml (1 hunks)
  • tests/integration_test/services_test.py (7 hunks)
  • tests/testing_data/system.yaml (1 hunks)
  • tests/unit_test/action/action_test.py (2 hunks)
  • tests/unit_test/channels/broadcast_processor_test.py (3 hunks)
  • tests/unit_test/events/definitions_test.py (6 hunks)
  • tests/unit_test/events/events_test.py (14 hunks)
Files not summarized due to errors (1)
  • tests/unit_test/events/events_test.py: Error: Message exceeds token limit
Files skipped from review due to trivial changes (4)
  • kairon/shared/constants.py
  • system.yaml
  • tests/testing_data/system.yaml
  • tests/unit_test/events/definitions_test.py
Additional context used
Ruff
kairon/events/definitions/scheduled_base.py

21-21: Use key not in dict instead of key not in dict.keys()

Remove .keys()

(SIM118)


35-35: typing.Text is deprecated, use str

Replace with str

(UP019)


39-39: typing.Text is deprecated, use str

Replace with str

(UP019)


43-43: typing.Text is deprecated, use str

Replace with str

(UP019)

kairon/events/definitions/message_broadcast.py

45-45: typing.Text is deprecated, use str

Replace with str

(UP019)


52-52: typing.Text is deprecated, use str

Replace with str

(UP019)


113-113: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


115-115: typing.Text is deprecated, use str

Replace with str

(UP019)


125-125: typing.Text is deprecated, use str

Replace with str

(UP019)


156-156: typing.Text is deprecated, use str

Replace with str

(UP019)

kairon/api/app/routers/bot/channels.py

188-188: Do not perform function call Security in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

kairon/shared/chat/broadcast/processor.py

21-21: typing.Text is deprecated, use str

Replace with str

(UP019)


21-21: typing.Text is deprecated, use str

Replace with str

(UP019)


84-84: typing.Text is deprecated, use str

Replace with str

(UP019)


84-84: typing.Text is deprecated, use str

Replace with str

(UP019)


84-84: typing.Text is deprecated, use str

Replace with str

(UP019)


84-84: typing.Text is deprecated, use str

Replace with str

(UP019)


121-121: typing.Text is deprecated, use str

Replace with str

(UP019)


161-161: typing.Text is deprecated, use str

Replace with str

(UP019)


161-161: typing.Text is deprecated, use str

Replace with str

(UP019)


162-162: typing.Text is deprecated, use str

Replace with str

(UP019)


188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


198-198: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


201-201: typing.Text is deprecated, use str

Replace with str

(UP019)


201-201: typing.Text is deprecated, use str

Replace with str

(UP019)


209-209: typing.Text is deprecated, use str

Replace with str

(UP019)


209-209: typing.Text is deprecated, use str

Replace with str

(UP019)

Additional comments not posted (26)
kairon/shared/chat/broadcast/constants.py (1)

7-7: LGTM!

The addition of the resend value to the MessageBroadcastLogType enum is straightforward and looks good.

kairon/shared/chat/broadcast/data_objects.py (1)

91-91: LGTM!

The addition of the retry_count field to the MessageBroadcastSettings class is straightforward and looks good.

kairon/shared/channels/broadcast/whatsapp.py (4)

Line range hint 50-66:
LGTM!

The addition of the retry_count parameter to the send_msg method is a good way to track message retries.


111-121: LGTM!

The addition of the retry_count parameter to the send_template_message method is a good way to track message retries.


128-162: LGTM!

The resend_broadcast function is well-implemented and handles the resending of broadcast messages effectively. The use of retry_count to track retries is a good addition.


Line range hint 188-196:
LGTM!

The update_retry_count function is well-implemented and updates the retry count for a broadcast message effectively.

kairon/api/app/routers/bot/channels.py (1)

185-196: LGTM!

The resend_message_broadcast_event endpoint is well-implemented and handles the resending of scheduled message broadcasts effectively. Ensure to fix the security issue flagged above.

Tools
Ruff

188-188: Do not perform function call Security in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

kairon/shared/chat/broadcast/processor.py (1)

116-119: Replace deprecated Text with str.

The Text type from the typing module is deprecated. Replace it with str.

-    def get_reference_id_from_broadcasting_logs(event_id: Text):
+    def get_reference_id_from_broadcasting_logs(event_id: str):

Likely invalid or redundant comment.

tests/unit_test/channels/broadcast_processor_test.py (1)

212-228: LGTM!

The test_get_settings function is well-implemented and includes assertions for the retry_count parameter.

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

936-936: LGTM!

The addition of the retry_broadcasting_limit field is consistent with the rest of the class and follows the correct pattern for adding new fields.

tests/unit_test/events/events_test.py (7)

1283-1284: Ensure retry_count is correctly handled.

Verify that the retry_count field is correctly managed throughout the broadcast process to avoid any inconsistencies.


1315-1315: Initialization of retry_count looks good.

The retry_count field is correctly initialized in the broadcast configuration.


1394-1395: Ensure retry_count is correctly handled.

Verify that the retry_count field is correctly managed throughout the broadcast process to avoid any inconsistencies.


1529-1530: Ensure retry_count is correctly handled.

Verify that the retry_count field is correctly managed throughout the broadcast process to avoid any inconsistencies.


1844-1845: Ensure retry_count is correctly handled.

Verify that the retry_count field is correctly managed throughout the broadcast process to avoid any inconsistencies.


1898-1899: Initialization of retry_count looks good.

The retry_count field is correctly initialized in the broadcast configuration.


2039-2040: Initialization of retry_count looks good.

The retry_count field is correctly initialized in the broadcast configuration.

tests/unit_test/action/action_test.py (2)

2702-2703: Ensure retry_broadcasting_limit is tested correctly.

The addition of the retry_broadcasting_limit field in the BotSettings class is correctly tested. Ensure that the value 3 is appropriate and consistent with the default settings or requirements.


3935-3937: Ensure retry_broadcasting_limit is tested correctly.

The addition of the retry_broadcasting_limit field in the get_bot_settings method is correctly tested. Ensure that the value 3 is appropriate and consistent with the default settings or requirements.

tests/integration_test/services_test.py (7)

2062-2095: LGTM!

The test case test_initiate_bsp_onboarding_for_broadcast is comprehensive and uses appropriate mocking and monkeypatching.


2097-2122: LGTM!

The test case test_add_broadcast_message is comprehensive and uses appropriate mocking.


2124-2152: LGTM!

The test case test_resend_broadcast_message is comprehensive and uses appropriate mocking.


2154-2189: LGTM!

The test case test_resend_broadcast_message_with_retry_limit_exceeded is comprehensive and uses appropriate monkeypatching and mocking.


2191-2216: LGTM!

The test case test_list_broadcast is comprehensive and verifies the retrieval of broadcast messages.


2218-2234: LGTM!

The test case test_delete_message_broadcast is comprehensive and uses appropriate mocking.


Line range hint 24488-24493:
LGTM! But verify the changes align with the context.

The changes to the test case test_get_llm_logs are partially visible and seem to be part of the existing test case.

Verification successful

Verification Successful!

The changes to the test case test_get_llm_logs align with the context and the function implementation is correct.

  • The function imports necessary modules.
  • It sets up an event loop and a logger.
  • It makes an async call to litellm.acompletion and asserts the expected results.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the changes to the test case `test_get_llm_logs` align with the context.

# Test: Search for the function definition. Expect: The function definition and new changes.
rg --type python $'def test_get_llm_logs'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the changes to the test case `test_get_llm_logs` align with the context.

# Locate the file containing the test case
fd 'services_test.py' -t f -e py -x rg 'def test_get_llm_logs' {}

Length of output: 92


Script:

#!/bin/bash
# Description: Extract the full content of the `test_get_llm_logs` function from the `services_test.py` file.

# Locate the file containing the test case and extract the function definition and its body.
fd 'services_test.py' -t f -e py -x rg -A 20 'def test_get_llm_logs' {}

Length of output: 834


Script:

#!/bin/bash
# Description: Extract additional lines from the `test_get_llm_logs` function in the `services_test.py` file to capture the complete function body.

# Locate the file containing the test case and extract the remaining function body.
fd 'services_test.py' -t f -e py -x rg -A 20 'response = client.get' {}

Length of output: 275269

@abstractmethod
def _resend_broadcast(self, msg_broadcast_id: Text):
raise NotImplementedError("Provider not implemented")

@abstractmethod
def delete_schedule(self, msg_broadcast_id: Text):
Copy link

Choose a reason for hiding this comment

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

Replace deprecated typing.Text with str.

The Text type is deprecated and should be replaced with str.

-    def delete_schedule(self, msg_broadcast_id: Text):
+    def delete_schedule(self, msg_broadcast_id: str):
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def delete_schedule(self, msg_broadcast_id: Text):
def delete_schedule(self, msg_broadcast_id: str):
Tools
Ruff

43-43: typing.Text is deprecated, use str

Replace with str

(UP019)

@@ -34,6 +35,10 @@
def _update_schedule(self, msg_broadcast_id: Text, config: Dict):
raise NotImplementedError("Provider not implemented")

@abstractmethod
def _resend_broadcast(self, msg_broadcast_id: Text):
Copy link

Choose a reason for hiding this comment

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

Replace deprecated typing.Text with str.

The Text type is deprecated and should be replaced with str.

-    def _resend_broadcast(self, msg_broadcast_id: Text):
+    def _resend_broadcast(self, msg_broadcast_id: str):
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def _resend_broadcast(self, msg_broadcast_id: Text):
def _resend_broadcast(self, msg_broadcast_id: str):
Tools
Ruff

39-39: typing.Text is deprecated, use str

Replace with str

(UP019)

Comment on lines +18 to +19
EventRequestType.update_schedule.value: self._update_schedule,
EventRequestType.resend_broadcast.value: self._resend_broadcast
Copy link

Choose a reason for hiding this comment

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

Use key not in dict instead of key not in dict.keys().

This is a more Pythonic way to check for the presence of a key in a dictionary.

-        if event_request_type not in request_implementation.keys():
+        if event_request_type not in request_implementation:

Committable suggestion was skipped due to low confidence.

bot_settings = MongoProcessor.get_bot_settings(self.bot, self.user)
config = MessageBroadcastProcessor.get_settings(event_id, self.bot, is_resend=True)

if bot_settings['retry_broadcasting_limit'] <= config["retry_count"]:
Copy link

Choose a reason for hiding this comment

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

Replace deprecated typing.Text with str.

The Text type is deprecated and should be replaced with str.

-    def execute(self, event_id: Text, **kwargs):
+    def execute(self, event_id: str, **kwargs):

Committable suggestion was skipped due to low confidence.

@@ -99,6 +112,16 @@
MessageBroadcastProcessor.delete_task(msg_broadcast_id, self.bot)
raise AppException(e)

def _resend_broadcast(self, msg_broadcast_id: Text):
Copy link

Choose a reason for hiding this comment

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

Replace deprecated typing.Text with str.

The Text type is deprecated and should be replaced with str.

-    def _resend_broadcast(self, msg_broadcast_id: Text):
+    def _resend_broadcast(self, msg_broadcast_id: str):
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def _resend_broadcast(self, msg_broadcast_id: Text):
def _resend_broadcast(self, msg_broadcast_id: str):
Tools
Ruff

115-115: typing.Text is deprecated, use str

Replace with str

(UP019)

@router.post("/broadcast/message/resend/{msg_broadcast_id}", response_model=Response)
async def resend_message_broadcast_event(
msg_broadcast_id: str,
current_user: User = Security(Authentication.get_current_user_and_bot, scopes=DESIGNER_ACCESS)
Copy link

Choose a reason for hiding this comment

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

Avoid function call in argument defaults.

Do not perform function call Security in argument defaults; instead, perform the call within the function or read the default from a module-level singleton variable.

-        current_user: User = Security(Authentication.get_current_user_and_bot, scopes=DESIGNER_ACCESS)
+        current_user: User = Depends(lambda: Authentication.get_current_user_and_bot(scopes=DESIGNER_ACCESS))
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
current_user: User = Security(Authentication.get_current_user_and_bot, scopes=DESIGNER_ACCESS)
current_user: User = Depends(lambda: Authentication.get_current_user_and_bot(scopes=DESIGNER_ACCESS))
Tools
Ruff

188-188: Do not perform function call Security in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

Comment on lines +21 to +24
def get_settings(notification_id: Text, bot: Text, **kwargs):
try:
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=True).get()
status = not kwargs.get("is_resend", False)
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=status).get()
Copy link

Choose a reason for hiding this comment

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

Replace deprecated Text with str.

The Text type from the typing module is deprecated. Replace it with str.

-    def get_settings(notification_id: Text, bot: Text, **kwargs):
+    def get_settings(notification_id: str, bot: str, **kwargs):
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def get_settings(notification_id: Text, bot: Text, **kwargs):
try:
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=True).get()
status = not kwargs.get("is_resend", False)
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=status).get()
def get_settings(notification_id: str, bot: str, **kwargs):
try:
status = not kwargs.get("is_resend", False)
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=status).get()
Tools
Ruff

21-21: typing.Text is deprecated, use str

Replace with str

(UP019)


21-21: typing.Text is deprecated, use str

Replace with str

(UP019)

Comment on lines +121 to +126
def extract_message_ids_from_broadcast_logs(reference_id: Text, retry_count: int = 0):
log_type = MessageBroadcastLogType.resend.value if retry_count > 0 else MessageBroadcastLogType.send.value
message_broadcast_logs = MessageBroadcastLogs.objects(reference_id=reference_id,
log_type=MessageBroadcastLogType.send.value)
log_type=log_type,
retry_count=retry_count)

Copy link

Choose a reason for hiding this comment

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

Replace deprecated Text with str.

The Text type from the typing module is deprecated. Replace it with str.

-    def extract_message_ids_from_broadcast_logs(reference_id: Text, retry_count: int = 0):
+    def extract_message_ids_from_broadcast_logs(reference_id: str, retry_count: int = 0):
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def extract_message_ids_from_broadcast_logs(reference_id: Text, retry_count: int = 0):
log_type = MessageBroadcastLogType.resend.value if retry_count > 0 else MessageBroadcastLogType.send.value
message_broadcast_logs = MessageBroadcastLogs.objects(reference_id=reference_id,
log_type=MessageBroadcastLogType.send.value)
log_type=log_type,
retry_count=retry_count)
def extract_message_ids_from_broadcast_logs(reference_id: str, retry_count: int = 0):
log_type = MessageBroadcastLogType.resend.value if retry_count > 0 else MessageBroadcastLogType.send.value
message_broadcast_logs = MessageBroadcastLogs.objects(reference_id=reference_id,
log_type=log_type,
retry_count=retry_count)
Tools
Ruff

121-121: typing.Text is deprecated, use str

Replace with str

(UP019)

Comment on lines 84 to +89
def add_event_log(bot: Text, log_type: Text, reference_id: Text = None, status: Text = None, **kwargs):
event_completion_states = [EVENT_STATUS.FAIL.value, EVENT_STATUS.COMPLETED.value]
is_new_log = log_type in {MessageBroadcastLogType.send.value, MessageBroadcastLogType.self.value} or kwargs.pop("is_new_log", None)
is_resend = kwargs.pop("is_resend", False)
event_completion_states = [] if is_resend else [EVENT_STATUS.FAIL.value, EVENT_STATUS.COMPLETED.value]
is_new_log = log_type in {MessageBroadcastLogType.send.value,
MessageBroadcastLogType.resend.value,
MessageBroadcastLogType.self.value} or kwargs.pop("is_new_log", None)
Copy link

Choose a reason for hiding this comment

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

Replace deprecated Text with str.

The Text type from the typing module is deprecated. Replace it with str.

-    def add_event_log(bot: Text, log_type: Text, reference_id: Text = None, status: Text = None, **kwargs):
+    def add_event_log(bot: str, log_type: str, reference_id: str = None, status: str = None, **kwargs):
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def add_event_log(bot: Text, log_type: Text, reference_id: Text = None, status: Text = None, **kwargs):
event_completion_states = [EVENT_STATUS.FAIL.value, EVENT_STATUS.COMPLETED.value]
is_new_log = log_type in {MessageBroadcastLogType.send.value, MessageBroadcastLogType.self.value} or kwargs.pop("is_new_log", None)
is_resend = kwargs.pop("is_resend", False)
event_completion_states = [] if is_resend else [EVENT_STATUS.FAIL.value, EVENT_STATUS.COMPLETED.value]
is_new_log = log_type in {MessageBroadcastLogType.send.value,
MessageBroadcastLogType.resend.value,
MessageBroadcastLogType.self.value} or kwargs.pop("is_new_log", None)
def add_event_log(bot: str, log_type: str, reference_id: str = None, status: str = None, **kwargs):
is_resend = kwargs.pop("is_resend", False)
event_completion_states = [] if is_resend else [EVENT_STATUS.FAIL.value, EVENT_STATUS.COMPLETED.value]
is_new_log = log_type in {MessageBroadcastLogType.send.value,
MessageBroadcastLogType.resend.value,
MessageBroadcastLogType.self.value} or kwargs.pop("is_new_log", None)
Tools
Ruff

84-84: typing.Text is deprecated, use str

Replace with str

(UP019)


84-84: typing.Text is deprecated, use str

Replace with str

(UP019)


84-84: typing.Text is deprecated, use str

Replace with str

(UP019)


84-84: typing.Text is deprecated, use str

Replace with str

(UP019)

Comment on lines +188 to +195
def update_retry_count(notification_id: Text, bot: Text, user: Text, retry_count: int = 0):
try:
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=False).get()
settings.retry_count = retry_count
settings.user = user
settings.timestamp = datetime.utcnow()
settings.save()
return settings.to_mongo().to_dict()
Copy link

Choose a reason for hiding this comment

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

Replace deprecated Text with str.

The Text type from the typing module is deprecated. Replace it with str.

-    def update_retry_count(notification_id: Text, bot: Text, user: Text, retry_count: int = 0):
+    def update_retry_count(notification_id: str, bot: str, user: str, retry_count: int = 0):
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def update_retry_count(notification_id: Text, bot: Text, user: Text, retry_count: int = 0):
try:
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=False).get()
settings.retry_count = retry_count
settings.user = user
settings.timestamp = datetime.utcnow()
settings.save()
return settings.to_mongo().to_dict()
def update_retry_count(notification_id: str, bot: str, user: str, retry_count: int = 0):
try:
settings = MessageBroadcastSettings.objects(id=notification_id, bot=bot, status=False).get()
settings.retry_count = retry_count
settings.user = user
settings.timestamp = datetime.utcnow()
settings.save()
return settings.to_mongo().to_dict()
Tools
Ruff

188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


188-188: typing.Text is deprecated, use str

Replace with str

(UP019)


188-188: typing.Text is deprecated, use str

Replace with str

(UP019)

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.

None yet

1 participant