-
Notifications
You must be signed in to change notification settings - Fork 80
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
Format text converter channels #1709
Format text converter channels #1709
Conversation
WalkthroughThe pull request introduces a new feature for handling formatted text messages across multiple messaging platforms (Messenger, Telegram, WhatsApp). A new Changes
Sequence DiagramsequenceDiagram
participant User
participant MessageHandler
participant ResponseConverter
participant ChannelSpecificHandler
User->>MessageHandler: Send formatted text message
MessageHandler->>ResponseConverter: Convert message
ResponseConverter->>ResponseConverter: paragraph_transformer
ResponseConverter-->>ChannelSpecificHandler: Formatted message
ChannelSpecificHandler->>User: Deliver message
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (4)
kairon/shared/constants.py (1)
129-129
: Consider aligning naming conventions for the new enum member.Currently,
"formatText"
uses partial camel case, whereas other enum values are lower-case (e.g.,"link"
,"image"
,"quick_reply"
). For consistency, you could rename it to"format_text"
.- FORMAT_TEXT = "formatText" + FORMAT_TEXT = "format_text"kairon/chat/converters/channels/telegram.py (1)
39-66
: Add exception chaining for clarity in paragraph_transformer.On line 65, consider chaining the raised exception via
raise ... from ex
to precisely distinguish it from errors in the exception handling block.- raise Exception(f"Error in TelegramResponseConverter::paragraph_transformer {str(ex)}") + raise Exception(f"Error in TelegramResponseConverter::paragraph_transformer {str(ex)}") from ex🧰 Tools
🪛 Ruff (0.8.2)
65-65: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
kairon/chat/converters/channels/messenger.py (1)
39-57
: Add exception chaining for clarity in paragraph_transformer.On line 56, consider chaining the raised exception via
raise ... from ex
to help identify its origin more accurately.- raise Exception(f"Error in MessengerResponseConverter::paragraph_transformer {str(ex)}") + raise Exception(f"Error in MessengerResponseConverter::paragraph_transformer {str(ex)}") from ex🧰 Tools
🪛 Ruff (0.8.2)
56-56: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
kairon/chat/converters/channels/whatsapp.py (1)
37-64
: Add exception chaining for clarity in paragraph_transformer.On line 63, chaining the raised exception with
from ex
can help pinpoint the original exception more precisely.- raise Exception(f"Error in WhatsappResponseConverter::paragraph_transformer {str(ex)}") + raise Exception(f"Error in WhatsappResponseConverter::paragraph_transformer {str(ex)}") from ex🧰 Tools
🪛 Ruff (0.8.2)
63-63: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
kairon/chat/converters/channels/messenger.py
(3 hunks)kairon/chat/converters/channels/telegram.py
(3 hunks)kairon/chat/converters/channels/whatsapp.py
(3 hunks)kairon/chat/handlers/channels/telegram.py
(1 hunks)kairon/chat/handlers/channels/whatsapp.py
(1 hunks)kairon/shared/constants.py
(1 hunks)metadata/message_template.yml
(4 hunks)tests/unit_test/utility_test.py
(3 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
metadata/message_template.yml
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
🪛 Ruff (0.8.2)
kairon/chat/converters/channels/telegram.py
65-65: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
kairon/chat/converters/channels/messenger.py
56-56: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
kairon/chat/converters/channels/whatsapp.py
63-63: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
🔇 Additional comments (24)
kairon/chat/converters/channels/telegram.py (1)
98-99
: The FORMAT_TEXT branch looks good.
The additional condition for FORMAT_TEXT
in messageConverter
cleanly delegates processing to paragraph_transformer
.
kairon/chat/converters/channels/messenger.py (1)
113-114
: The FORMAT_TEXT handling is properly integrated.
Good job adding the condition for FORMAT_TEXT
to delegate processing to paragraph_transformer
.
kairon/chat/converters/channels/whatsapp.py (1)
152-153
: FORMAT_TEXT case is appropriately handled.
Your additional condition in messageConverter
properly calls paragraph_transformer
for formatted text.
kairon/chat/handlers/channels/telegram.py (1)
159-159
: Add support for 'formatText' in Telegram.
This condition properly includes 'formatText'
alongside 'link'
and 'video'
. The logic appends the 'text'
field to response_list
and invokes the same send_message
method used for regular text messages.
kairon/chat/handlers/channels/whatsapp.py (1)
236-236
: Extend content types to include 'formatText' for WhatsApp.
Adding "formatText": "text"
in the content_type
dictionary ensures the WhatsApp channel can handle formatted text. This is consistent with the new formatText
type introduced in the codebase.
tests/unit_test/utility_test.py (15)
3339-3357
: Test basic paragraph transformation for WhatsApp.
These lines introduce a test verifying the transformation of a single paragraph of text into WhatsApp’s JSON structure. This ensures straightforward text is appended with a trailing newline.
3358-3375
: Test paragraph transformation with bold text for WhatsApp.
This test confirms that bold text is correctly wrapped with asterisks (*text*
) in the final WhatsApp message body. The fallback for normal text remains unaltered.
3376-3392
: Test leading/trailing spaces in paragraph transformation for WhatsApp.
Ensures that user-provided spacing is preserved in the final message by maintaining exact leading and trailing whitespaces.
3393-3402
: Test empty paragraphs for WhatsApp.
Checks converting an empty list of paragraphs produces an empty body. This prevents errors in scenarios where no text is supplied.
3403-3412
: Test exception handling in WhatsApp paragraph transformation.
Here, the test verifies that custom exceptions are raised and includes proper error messages when underlying configuration lookups fail.
3414-3428
: Test basic paragraph transformation for Telegram.
Examines the function’s correctness when converting a single paragraph. Ensures a trailing newline is appended for a clean read in Telegram messages.
3429-3444
: Test bold text transformation for Telegram.
Checks that bold property in the object is translated to HTML tags (<b>...</b>
) for Telegram. Normal text remains unaffected.
3445-3459
: Test leading/trailing spaces for Telegram paragraphs.
Verifies any existing whitespace is left intact in the final content. This helps preserve user-intended formatting.
3460-3467
: Test empty paragraphs for Telegram.
Ensures an empty array of paragraphs cleanly produces an empty "text"
field, preventing any extraneous newlines.
3468-3475
: Test exception handling in Telegram paragraph formatting.
This block validates correct exception propagation if the channel configuration fails to load or parse.
3477-3491
: Test basic paragraph transformation for Messenger.
Ensures a single paragraph is handled correctly in Messenger with a trailing newline.
3492-3507
: Test bold text transformation in Messenger paragraphs.
Confirms that bold text simply remains standard text without formatting markup, matching current Messenger design.
3508-3522
: Test leading/trailing spaces in Messenger paragraphs.
Checks that user-provided spacing is retained, preserving the original text spacing.
3523-3530
: Test empty paragraphs for Messenger.
Verifies that an empty structure leads to an empty "text"
field with no appended newline.
3531-3537
: Test exception handling in Messenger paragraph transformation.
Ensures that exceptions are thrown with the correct context and message when channel configuration retrieval fails.
metadata/message_template.yml (4)
1-1
: Add 'formatText' to type_list.
This new element type enables rendering styled text segments across all supported channels.
🧰 Tools
🪛 yamllint (1.35.1)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
[warning] 1-1: too few spaces after comma
(commas)
91-91
: Add 'formatText' entry for Messenger.
The JSON template extends Messenger’s support to handle custom formatted text via a simple "text"
field.
116-119
: Introduce 'formatText' template for WhatsApp.
Defines "preview_url"
and "body"
fields to capture styled text in a single message body, aligning with the newly supported formatText
element.
136-142
: Include 'formatText' in Telegram’s message template.
The block declares how Telegram should display formatted text, applying "parse_mode": "HTML"
for styling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
whatsapp, telegram, messenger & instagram
Summary by CodeRabbit
New Features
formatText
, in the messaging template for various platforms.Bug Fixes
Tests