Repository navigation
[19.0][MIG] mail_gateway_whatsapp: Migration to 19.0 - #321
CarlosRoca13 wants to merge 41 commits into
Conversation
The webhook route is public, so the transaction default environment is the public user. Using with_user() was not enough: when the ORM writes a relation to a model that forbids sudo commands (like res.partner), it checks the access with the transaction user. Incoming messages from a new contact then failed with an AccessError when webhook_user_id was a regular internal user. Use request.update_env() instead, so the transaction runs as the webhook user.
The webhook user processes the incoming messages, so it needs the access of a gateway user (e.g. to link the authors to their partner). Restrict the selection to users of the Gateway / User group and document it.
Allow to send documents, images and so on add mark on message Improve security Pass logic to components Add tests Manage change of version of Facebook API
Currently translated at 4.1% (4 of 96 strings) Translation: social-16.0/social-16.0-mail_gateway_whatsapp Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_gateway_whatsapp/es/
…e company wants to initiate a conversation with a customer, a template must be used; otherwise, messages will not be sent. This also applies when the last conversation with the customer is older than 24 hours. - Enabled downloading templates from META - Added the ability to create templates directly in Odoo. Note: Currently, templates with variables or buttons are not supported.
…ated to the current user - Use OdooBot for webhooks instead of the current user, following the same logic as Odoo. - Avoid automatically adding the current user as a member of a new gateway to prevent notifications for all messages. This is now an explicit configuration.
Currently translated at 100.0% (210 of 210 strings) Translation: social-16.0/social-16.0-mail_gateway_whatsapp Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_gateway_whatsapp/it/
115d379 to
812566b
Compare
|
/ocabot migration mail_gateway_whatsapp Does this contains the latest commits from 19 (the security one)? Please also squash together the commits from the same translator. |
…s on failures When a message fails for any reason, the POST request that creates the message in META does not contain any status. However, META notifies the status via webhook. This commit handles this notification, records the error, and notifies the user.
…nt to the API In the previous PR OCA/social#1717 we handled the notification via webhook when Meta returns an error. However, when the error occurs in the communication with Meta, the message is displayed as delivered. After this commit, the message is displayed as error when applicable. The failure details are only written when failure_type = 'unknown'. See: https://github.com/OCA/social/blob/695efd6fa3401614118c6a52f58453b40a9f0842/mail_gateway/models/mail_message.py#L114 So, in exception cases, we write this field to ensure it is processed correctly.
… WhatsApp templates
You may want to send messages through the WhatsApp gateway in your server actions the same you are able to send mails in the linked documents. This also allows to select this kind of server action on automation rules (base_automation). TT57123
You may have several contacts with the same mobile number.
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 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/
… with WhatsApp gateway
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.
…late In 19.0 the Message model has notification_ids instead of notifications, so the template raised an error for every message in Discuss.
812566b to
afa5fc2
Compare
Port of OCA/social#1937. The webhook is processed as the webhook user, which may not be an administrator. Read the gateway and search the partner gateway channels with sudo so that a regular gateway user can process the webhook. Tests now use a gateway user as webhook user and fail if the HTTP requests do not succeed.
afa5fc2 to
38688c5
Compare
|
Yes, they were added But I didn't remember to separate them in a different commit. Now it should be all correct |
|
Does this include @vgavinas' comments? |
|
Tested #321 at 38688c5 on Odoo 19.0 CE with a live WhatsApp Cloud API test number (mail_gateway and mail_gateway_whatsapp both from this branch):
Still open, maybe worth a note in the description: delivery statuses (delivered / read) from the webhook are not stored. The notification stays "sent" after the message has been read on the phone. So my comments from #203 are covered, except the delivery statuses. |
|
Hi @vgavinas Can you check if it is covered now? Thanks |
|
Re-tested at ac6a407 with the live WhatsApp Cloud API test number: yes, it's covered. An outgoing message got I couldn't check the new status display in Discuss itself, because Discuss is still empty due to #319. Thanks! |
carlos-lopez-tecnativa
left a comment
There was a problem hiding this comment.
I tested it locally, but I found some issues and some missing features. I think some of them could be handled in mail_gateway, but I'm commenting here because I tested it with this module.
When a regular user tries to open or leave a gateway, I get this AccessError:
In the v19 migration of the mail_gateway module, mail.resend.message was removed because Odoo removed this wizard. However, when a message failed, this wizard was where the user could get more information about the error:
c0254e9#diff-a652fc8b86e436182d90818bcbaf15fb7f82af72a206ceb7bb0c77d74b8c86edL5
I expected to see more information when a message fails, something like this:
The error is saved in mail.notification:
| <field | ||
| name="field_name" | ||
| widget="DynamicModelFieldSelectorChar" | ||
| required="1" | ||
| options="{'model': 'model'}" |
There was a problem hiding this comment.
This widget doesn't exist anymore. Please update it:
| <field | |
| name="field_name" | |
| widget="DynamicModelFieldSelectorChar" | |
| required="1" | |
| options="{'model': 'model'}" | |
| <field | |
| name="field_name" | |
| widget="field_selector" | |
| required="1" | |
| options="{'model': 'model', 'allow_properties': False}" |


cc @Tecnativa
This PR is superseding #203 to resolve comments. The migration work is respected
ping @pedrobaeza @etobella @carlos-lopez-tecnativa