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

replace kwargs double backslash for multiline messages #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leonbuchnerbd
Copy link

rocketchat_API/APISections/base.py line 86

if you want to use the api to send multiline messages, you have to adapt the kwargs arguments.

the kwargs arguments are json serialized and have problems with escape sequences.

I fixed this here.

Copy link
Owner

@jadolg jadolg left a comment

Choose a reason for hiding this comment

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

Hi @leonbuchnerbd
thank you for your contribution.
I left you a comment here with some changes I think are worth doing and I think the linter isn't happy. That should be easy to fix with black.

@@ -83,6 +83,12 @@ def call_api_get(self, method, api_path=None, **kwargs):
)

def call_api_post(self, method, files=None, use_json=None, **kwargs):
if "text" in kwargs:
Copy link
Owner

@jadolg jadolg Mar 14, 2025

Choose a reason for hiding this comment

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

Could you please extract this into a separate function that sanitizes the text and add a comment/docstring with what the purpose of it is.
It'll make it easier to keep track of it in the future.
I'd also like to see this tested if possible.
Eg: in

def test_chat_post_update_delete_message(logged_rocket):
include some of these characters and check that the posted message has them by retrieving it.
Or create a new test for this purpose altogether.
A better place to place this cleanup could be the chat_post_message function itself since text is not used anywhere else.
Another use I could think of is when text is used in attachments like what we do here:
{"color": "#ff0000", "text": "there"},

That use-case would not be taken into account.

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