Skip to content

Commit 319405b

Browse files
committed
Merge PR #1614 into 17.0
Signed-off-by pedrobaeza
2 parents 6a03073 + 56e5c2d commit 319405b

File tree

71 files changed

+4511
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4511
-0
lines changed

mail_gateway/README.rst

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
============
2+
Mail Gateway
3+
============
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:1fc341f96ecbd2a96d20eb12aae392827aa821f05dbda6cc30a702d19a58f223
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
20+
:target: https://github.com/OCA/social/tree/17.0/mail_gateway
21+
:alt: OCA/social
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_gateway
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module will allow you to integrate an external chat system in your
32+
Odoo system. It requires extra modules with the specific configuration
33+
of each chat system, like mail_gateway_telegram or
34+
mail_gateway_whatsapp.
35+
36+
This way, a group of users can respond customers or any other set of
37+
partners within Odoo, but the messages will be sent through the external
38+
chat system.
39+
40+
**Table of contents**
41+
42+
.. contents::
43+
:local:
44+
45+
Usage
46+
=====
47+
48+
When external messages are received, they will be directly sent to the
49+
discuss menu. Answering to these messages will send the answer to the
50+
external contact. We can assign this messages to any record using the
51+
message actions. Also, we can assign the sender to a partner using the
52+
followers menu and selecting the partner.
53+
54+
On a standard record associated to a partner with external chat, we can
55+
send messages to the external contact directly selecting the methods of
56+
the partner. To use this, we just need to use the
57+
58+
It is recomended to enable chatter notification to all users that will
59+
receive messages from gateways.
60+
61+
Bug Tracker
62+
===========
63+
64+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
65+
In case of trouble, please check there if your issue has already been reported.
66+
If you spotted it first, help us to smash it by providing a detailed and welcomed
67+
`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**>`_.
68+
69+
Do not contact contributors directly about support or help with technical issues.
70+
71+
Credits
72+
=======
73+
74+
Authors
75+
-------
76+
77+
* Creu Blanca
78+
* Dixmit
79+
80+
Contributors
81+
------------
82+
83+
- Enric Tobella
84+
- Olga Marco
85+
86+
Other credits
87+
-------------
88+
89+
This work has been funded by AEOdoo (Asociación Española de Odoo -
90+
https://www.aeodoo.org)
91+
92+
Maintainers
93+
-----------
94+
95+
This module is maintained by the OCA.
96+
97+
.. image:: https://odoo-community.org/logo.png
98+
:alt: Odoo Community Association
99+
:target: https://odoo-community.org
100+
101+
OCA, or the Odoo Community Association, is a nonprofit organization whose
102+
mission is to support the collaborative development of Odoo features and
103+
promote its widespread use.
104+
105+
This module is part of the `OCA/social <https://github.com/OCA/social/tree/17.0/mail_gateway>`_ project on GitHub.
106+
107+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

mail_gateway/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import controllers
2+
from . import models
3+
4+
from .hooks import pre_init_hook
5+
from . import wizards

mail_gateway/__manifest__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2024 Dixmit
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Mail Gateway",
6+
"summary": "Base module for gateway communications",
7+
"version": "17.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "Creu Blanca,Dixmit,Odoo Community Association (OCA)",
10+
"website": "https://github.com/OCA/social",
11+
"depends": ["mail"],
12+
"pre_init_hook": "pre_init_hook",
13+
"data": [
14+
"wizards/mail_compose_gateway_message.xml",
15+
"wizards/mail_message_gateway_link.xml",
16+
"wizards/mail_message_gateway_send.xml",
17+
"wizards/mail_guest_manage.xml",
18+
"security/security.xml",
19+
"security/ir.model.access.csv",
20+
"views/mail_gateway.xml",
21+
"views/res_partner_gateway_channel.xml",
22+
"views/mail_guest_views.xml",
23+
],
24+
"assets": {
25+
"web.assets_backend": [
26+
"mail_gateway/static/src/components/**/*",
27+
"mail_gateway/static/src/core/**/*",
28+
"mail_gateway/static/src/models/**/*",
29+
],
30+
},
31+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import gateway
2+
from . import discuss
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2024 Dixmit
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
from odoo.addons.mail.controllers.thread import ThreadController
5+
6+
7+
class GatewayThreadController(ThreadController):
8+
def _get_allowed_message_post_params(self):
9+
result = super()._get_allowed_message_post_params()
10+
result.add("gateway_notifications")
11+
return result
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2024 Dixmit
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
import json
5+
import logging
6+
7+
from odoo.http import Controller, request, route
8+
9+
from odoo.addons.mail.models.discuss.mail_guest import add_guest_to_context
10+
11+
_logger = logging.getLogger(__name__)
12+
13+
14+
class GatewayController(Controller):
15+
@route(
16+
"/gateway/<string:usage>/<string:token>/update",
17+
type="http",
18+
auth="public",
19+
methods=["GET", "POST"],
20+
csrf=False,
21+
)
22+
@add_guest_to_context
23+
def post_update(self, usage, token, *args, **kwargs):
24+
if request.httprequest.method == "GET":
25+
bot_data = request.env["mail.gateway"]._get_gateway(
26+
token, gateway_type=usage, state="pending"
27+
)
28+
if not bot_data:
29+
return request.make_response(
30+
json.dumps({}),
31+
[
32+
("Content-Type", "application/json"),
33+
],
34+
)
35+
return (
36+
request.env["mail.gateway.%s" % usage]
37+
.with_user(bot_data["webhook_user_id"])
38+
.with_company(bot_data["company_id"])
39+
._receive_get_update(bot_data, request, **kwargs)
40+
)
41+
bot_data = request.env["mail.gateway"]._get_gateway(
42+
token, gateway_type=usage, state="integrated"
43+
)
44+
if not bot_data:
45+
_logger.warning(
46+
"Gateway was not found for token %s with usage %s", token, usage
47+
)
48+
return request.make_response(
49+
json.dumps({}),
50+
[
51+
("Content-Type", "application/json"),
52+
],
53+
)
54+
jsonrequest = json.loads(
55+
request.httprequest.get_data().decode(request.httprequest.charset)
56+
)
57+
dispatcher = (
58+
request.env["mail.gateway.%s" % usage]
59+
.with_user(bot_data["webhook_user_id"])
60+
.with_context(no_gateway_notification=True)
61+
)
62+
if not dispatcher._verify_update(bot_data, jsonrequest):
63+
_logger.warning(
64+
"Message could not be verified for token %s with usage %s", token, usage
65+
)
66+
return request.make_response(
67+
json.dumps({}),
68+
[
69+
("Content-Type", "application/json"),
70+
],
71+
)
72+
_logger.debug(
73+
"Received message for token %s with usage %s: %s",
74+
token,
75+
usage,
76+
json.dumps(jsonrequest),
77+
)
78+
gateway = dispatcher.env["mail.gateway"].browse(bot_data["id"])
79+
dispatcher._receive_update(gateway, jsonrequest)
80+
return request.make_response(
81+
json.dumps({}),
82+
[
83+
("Content-Type", "application/json"),
84+
],
85+
)

mail_gateway/hooks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def pre_init_hook(env):
2+
"""
3+
The objective of this hook is to speed up the installation
4+
of the module on an existing Odoo instance.
5+
6+
Without this script, big databases can take a long time to install this
7+
module.
8+
"""
9+
env.cr.execute(
10+
"""ALTER TABLE mail_message
11+
ADD COLUMN IF NOT EXISTS gateway_channel_id int"""
12+
)

0 commit comments

Comments
 (0)