@ -0,0 +1,48 @@ |
|||||
|
.. image:: https://img.shields.io/badge/license-LGPL--3-green.svg |
||||
|
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html |
||||
|
:alt: License: LGPL-3 |
||||
|
|
||||
|
Push Notification From ChatBox |
||||
|
============================== |
||||
|
* Push Notification From ChatBox is valuable for teams looking to streamline communication and enhance productivity within the Odoo platform. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
* Install the pyfcm python package |
||||
|
* Install our module and make sure that your instance served over https.Firebase is intent on being a highly secure solution, so they have chosen to require the use of a https for all communication and http is not working. |
||||
|
* After installation of module its important that allow the notification access in the webpage |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
Lesser General Public License, Version 3 (LGPL v3). |
||||
|
(https://www.gnu.org/licenses/lgpl-3.0-standalone.html) |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
Developer: (V17) Gokul P I , Contact: odoo@cybrosys.com |
||||
|
|
||||
|
Contacts |
||||
|
-------- |
||||
|
* Mail Contact : odoo@cybrosys.com |
||||
|
* Website : https://cybrosys.com |
||||
|
|
||||
|
Bug Tracker |
||||
|
----------- |
||||
|
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
||||
|
|
||||
|
Maintainer |
||||
|
========== |
||||
|
.. image:: https://cybrosys.com/images/logo.png |
||||
|
:target: https://cybrosys.com |
||||
|
|
||||
|
This module is maintained by Cybrosys Technologies. |
||||
|
|
||||
|
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Further information |
||||
|
=================== |
||||
|
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import controllers |
||||
|
from . import models |
@ -0,0 +1,53 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
{ |
||||
|
"name": "Push Notification From ChatBox", |
||||
|
'version': '17.0.1.0.0', |
||||
|
'category': 'Discuss,Extra Tools', |
||||
|
'summary': 'With Push Notification From ChatBox, users can respond promptly' |
||||
|
' to important messages, improving communication efficiency.', |
||||
|
'description': 'Push Notification From ChatBox is valuable for teams ' |
||||
|
'looking to streamline communication and enhance ' |
||||
|
'productivity within the Odoo platform.', |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': "https://www.cybrosys.com", |
||||
|
"depends": ["web", "mail"], |
||||
|
"data": [ |
||||
|
"security/ir.model.access.csv", |
||||
|
"views/res_config_settings_views.xml" |
||||
|
], |
||||
|
'assets': { |
||||
|
'web.assets_backend': [ |
||||
|
"https://www.gstatic.com/firebasejs/8.4.3/firebase-app.js", |
||||
|
"https://www.gstatic.com/firebasejs/8.4.3/firebase-messaging.js", |
||||
|
"mail_push_notification/static/src/js/firebase.js", |
||||
|
], |
||||
|
}, |
||||
|
"external_dependencies": {"python": ["pyfcm"]}, |
||||
|
'images': ['static/description/banner.png'], |
||||
|
'license': 'LGPL-3', |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import mail_push_notification |
@ -0,0 +1,128 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
import json |
||||
|
from odoo import http |
||||
|
from odoo.http import request |
||||
|
|
||||
|
|
||||
|
class MailPushNotification(http.Controller): |
||||
|
"""Controller for handling push notifications using Firebase |
||||
|
Cloud Messaging""" |
||||
|
|
||||
|
@http.route('/firebase-messaging-sw.js', type='http', auth="public") |
||||
|
def firebase_http(self): |
||||
|
"""Returns the Firebase service worker script. |
||||
|
:return: The Firebase service worker script. |
||||
|
:rtype: str""" |
||||
|
if request.env.company and request.env.company.push_notification: |
||||
|
firebase_js = """ |
||||
|
this.addEventListener('fetch', function(e) { |
||||
|
e.respondWith( |
||||
|
caches.match(e.request).then(function(response) { |
||||
|
return response || fetch(e.request); |
||||
|
}) |
||||
|
); |
||||
|
}); |
||||
|
importScripts('https://www.gstatic.com/firebasejs/8.4.2/firebase-app.js'); |
||||
|
importScripts('https://www.gstatic.com/firebasejs/8.4.2/firebase-messaging.js'); |
||||
|
var firebaseConfig = { |
||||
|
apiKey: '%s', |
||||
|
authDomain: '%s', |
||||
|
projectId: '%s', |
||||
|
storageBucket: '%s', |
||||
|
messagingSenderId: '%s', |
||||
|
appId: '%s', |
||||
|
measurementId: '%s', |
||||
|
}; |
||||
|
firebase.initializeApp(firebaseConfig); |
||||
|
const messaging = firebase.messaging(); |
||||
|
messaging.setBackgroundMessageHandler(function(payload) { |
||||
|
const notificationTitle = "Background Message Title"; |
||||
|
const notificationOptions = { |
||||
|
body: payload.notification.body, |
||||
|
icon:'/mail_push_notification/static/description/icon.png', |
||||
|
}; |
||||
|
return self.registration.showNotification( |
||||
|
notificationTitle, |
||||
|
notificationOptions, |
||||
|
); |
||||
|
}); |
||||
|
""" % ( |
||||
|
request.env.company.api_key, request.env.company.auth_domain, |
||||
|
request.env.company.project_id_firebase, |
||||
|
request.env.company.storage_bucket, |
||||
|
request.env.company.messaging_sender_id_firebase, |
||||
|
request.env.company.app_id_firebase, |
||||
|
request.env.company.measurement_id_firebase) |
||||
|
else: |
||||
|
firebase_js = """ |
||||
|
this.addEventListener('fetch', function(e) { |
||||
|
e.respondWith( |
||||
|
caches.match(e.request).then(function(response) { |
||||
|
return response || fetch(e.request); |
||||
|
}) |
||||
|
); |
||||
|
}); |
||||
|
""" |
||||
|
return http.request.make_response(firebase_js, [ |
||||
|
('Content-Type', 'text/javascript')]) |
||||
|
|
||||
|
@http.route('/push_notification', type='http', auth="public", |
||||
|
csrf=False) |
||||
|
def get_registration_tokens(self, **post): |
||||
|
"""Handles registration tokens for push notifications. |
||||
|
Create a new registration token if it doesn't already exist |
||||
|
:param post: POST request data containing registration token. |
||||
|
:type post: dict |
||||
|
""" |
||||
|
user_notification = request.env['push.notification'].sudo().search( |
||||
|
[('register_id', '=', post.get('name'))], limit=1) |
||||
|
if not user_notification: |
||||
|
request.env['push.notification'].sudo().create({ |
||||
|
'register_id': post.get('name'), |
||||
|
'user_id': request.env.user.id |
||||
|
}) |
||||
|
|
||||
|
@http.route('/firebase_config_details', type='json', auth="public") |
||||
|
def send_datas(self): |
||||
|
"""Sends Firebase configuration details. |
||||
|
:return: JSON containing Firebase configuration details. |
||||
|
:rtype: str""" |
||||
|
if request.env.company and request.env.company.push_notification: |
||||
|
return json.dumps({ |
||||
|
'vapid': request.env.company.vapid, |
||||
|
'config': { |
||||
|
'apiKey': request.env.company.api_key, |
||||
|
'authDomain': request.env.company.auth_domain, |
||||
|
'projectId': request.env.company.project_id_firebase, |
||||
|
'storageBucket': request.env.company.storage_bucket, |
||||
|
'messagingSenderId': request.env.company.messaging_sender_id_firebase, |
||||
|
'appId': request.env.company.app_id_firebase, |
||||
|
'measurementId': request.env.company.measurement_id_firebase |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
@http.route('/firebase_credentials', type="json", auth="public") |
||||
|
def firebase_credentials(self, **kw): |
||||
|
""" Retrieve Firebase credentials for the current company.""" |
||||
|
return {'id': request.env.company.id, |
||||
|
'push_notification': request.env.company.push_notification} |
@ -0,0 +1,6 @@ |
|||||
|
## Module <mail_push_notification> |
||||
|
|
||||
|
#### 01.12.2023 |
||||
|
#### Version 17.0.1.0.0 |
||||
|
#### ADD |
||||
|
- Initial commit for Push Notification From ChatBox |
@ -0,0 +1,25 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import mail_thread |
||||
|
from . import push_notification |
||||
|
from . import res_company |
||||
|
from . import res_config_settings |
@ -0,0 +1,66 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from pyfcm import FCMNotification |
||||
|
from odoo import models |
||||
|
|
||||
|
|
||||
|
class MailThread(models.AbstractModel): |
||||
|
"""Inherits MailThread to send notifications using chatterbox""" |
||||
|
_inherit = 'mail.thread' |
||||
|
|
||||
|
def _notify_thread(self, message, msg_vals=False, **kwargs): |
||||
|
"""Supering the _notify_thread() function to fetch the details of the |
||||
|
chat message and push that message as a notification """ |
||||
|
res = super(MailThread, self)._notify_thread(message, |
||||
|
msg_vals=msg_vals, |
||||
|
**kwargs) |
||||
|
msg = message.read() |
||||
|
if self.env.company.push_notification and self.env.user.has_group( |
||||
|
'base.group_user'): |
||||
|
try: |
||||
|
push_service = FCMNotification( |
||||
|
api_key=self.env.company.server_key) |
||||
|
receiver_id = False |
||||
|
domain = [] |
||||
|
if self.channel_type != 'channel': |
||||
|
for partner in self.channel_partner_ids: |
||||
|
if partner.id != msg[0]['author_id'][0]: |
||||
|
receiver_id = self.env['res.users'].search([( |
||||
|
'partner_id', |
||||
|
'=', |
||||
|
partner.id)]) |
||||
|
if receiver_id: |
||||
|
domain = [('user_id', '=', |
||||
|
receiver_id.id)] |
||||
|
push_service.notify_multiple_devices( |
||||
|
registration_ids=[registration_id.register_id for |
||||
|
registration_id in |
||||
|
self.env['push.notification'].search( |
||||
|
domain)], |
||||
|
message_title='Send by ' + msg[0]['author_id'][1], |
||||
|
message_body=msg[0]['description'], |
||||
|
extra_notification_kwargs={ |
||||
|
'click_action': '/web' |
||||
|
}) |
||||
|
except Exception: |
||||
|
pass |
||||
|
return res |
@ -0,0 +1,34 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class PushNotification(models.Model): |
||||
|
"""Using this class create the registration id for the user to send |
||||
|
push notifications""" |
||||
|
_name = 'push.notification' |
||||
|
_description = 'Web Push Notification' |
||||
|
|
||||
|
user_id = fields.Many2one("res.users", string="Firebase User", |
||||
|
help="Corresponding Firebase User") |
||||
|
register_id = fields.Char(string="Registration Id", |
||||
|
help="Firebase Registration Token") |
@ -0,0 +1,56 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class ResCompany(models.Model): |
||||
|
"""Inheriting this class to add the firebase credential need in config |
||||
|
settings and use the multi company feature""" |
||||
|
_inherit = 'res.company' |
||||
|
|
||||
|
push_notification = fields.Boolean(string='Enable Push Notification', |
||||
|
help="Enable Web Push Notification") |
||||
|
server_key = fields.Char(string="Server Key", |
||||
|
help="Server Key of the firebase") |
||||
|
vapid = fields.Char(string="Vapid", help='VapId of the firebase', |
||||
|
readonly=False) |
||||
|
api_key = fields.Char(string="Api Key", |
||||
|
help='Corresponding apiKey of firebase config', |
||||
|
readonly=False) |
||||
|
auth_domain = fields.Char(string="Auth Domain", |
||||
|
help='Corresponding authDomain of firebase ' |
||||
|
'config') |
||||
|
project_id_firebase = fields.Char(string="Project Id", |
||||
|
help='Corresponding projectId of ' |
||||
|
'firebase config') |
||||
|
storage_bucket = fields.Char(string="Storage Bucket", |
||||
|
help='Corresponding storageBucket of ' |
||||
|
'firebase config') |
||||
|
messaging_sender_id_firebase = fields.Char(string="Messaging Sender Id", |
||||
|
help='Corresponding ' |
||||
|
'messagingSenderId of ' |
||||
|
'firebase config') |
||||
|
app_id_firebase = fields.Char(string="App Id", |
||||
|
help='Corresponding appId of firebase config') |
||||
|
measurement_id_firebase = fields.Char(string="Measurement Id", |
||||
|
help='Corresponding measurementId ' |
||||
|
'of firebase config') |
@ -0,0 +1,116 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gokul PI (<https://www.cybrosys.com>) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from pyfcm import FCMNotification |
||||
|
from odoo import fields, models, _ |
||||
|
|
||||
|
|
||||
|
class ResConfigSettings(models.TransientModel): |
||||
|
"""Inheriting the ResConfigSettings to add the firebase config details |
||||
|
to push notifications """ |
||||
|
_inherit = 'res.config.settings' |
||||
|
|
||||
|
push_notification = fields.Boolean(string='Enable Push Notification', |
||||
|
help="Enable Web Push Notification", |
||||
|
related='company_id.push_notification', |
||||
|
readonly=False) |
||||
|
server_key = fields.Char(string="Server Key", |
||||
|
help="Server Key of the firebase", |
||||
|
related='company_id.server_key', readonly=False) |
||||
|
vapid = fields.Char(string="Vapid", help='VapId of the firebase', |
||||
|
related='company_id.vapid', readonly=False) |
||||
|
api_key = fields.Char(string="Api Key", |
||||
|
help='Corresponding apiKey of firebase config', |
||||
|
related='company_id.api_key', readonly=False) |
||||
|
auth_domain = fields.Char(string="Auth Domain", |
||||
|
help='Corresponding authDomain of firebase ' |
||||
|
'config', |
||||
|
related='company_id.auth_domain', readonly=False) |
||||
|
project_id_firebase = fields.Char(string="Project Id", |
||||
|
help='Corresponding projectId of ' |
||||
|
'firebase config', |
||||
|
related='company_id.project_id_firebase', |
||||
|
readonly=False) |
||||
|
storage_bucket = fields.Char(string="Storage Bucket", |
||||
|
help='Corresponding storageBucket of ' |
||||
|
'firebase config', |
||||
|
related='company_id.storage_bucket', |
||||
|
readonly=False) |
||||
|
messaging_sender_id_firebase = fields.Char(string="Messaging Sender Id", |
||||
|
help='Corresponding ' |
||||
|
'messagingSenderId of ' |
||||
|
'firebase config', |
||||
|
related='company_id' |
||||
|
'.messaging_sender_id_firebase', |
||||
|
readonly=False) |
||||
|
app_id_firebase = fields.Char(string="App Id", |
||||
|
help='Corresponding appId of firebase config', |
||||
|
related='company_id.app_id_firebase', |
||||
|
readonly=False) |
||||
|
measurement_id_firebase = fields.Char(string="Measurement Id", |
||||
|
help='Corresponding measurementId ' |
||||
|
'of firebase config', |
||||
|
related='company_id' |
||||
|
'.measurement_id_firebase', |
||||
|
readonly=False) |
||||
|
|
||||
|
def test_connection(self): |
||||
|
"""Test connection to firebase using the firebase credentials""" |
||||
|
if self.env.company.push_notification: |
||||
|
try: |
||||
|
push_service = FCMNotification( |
||||
|
api_key=self.env.company.server_key) |
||||
|
registration_ids = self.env['push.notification'].sudo().search( |
||||
|
[('user_id', '=', self.env.user.id)]) |
||||
|
push_service.notify_multiple_devices( |
||||
|
registration_ids=[registration_id.register_id for |
||||
|
registration_id in registration_ids], |
||||
|
message_title='Test Connection', |
||||
|
message_body='Successfully', |
||||
|
extra_notification_kwargs={ |
||||
|
'click_action': '/web' |
||||
|
}) |
||||
|
return { |
||||
|
'type': 'ir.actions.client', |
||||
|
'tag': 'display_notification', |
||||
|
'params': { |
||||
|
'type': 'success', |
||||
|
'message': _("Connection successfully established"), |
||||
|
'next': { |
||||
|
'type': 'ir.actions.client', |
||||
|
'tag': 'reload_context', |
||||
|
}, |
||||
|
} |
||||
|
} |
||||
|
except: |
||||
|
return { |
||||
|
'type': 'ir.actions.client', |
||||
|
'tag': 'display_notification', |
||||
|
'params': { |
||||
|
'type': 'danger', |
||||
|
'message': _( |
||||
|
"Failed to connect with firebase"), |
||||
|
'next': { |
||||
|
'type': 'ir.actions.client', |
||||
|
'tag': 'reload_context', |
||||
|
}, |
||||
|
} |
||||
|
} |
|
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 589 B |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 565 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 967 B |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 1.3 MiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 215 KiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 159 KiB |
After Width: | Height: | Size: 132 KiB |
After Width: | Height: | Size: 124 KiB |
After Width: | Height: | Size: 133 KiB |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 143 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 201 KiB |
After Width: | Height: | Size: 220 KiB |
After Width: | Height: | Size: 180 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 463 KiB |
After Width: | Height: | Size: 222 KiB |
After Width: | Height: | Size: 212 KiB |
After Width: | Height: | Size: 285 KiB |
After Width: | Height: | Size: 141 KiB |
After Width: | Height: | Size: 266 KiB |
After Width: | Height: | Size: 163 KiB |
After Width: | Height: | Size: 203 KiB |
After Width: | Height: | Size: 248 KiB |
After Width: | Height: | Size: 424 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 7.3 KiB |
@ -0,0 +1,89 @@ |
|||||
|
/** @odoo-module **/ |
||||
|
import { jsonrpc } from "@web/core/network/rpc_service"; |
||||
|
/** |
||||
|
* Odoo module for handling Firebase push notifications. |
||||
|
* |
||||
|
* This module initializes Firebase messaging and handles push notifications |
||||
|
* for the current session's company. It also registers the service worker for |
||||
|
* handling notifications if the company has push notifications enabled. |
||||
|
* |
||||
|
* @module mail_push_notification |
||||
|
*/ |
||||
|
var vapid = ''; |
||||
|
var firebaseConfig = {}; |
||||
|
var push_notification = false; |
||||
|
/** |
||||
|
* Sends an RPC query to retrieve push notification settings for the current company. |
||||
|
* |
||||
|
* @function |
||||
|
* @returns {Promise} A promise that resolves with the push notification settings. |
||||
|
*/ |
||||
|
jsonrpc("/firebase_credentials", {}).then(function(data) { |
||||
|
if (data) { |
||||
|
if (data.push_notification) { |
||||
|
push_notification = true; |
||||
|
if ("serviceWorker" in navigator) { |
||||
|
navigator.serviceWorker.register("/firebase-messaging-sw.js").then(function () {}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
jsonrpc("/firebase_config_details", {}).then(function (data) { |
||||
|
if (data) { |
||||
|
var json = JSON.parse(data); |
||||
|
vapid = json.vapid; |
||||
|
firebaseConfig = json.config; |
||||
|
/** |
||||
|
* Initializes Firebase messaging and sets up event listeners for incoming messages. |
||||
|
* |
||||
|
* @function |
||||
|
*/ |
||||
|
firebase.initializeApp(firebaseConfig); |
||||
|
const messaging = firebase.messaging(); |
||||
|
/** |
||||
|
* Handles incoming push notification messages. |
||||
|
* |
||||
|
* @function |
||||
|
* @param {Object} payload - The notification payload. |
||||
|
*/ |
||||
|
messaging.onMessage((payload) => { |
||||
|
const notificationOptions = { |
||||
|
body: payload.notification.body, |
||||
|
}; |
||||
|
let notification = payload.notification; |
||||
|
navigator.serviceWorker.getRegistrations().then((registration) => { |
||||
|
registration[0].showNotification(notification.title, notificationOptions); |
||||
|
}); |
||||
|
}); |
||||
|
/** |
||||
|
* Requests permission for receiving push notifications and retrieves the registration token. |
||||
|
* |
||||
|
* @function |
||||
|
*/ |
||||
|
messaging.requestPermission().then(function () { |
||||
|
/** |
||||
|
* Retrieves the registration token and sends it to the server for subscription. |
||||
|
* |
||||
|
* @function |
||||
|
* @param {string} vapidKey - The VAPID key for authentication. |
||||
|
*/ |
||||
|
messaging.getToken({ vapidKey: vapid }).then((currentToken) => { |
||||
|
if (currentToken) { |
||||
|
/** |
||||
|
* Sends a POST request to the server with the registration token. |
||||
|
* |
||||
|
* @function |
||||
|
* @param {string} token - The registration token. |
||||
|
*/ |
||||
|
$.post("/push_notification", { |
||||
|
name: currentToken |
||||
|
}); |
||||
|
} else { |
||||
|
console.log('No registration token found'); |
||||
|
} |
||||
|
}).catch((err) => { |
||||
|
console.log('There is an error has occurred while attempting to retrieve the token.', err); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
}); |
@ -0,0 +1,114 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!-- Inheriting the config setting and add the fields for connecting to |
||||
|
Firebase --> |
||||
|
<record id="res_config_settings_view_form" model="ir.ui.view"> |
||||
|
<field name="name"> |
||||
|
res.config.settings.view.form.inherit.mail.push.notification |
||||
|
</field> |
||||
|
<field name="model">res.config.settings</field> |
||||
|
<field name="inherit_id" |
||||
|
ref="base_setup.res_config_settings_view_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//form" position="inside"> |
||||
|
<app data-string="Push Notification From ChatBox" |
||||
|
string="Push Notification From ChatBox" |
||||
|
name="mail_push_notification"> |
||||
|
<block title="Push Notification From ChatBox" |
||||
|
name="mail_push_notification_setting_container"> |
||||
|
</block> |
||||
|
</app> |
||||
|
<div class="row mt16 o_settings_container"> |
||||
|
<div id="firebase_setting" |
||||
|
class="col-xs-12 col-md-6 o_setting_box"> |
||||
|
<div class="o_setting_left_pane"> |
||||
|
<field name="push_notification"/> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="push_notification"/> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div id="firebase_other_setting" |
||||
|
class="col-xs-12 col-md-12 o_setting_box" |
||||
|
invisible="push_notification == False"> |
||||
|
<div class="o_setting_left_pane"> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="server_key" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="server_key" |
||||
|
required="push_notification==True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_left_pane"> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="vapid" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="vapid" |
||||
|
required="push_notification == True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_left_pane"> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="api_key" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="api_key" |
||||
|
required="push_notification == True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="auth_domain" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="auth_domain" |
||||
|
required="push_notification == True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="project_id_firebase" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="project_id_firebase" |
||||
|
required="push_notification == True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="storage_bucket" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="storage_bucket" |
||||
|
required="push_notification == True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="messaging_sender_id_firebase" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="messaging_sender_id_firebase" |
||||
|
required="push_notification== True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="app_id_firebase" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="app_id_firebase" |
||||
|
required="push_notification == True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="o_setting_right_pane"> |
||||
|
<label for="measurement_id_firebase" |
||||
|
class="col-2 col-lg-2 o_light_label"/> |
||||
|
<field name="measurement_id_firebase" |
||||
|
required="push_notification == True" |
||||
|
password="1"/> |
||||
|
</div> |
||||
|
<div class="col-lg-6 col-8 d-flex flex-row-reverse |
||||
|
o_setting_box"> |
||||
|
<button name="test_connection" |
||||
|
string="Test Connection" |
||||
|
type="object" class="btn-primary"/> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |