diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c30e9008..10cfdbddf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ exclude: | - (?x) + #(?x) # Files and folders generated by bots, to avoid loops ^setup/|/static/description/index\.html$| # Maybe reactivate this when all README files include prettier ignore tags? diff --git a/setup/sms_clickatell/odoo/addons/sms_clickatell b/setup/sms_clickatell/odoo/addons/sms_clickatell new file mode 120000 index 000000000..13d433528 --- /dev/null +++ b/setup/sms_clickatell/odoo/addons/sms_clickatell @@ -0,0 +1 @@ +../../../../sms_clickatell \ No newline at end of file diff --git a/setup/sms_clickatell/setup.py b/setup/sms_clickatell/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sms_clickatell/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/sms_clickatell/README.rst b/sms_clickatell/README.rst new file mode 100644 index 000000000..cb6b91d43 --- /dev/null +++ b/sms_clickatell/README.rst @@ -0,0 +1,93 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======================================================================== +SMS Clickatell - Override Odoo Standard SMS gateway +======================================================================== + +Send SMS with Clickatell instead of Odoo SA IAP. + +Installation +============ + +To install this module, you need to: + +#. Just do an standard installation. + +Configuration +============= + +To configure this module, you need to: + +#. Go to Configuration, Technical, IAP Accounts and add your Clickatell +API key under an account named "sms.clickatell. + + +.. figure:: path/to/local/image.png + :alt: alternative description + :width: 600 px + +Usage +===== + +To use this module, you need to: + +#. Go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} + +.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt +.. branch is "8.0" for example + +Known issues / Roadmap +====================== + +* Extend to whatsapp msgs? + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Firstname Lastname +* Second Person + +Funders +------- + +The development of this module has been financially supported by: + +* Company 1 name +* Company 2 name + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/sms_clickatell/__init__.py b/sms_clickatell/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sms_clickatell/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sms_clickatell/__manifest__.py b/sms_clickatell/__manifest__.py new file mode 100644 index 000000000..09ca153d9 --- /dev/null +++ b/sms_clickatell/__manifest__.py @@ -0,0 +1,14 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "SMS Clickatell", + "summary": """ + Send SMS with Clickatell instead of Odoo SA IAP.""", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "author": "RPSJR, Odoo Community Association (OCA)", + "website": "https://github.com/oca/connector-telephony", + "depends": ["sms", "iap"], # Odoo SA. + "data": ["views/iap_account.xml"], + "demo": [], +} diff --git a/sms_clickatell/models/__init__.py b/sms_clickatell/models/__init__.py new file mode 100644 index 000000000..9a1d7d528 --- /dev/null +++ b/sms_clickatell/models/__init__.py @@ -0,0 +1 @@ +from . import iap_account, sms_api diff --git a/sms_clickatell/models/iap_account.py b/sms_clickatell/models/iap_account.py new file mode 100644 index 000000000..ece5b49b6 --- /dev/null +++ b/sms_clickatell/models/iap_account.py @@ -0,0 +1,10 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IapAccount(models.Model): + + _inherit = "iap.account" + + key = fields.Char() diff --git a/sms_clickatell/models/sms_api.py b/sms_clickatell/models/sms_api.py new file mode 100644 index 000000000..6f653b7cf --- /dev/null +++ b/sms_clickatell/models/sms_api.py @@ -0,0 +1,60 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import json + +import requests + +from odoo import api, models + + +class SmsApi(models.AbstractModel): + + _inherit = "sms.api" + + @api.model + def _contact_iap(self, local_endpoint, params): + account = self.env["iap.account"].get("sms.clickatell") + headers = { + "Content-Type": "application/json", + "Accept": "application/json", + "Authorization": account.key, + } + + if local_endpoint == "/iap/message_send": + messages = [ + {"channel": "sms", "to": number, "content": params["message"]} + for number in params["numbers"] + ] + + elif local_endpoint == "/iap/sms/1/send": + messages = [ + { + "channel": "sms", + "to": message["number"], + "content": message["content"], + } + for message in params["messages"] + ] + + values = json.dumps({"messages": messages}) + request = requests.post( + "https://platform.clickatell.com/v1/message", data=values, headers=headers + ) + response_list = request.json()["messages"] + params_list = params["messages"] + if type(request.json()) is dict: + response = [] + for resp_id in range(len(response_list)): + response.append( + { + **params_list[resp_id], + "state": ( + "success" + if "error" not in response_list[resp_id] + else "wrong_number_format" + ), + "credit": 2, + **response_list[resp_id], + } + ) + return response diff --git a/sms_clickatell/static/description/icon.png b/sms_clickatell/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sms_clickatell/static/description/icon.png differ diff --git a/sms_clickatell/views/iap_account.xml b/sms_clickatell/views/iap_account.xml new file mode 100644 index 000000000..9b76496c2 --- /dev/null +++ b/sms_clickatell/views/iap_account.xml @@ -0,0 +1,14 @@ + + + + + iap.account.form (in sms_clickatell) + iap.account + + + + + + + +