Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions mail_gateway_whatsapp/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=====================
Mail Whatsapp Gateway
=====================
Expand All @@ -17,7 +13,7 @@ Mail Whatsapp Gateway
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
Expand Down
4 changes: 2 additions & 2 deletions mail_gateway_whatsapp/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

{
"name": "Mail Whatsapp Gateway",
"summary": """
Set a gateway for whatsapp""",
"summary": "Set a gateway for WhatsApp",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Creu Blanca, Dixmit, Odoo Community Association (OCA)",
Expand All @@ -14,6 +13,7 @@
"data": [
"security/security.xml",
"security/ir.model.access.csv",
"views/ir_actions_server_views.xml",
"wizards/whatsapp_composer.xml",
"wizards/mail_compose_gateway_message.xml",
"views/mail_whatsapp_template_views.xml",
Expand Down
1 change: 1 addition & 0 deletions mail_gateway_whatsapp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import ir_actions_server
from . import mail_gateway
from . import mail_thread
from . import mail_gateway_whatsapp
Expand Down
90 changes: 90 additions & 0 deletions mail_gateway_whatsapp/models/ir_actions_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright 2025 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import markupsafe

from odoo import api, exceptions, fields, models


class IrServerAction(models.Model):
_inherit = "ir.actions.server"

state = fields.Selection(
selection_add=[("whatsapp", "WhatsApp message")],
ondelete={"whatsapp": "cascade"},
)
whatsapp_gateway_id = fields.Many2one(
comodel_name="mail.gateway", domain=[("gateway_type", "=", "whatsapp")]
)
whatsapp_partner = fields.Char()
whatsapp_template_id = fields.Many2one(
comodel_name="mail.whatsapp.template",
domain="[('gateway_id', '=', whatsapp_gateway_id),('model_id', '=', model_id)]",
)

@api.depends("state")
def _compute_available_model_ids(self):
gateway_based = self.filtered(lambda action: action.state == "whatsapp")
if gateway_based:
mail_models = self.env["ir.model"].search(
[("is_mail_thread", "=", True), ("transient", "=", False)]
)
gateway_based.available_model_ids = mail_models.ids
return super(
IrServerAction, self - gateway_based
)._compute_available_model_ids()

@api.constrains("state", "model_id")
def _check_whatsapp_model_coherency(self):
for action in self:
if action.state == "whatsapp" and (
action.model_id.transient or not action.model_id.is_mail_thread
):
raise exceptions.ValidationError(
self.env._(
"Sending WhatsApp message can only be done on a non transient "
"mail.thread model"
)
)

def _run_action_whatsapp_multi(self, eval_context=None):
# Method called by upstream in ir.actions~_get_runner() using naming convention
context = self.env.context
if (
not self.whatsapp_template_id
or (not context.get("active_ids") and not context.get("active_id"))
or self._is_recompute()
):
return False
res_ids = context.get("active_ids", [context.get("active_id")])
for record in self.env[self.model_id.model].browse(res_ids):
partner_id = int(
self.env["mail.render.mixin"]._render_template(
self.whatsapp_partner, record._name, [record.id]
)[record.id]
)
partner = self.env["res.partner"].browse(partner_id)
partner._whatsapp_get_channel("mobile", self.whatsapp_gateway_id)
gateway_channel = partner.gateway_channel_ids.filtered(
lambda x: x.gateway_id == self.whatsapp_gateway_id
)
body = markupsafe.Markup(
self.whatsapp_template_id.with_context(
default_res_id=record.id
).render_body_message()
)
# pylint: disable=translation-required
record.with_context(
whatsapp_template_id=self.whatsapp_template_id.id, res_id=record.id
).message_post(
body=body,
subtype_xmlid="mail.mt_comment",
message_type="comment",
gateway_notifications=[
{
"channel_type": "gateway",
"gateway_channel_id": gateway_channel.id,
"partner_id": partner_id,
}
],
)
return False
36 changes: 15 additions & 21 deletions mail_gateway_whatsapp/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Mail Whatsapp Gateway</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="mail-whatsapp-gateway">
<h1 class="title">Mail Whatsapp Gateway</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="mail-whatsapp-gateway">
<h1>Mail Whatsapp Gateway</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a7bdf09868559f4a3a765f239ee66aec81889e5a9f1a29249cfd54f418a52143
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/18.0/mail_gateway_whatsapp"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/18.0/mail_gateway_whatsapp"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_gateway_whatsapp"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to respond whatsapp chats.</p>
<p>This way, a group of users can respond customers or any other set of
partners in an integrated way.</p>
Expand All @@ -399,9 +394,9 @@ <h1>Mail Whatsapp Gateway</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<div class="section" id="first-steps">
<h3><a class="toc-backref" href="#toc-entry-2">First steps</a></h3>
<h2><a class="toc-backref" href="#toc-entry-2">First steps</a></h2>
<p>You need to create a WhatsApp Business Account (WABA), a Meta App and
define a phone number. You can follow this
<a class="reference external" href="https://developers.facebook.com/micro_site/url/?click_from_context_menu=true&amp;country=ES&amp;destination=https%3A%2F%2Fwww.facebook.com%2Fbusiness%2Fhelp%2F2087193751603668&amp;event_type=click&amp;last_nav_impression_id=0m3TRxrxOlly1eRmB&amp;max_percent_page_viewed=22&amp;max_viewport_height_px=1326&amp;max_viewport_width_px=2560&amp;orig_http_referrer=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fwhatsapp%2Fcloud-api%2Fget-started-for-bsps%3Flocale%3Den_US&amp;orig_request_uri=https%3A%2F%2Fdevelopers.facebook.com%2Fajax%2Fpagelet%2Fgeneric.php%2FDeveloperNotificationsPayloadPagelet%3Ffb_dtsg_ag%3D--sanitized--%26data%3D%257B%2522businessUserID%2522%253Anull%252C%2522cursor%2522%253Anull%252C%2522length%2522%253A15%252C%2522clientRequestID%2522%253A%2522js_k6%2522%257D%26__usid%3D6-Trd7hi4itpm%253APrd7ifiub2tvy%253A0-Ard7g9twdm0p1-RV%253D6%253AF%253D%26locale%3Den_US%26jazoest%3D24920&amp;region=emea&amp;scrolled=false&amp;session_id=1jLoVJNU6iVMaw3ml&amp;site=developers">steps</a>.</p>
Expand All @@ -410,7 +405,7 @@ <h3><a class="toc-backref" href="#toc-entry-2">First steps</a></h3>
<p>In order to make the webhook accessible, the system must be public.</p>
</div>
<div class="section" id="configure-the-gateway">
<h3><a class="toc-backref" href="#toc-entry-3">Configure the gateway</a></h3>
<h2><a class="toc-backref" href="#toc-entry-3">Configure the gateway</a></h2>
<p>Once you have created the Meta App, you need to add the gateway and
webhook. In order to make it you must follow this steps:</p>
<ul class="simple">
Expand Down Expand Up @@ -443,40 +438,40 @@ <h3><a class="toc-backref" href="#toc-entry-3">Configure the gateway</a></h3>
</div>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-4">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Usage</a></h1>
<ol class="arabic simple">
<li>Access Gateway</li>
<li>Wait until someone starts a conversation.</li>
<li>Now you will be able to respond and receive messages to this person.</li>
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-5">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-5">Known issues / Roadmap</a></h1>
<p><strong>WhatsApp templates</strong></p>
<ul class="simple">
<li>Add support for Variables</li>
<li>Add support for Buttons</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_gateway_whatsapp%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-7">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-7">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-8">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">Authors</a></h2>
<ul class="simple">
<li>Creu Blanca</li>
<li>Dixmit</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-9">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
<ul>
<li><p class="first">Olga Marco &lt;<a class="reference external" href="mailto:olga.marco&#64;creublanca.es">olga.marco&#64;creublanca.es</a>&gt;</p>
</li>
Expand All @@ -492,12 +487,12 @@ <h3><a class="toc-backref" href="#toc-entry-9">Contributors</a></h3>
</ul>
</div>
<div class="section" id="other-credits">
<h3><a class="toc-backref" href="#toc-entry-10">Other credits</a></h3>
<h2><a class="toc-backref" href="#toc-entry-10">Other credits</a></h2>
<p>This work has been funded by AEOdoo (Asociación Española de Odoo -
<a class="reference external" href="https://www.aeodoo.org">https://www.aeodoo.org</a>)</p>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -510,6 +505,5 @@ <h3><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
33 changes: 33 additions & 0 deletions mail_gateway_whatsapp/views/ir_actions_server_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="ir_actions_server_view_form" model="ir.ui.view">
<field
name="name"
>ir.actions.server.view.form.inherit.mail_gateway_whatsapp</field>
<field name="model">ir.actions.server</field>
<field name="inherit_id" ref="base.view_server_action_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='link_field_id']" position="after">
<field
name="whatsapp_gateway_id"
string="Gateway"
invisible="state != 'whatsapp'"
required="state == 'whatsapp'"
/>
<field
name="whatsapp_partner"
placeholder="Insert here the Jinja expression to get the partner ID"
string="Partner"
invisible="state != 'whatsapp'"
required="state == 'whatsapp'"
/>
<field
name="whatsapp_template_id"
string="WhatsApp template"
invisible="state != 'whatsapp'"
required="state == 'whatsapp'"
/>
</xpath>
</field>
</record>
</odoo>
Loading