Skip to content

[18.0][FIX] ai_oca_bridge_chatter: post AI replies as Discuss comments - #112

Open
marcelsavegnago wants to merge 1 commit into
OCA:18.0from
Escodoo:18.0-imp-ai_oca_bridge_chatter
Open

marcelsavegnago wants to merge 1 commit into
OCA:18.0from
Escodoo:18.0-imp-ai_oca_bridge_chatter

Conversation

@marcelsavegnago

Copy link
Copy Markdown
Member

Discuss only draws chat bubbles for mail.mt_comment. Bridge replies defaulted to mail.mt_note, so AI messages rendered as plain text while manually typed bot messages appeared in bubbles.

@OCA-git-bot OCA-git-bot added series:18.0 mod:ai_oca_bridge_chatter Module ai_oca_bridge_chatter labels Sep 1, 2026
@marcelsavegnago
marcelsavegnago marked this pull request as ready for review September 2, 2026 00:13
@marcelsavegnago

Copy link
Copy Markdown
Member Author

ping @etobella

response["author_id"] = self.chatter_user_id.partner_id.id
response["message_type"] = "comment"
body = response.get("body") or ""
body_is_html = bool(response.pop("body_is_html", False))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might break previous installations....

I mean, imagine I was responding with HTML 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. This should be covered now.

Existing bridges that already return HTML as a plain str are detected and converted to Markup before posting, so the HTML is not escaped or wrapped again. Bridges can also explicitly set body_is_html=True.

Plain-text responses remain unchanged, while the message is still posted as mail.mt_comment so Discuss renders it as a chat bubble.

Could you please check the latest changes?

@marcelsavegnago
marcelsavegnago force-pushed the 18.0-imp-ai_oca_bridge_chatter branch from f539a0a to a0c2f60 Compare September 9, 2026 21:31
# <p>&lt;p&gt;...&lt;/p&gt;</p>. body_is_html=True also warns for
# internal users, so convert HTML to Markup instead of rewriting.
body = response.get("body")
body_is_html = bool(response.pop("body_is_html", False))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For me, by default we should assume that it was html, at least in this version

@marcelsavegnago marcelsavegnago Sep 15, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok. Done

@marcelsavegnago
marcelsavegnago force-pushed the 18.0-imp-ai_oca_bridge_chatter branch from e784ce1 to ba09707 Compare September 15, 2026 14:07

@etobella etobella left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don' t get it. According to the message,of the PR we should be modifying the subtype. However, you are adding also the markdown functionality (not a problem for me, but it should be documented in the PR description at least).

Also, as this is already in production, we shouldn't change anything in previous messages, so no markdown transformation should happen if the new parameter is not set.

# rewriting. Assume HTML by default; body_is_html=False opts out.
body = response.get("body") or ""
body_is_html = bool(response.pop("body_is_html", True))
if body_is_html and not isinstance(body, Markup):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if not body_is_html, isn't it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we invert it, HTML (the 18.0 default) stays as str and message_post
escapes it again, which is the original bug.

Odoo 18 treats Markup as trusted HTML and escapes a plain str, so we
wrap only when body_is_html is true (the default). body_is_html=False
is just an opt-out.

Happy to drop the flag and always convert to Markup if you prefer that
for this version.

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

Labels

mod:ai_oca_bridge_chatter Module ai_oca_bridge_chatter series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants