Skip to content
Merged
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
107 changes: 107 additions & 0 deletions mail_gateway/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
============
Mail Gateway
============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1fc341f96ecbd2a96d20eb12aae392827aa821f05dbda6cc30a702d19a58f223
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/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
:target: https://github.com/OCA/social/tree/17.0/mail_gateway
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_gateway
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module will allow you to integrate an external chat system in your
Odoo system. It requires extra modules with the specific configuration
of each chat system, like mail_gateway_telegram or
mail_gateway_whatsapp.

This way, a group of users can respond customers or any other set of
partners within Odoo, but the messages will be sent through the external
chat system.

**Table of contents**

.. contents::
:local:

Usage
=====

When external messages are received, they will be directly sent to the
discuss menu. Answering to these messages will send the answer to the
external contact. We can assign this messages to any record using the
message actions. Also, we can assign the sender to a partner using the
followers menu and selecting the partner.

On a standard record associated to a partner with external chat, we can
send messages to the external contact directly selecting the methods of
the partner. To use this, we just need to use the

It is recomended to enable chatter notification to all users that will
receive messages from gateways.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
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
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_gateway%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Creu Blanca
* Dixmit

Contributors
------------

- Enric Tobella
- Olga Marco

Other credits
-------------

This work has been funded by AEOdoo (Asociación Española de Odoo -
https://www.aeodoo.org)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/social <https://github.com/OCA/social/tree/17.0/mail_gateway>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions mail_gateway/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import controllers
from . import models

from .hooks import pre_init_hook
from . import wizards
31 changes: 31 additions & 0 deletions mail_gateway/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2024 Dixmit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Mail Gateway",
"summary": "Base module for gateway communications",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "Creu Blanca,Dixmit,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"depends": ["mail"],
"pre_init_hook": "pre_init_hook",
"data": [
"wizards/mail_compose_gateway_message.xml",
"wizards/mail_message_gateway_link.xml",
"wizards/mail_message_gateway_send.xml",
"wizards/mail_guest_manage.xml",
"security/security.xml",
"security/ir.model.access.csv",
"views/mail_gateway.xml",
"views/res_partner_gateway_channel.xml",
"views/mail_guest_views.xml",
],
"assets": {
"web.assets_backend": [
"mail_gateway/static/src/components/**/*",
"mail_gateway/static/src/core/**/*",
"mail_gateway/static/src/models/**/*",
],
},
}
2 changes: 2 additions & 0 deletions mail_gateway/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import gateway
from . import discuss
11 changes: 11 additions & 0 deletions mail_gateway/controllers/discuss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 Dixmit
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.addons.mail.controllers.thread import ThreadController


class GatewayThreadController(ThreadController):
def _get_allowed_message_post_params(self):
result = super()._get_allowed_message_post_params()
result.add("gateway_notifications")
return result

Check warning on line 11 in mail_gateway/controllers/discuss.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/discuss.py#L9-L11

Added lines #L9 - L11 were not covered by tests
85 changes: 85 additions & 0 deletions mail_gateway/controllers/gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright 2024 Dixmit
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import json
import logging

from odoo.http import Controller, request, route

from odoo.addons.mail.models.discuss.mail_guest import add_guest_to_context

_logger = logging.getLogger(__name__)


class GatewayController(Controller):
@route(
"/gateway/<string:usage>/<string:token>/update",
type="http",
auth="public",
methods=["GET", "POST"],
csrf=False,
)
@add_guest_to_context
def post_update(self, usage, token, *args, **kwargs):
if request.httprequest.method == "GET":
bot_data = request.env["mail.gateway"]._get_gateway(

Check warning on line 25 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L25

Added line #L25 was not covered by tests
token, gateway_type=usage, state="pending"
)
if not bot_data:
return request.make_response(

Check warning on line 29 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L29

Added line #L29 was not covered by tests
json.dumps({}),
[
("Content-Type", "application/json"),
],
)
return (

Check warning on line 35 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L35

Added line #L35 was not covered by tests
request.env["mail.gateway.%s" % usage]
.with_user(bot_data["webhook_user_id"])
.with_company(bot_data["company_id"])
._receive_get_update(bot_data, request, **kwargs)
)
bot_data = request.env["mail.gateway"]._get_gateway(

Check warning on line 41 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L41

Added line #L41 was not covered by tests
token, gateway_type=usage, state="integrated"
)
if not bot_data:
_logger.warning(

Check warning on line 45 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L45

Added line #L45 was not covered by tests
"Gateway was not found for token %s with usage %s", token, usage
)
return request.make_response(

Check warning on line 48 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L48

Added line #L48 was not covered by tests
json.dumps({}),
[
("Content-Type", "application/json"),
],
)
jsonrequest = json.loads(

Check warning on line 54 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L54

Added line #L54 was not covered by tests
request.httprequest.get_data().decode(request.httprequest.charset)
)
dispatcher = (

Check warning on line 57 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L57

Added line #L57 was not covered by tests
request.env["mail.gateway.%s" % usage]
.with_user(bot_data["webhook_user_id"])
.with_context(no_gateway_notification=True)
)
if not dispatcher._verify_update(bot_data, jsonrequest):
_logger.warning(

Check warning on line 63 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L63

Added line #L63 was not covered by tests
"Message could not be verified for token %s with usage %s", token, usage
)
return request.make_response(

Check warning on line 66 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L66

Added line #L66 was not covered by tests
json.dumps({}),
[
("Content-Type", "application/json"),
],
)
_logger.debug(

Check warning on line 72 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L72

Added line #L72 was not covered by tests
"Received message for token %s with usage %s: %s",
token,
usage,
json.dumps(jsonrequest),
)
gateway = dispatcher.env["mail.gateway"].browse(bot_data["id"])
dispatcher._receive_update(gateway, jsonrequest)
return request.make_response(

Check warning on line 80 in mail_gateway/controllers/gateway.py

View check run for this annotation

Codecov / codecov/patch

mail_gateway/controllers/gateway.py#L78-L80

Added lines #L78 - L80 were not covered by tests
json.dumps({}),
[
("Content-Type", "application/json"),
],
)
12 changes: 12 additions & 0 deletions mail_gateway/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def pre_init_hook(env):
"""
The objective of this hook is to speed up the installation
of the module on an existing Odoo instance.

Without this script, big databases can take a long time to install this
module.
"""
env.cr.execute(
"""ALTER TABLE mail_message
ADD COLUMN IF NOT EXISTS gateway_channel_id int"""
)
Loading