Skip to content

[MIG] mail_gateway_whatsapp: Migration to 19.0 - #203

Open
DucTruongKomit wants to merge 63 commits into
OCA:19.0from
komit-consulting:19.0-mig-mail_gateway_whatsapp
Open

DucTruongKomit wants to merge 63 commits into
OCA:19.0from
komit-consulting:19.0-mig-mail_gateway_whatsapp

Conversation

@DucTruongKomit

@DucTruongKomit DucTruongKomit commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

[MIG] mail_gateway_whatsapp: Migration to 19.0

This module is depended to mail_gateway in PR: #202.
So I added the Commits here for test.

@OCA-git-bot OCA-git-bot added series:19.0 mod:mail_gateway_whatsapp Module mail_gateway_whatsapp labels Jun 2, 2026
@DucTruongKomit
DucTruongKomit marked this pull request as draft June 2, 2026 08:25
@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch from c7e221d to 6639a38 Compare June 4, 2026 08:26
@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch from 6639a38 to 56e3f02 Compare July 3, 2026 09:45
@OCA-git-bot OCA-git-bot added the mod:mail_gateway Module mail_gateway label Jul 3, 2026
@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch 4 times, most recently from 125dd08 to f569f39 Compare July 10, 2026 09:41
@DucTruongKomit
DucTruongKomit marked this pull request as ready for review July 10, 2026 09:44
@DucTruongKomit
DucTruongKomit marked this pull request as draft July 10, 2026 09:44
@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch 2 times, most recently from c8b5408 to 7386cf0 Compare July 10, 2026 10:43
@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch from 7386cf0 to 009bb90 Compare September 8, 2026 05:27
@pedrobaeza

Copy link
Copy Markdown
Member

To include #1902 and #1909

@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch 4 times, most recently from 89ff506 to acc1ec8 Compare September 25, 2026 09:33
@DucTruongKomit

Copy link
Copy Markdown
Contributor Author

To include #1902 and #1909

I already solved it, thank you.

@DucTruongKomit
DucTruongKomit marked this pull request as ready for review September 25, 2026 09:40
@adolfomeza

Copy link
Copy Markdown

Functional test with the real WhatsApp Cloud API 👍

I tested this branch at acc1ec8, which includes the mail_gateway migration. I used Odoo 19.0 Community (build 20260810) on a fresh database, with a Meta test phone number and Graph API v23.0.

Automated tests: --test-tags /mail_gateway,/mail_gateway_whatsapp gives 0 failed, 0 error(s) of 141 tests.

With Meta, end to end:

  • Webhook verification (GET with hub.challenge) is accepted by Meta, and the gateway switches to integrated.
  • Incoming messages: the X-Hub-Signature-256 signature is verified with the app secret, and a text message creates the gateway channel and the message in Discuss.
  • Outgoing: a reply posted from the channel is delivered to the phone (wamid returned, notification sent).

One thing worth documenting (or fixing): if webhook_user_id is set to a regular internal user (for example admin) instead of the default base.user_root, every incoming message from a new contact fails with 403:

AccessError: Failed to write field discuss.channel.channel_partner_ids
Public user (id=3) doesn't have 'read' access to: Contact (res.partner)

The call chain is _get_channel → discuss.channel.create → _subscribe_users_automatically → _compute_channel_partner_ids. The same payload with the same user works when I run it from odoo shell, and only fails inside the HTTP request. I didn't dig into the root cause. With the default user (base.user_root) it works fine.

Not tested: templates, media messages and delivery status updates.

Thanks for the migration!

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot migration mail_gateway_whatsapp

@OCA-git-bot OCA-git-bot added this to the 19.0 milestone Oct 2, 2026
@OCA-git-bot OCA-git-bot mentioned this pull request Oct 2, 2026
22 of 38 tasks
@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch from acc1ec8 to c2e783b Compare October 2, 2026 09:23
@OCA-git-bot OCA-git-bot added mod:mail_forward Module mail_forward mod:mail_print Module mail_print labels Oct 2, 2026
mymage and others added 29 commits October 2, 2026 17:42
Currently translated at 100.0% (254 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/it/
…th that mark, discuss will show an audio player instead of a download button. For reference, this is where the "voice" key is detected and the attachment is processed as such:

https://github.com/odoo/odoo/blob/3a54f1e4b706d6732d8dc16bc206f5fc4d6ab923/addons/mail/models/discuss/ir_attachment.py#L29-L32
Currently translated at 100.0% (254 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/es/
When a message from whatsapp arrives and it's a response from a message sent from Odoo, set the parent_id field.
… body. Currently, attachment captions are disregarded.
Currently translated at 4.3% (11 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/gl/
Currently translated at 8.2% (21 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/gl/
Currently translated at 11.4% (29 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/gl/
Currently translated at 100.0% (254 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/es/
Currently translated at 49.6% (126 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/pt_BR/
Currently translated at 61.0% (155 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/gl/
Currently translated at 65.7% (167 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/gl/
Currently translated at 89.3% (227 of 254 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/gl/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/
Currently translated at 100.0% (255 of 255 strings)

Translation: social-18.0/social-18.0-mail_gateway_whatsapp
Translate-URL: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp/it/
…record

Nothing enforces uniqueness on (gateway_id, gateway_token), so two webhooks
delivered in parallel for the same unknown number each create their own
record. The unbounded searches in _get_author then return both, and every
later message of that correspondent fails on ensure_one(): the webhook
answers 500 and the delivery is lost.

limit=1 bounds both searches. The default _order is id, so the oldest record
wins.
Incoming text was passed raw to message_post. mail_thread only escapes a str
body, and escape() does not turn newlines into markup, so a multi-line message
was archived as a single block and its URLs were not clickable. The assembled
body (text plus media captions) now goes through plaintext2html before both
message_post calls of _process_update, mirroring the outgoing path where the
body is sent as html2plaintext(body).

The same root cause affected the location branch: the anchor was built as a
str, so escape() rendered it as literal HTML instead of a link. It is now built
as Markup, with % interpolation so the payload coordinates stay escaped.

A test covers a multi-line incoming message carrying a location: line breaks
rendered, blank line kept as a paragraph break, URL turned into a link,
markup-looking text left literal, and the location anchor kept as a link.
WhatsApp clients mark up text with *bold*, _italic_, ~strikethrough~ and
```monospace```. Incoming, those markers were archived as literal characters.
Outgoing, html2plaintext sent <strong> as *bold*, which WhatsApp happens to
read as bold, but <em> as /italic/, which it shows as is, and dropped the
other tags.

Both ways now use the same table. Incoming, the markers are turned into html
tags after plaintext2html, leaving the tags and links it produced alone.
Outgoing, the formatting tags are turned back into markers before
html2plaintext.

Tests cover an incoming message carrying markers and a link whose url holds an
underscore, and an outgoing message carrying bold and italic.
@DucTruongKomit
DucTruongKomit force-pushed the 19.0-mig-mail_gateway_whatsapp branch from 4780be9 to ec43cce Compare October 2, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:mail_gateway_whatsapp Module mail_gateway_whatsapp mod:mail_gateway Module mail_gateway series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.