diff --git a/twilio_sms_client/README.rst b/twilio_sms_client/README.rst new file mode 100644 index 0000000..c4b7471 --- /dev/null +++ b/twilio_sms_client/README.rst @@ -0,0 +1,54 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +=============== +SMS client OVH +=============== + +This module provide OVH fields to create OVH gateway. + +Usage +===== + +To use this module, you need to: + +* go to settings > technical > telephony >gateway configuration and select OVH http in method +* go to settings > technical > keychain and set your credentials + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + + +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 smashing it by providing a detailed and welcomed feedback + +Credits +======= + +Contributors +------------ + +* Valentin Chemiere +* Yvan Party +* MonsieurB + +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 http://odoo-community.org. + diff --git a/twilio_sms_client/__init__.py b/twilio_sms_client/__init__.py new file mode 100644 index 0000000..8bb27f1 --- /dev/null +++ b/twilio_sms_client/__init__.py @@ -0,0 +1,5 @@ +# coding: utf-8 +# Copyright 2017 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/twilio_sms_client/__openerp__.py b/twilio_sms_client/__openerp__.py new file mode 100644 index 0000000..785a274 --- /dev/null +++ b/twilio_sms_client/__openerp__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 OpenSynergy Indonesia + +{ + "name": "Twilio SMS Client", + "version": "8.0.1.0.0", + "license": "AGPL-3", + "depends": ["mail", + "base_sms_client", + "base_suspend_security", + "keychain", + ], + "external_dependency": { + "python": [ + "twilio", + ], + }, + "author": "OpenSynergy Indonesia" + "Odoo Community Association (OCA),Akretion", + "website": "https://github.com/oca/connector-telephony", + "category": "Tools", + "data": [ + "data/keychain.xml", + ], + "installable": True, +} diff --git a/twilio_sms_client/data/keychain.xml b/twilio_sms_client/data/keychain.xml new file mode 100644 index 0000000..c705e5d --- /dev/null +++ b/twilio_sms_client/data/keychain.xml @@ -0,0 +1,10 @@ + + + + + Twilio sms default + twilio_provider + twilio_default_account + + + diff --git a/twilio_sms_client/models/__init__.py b/twilio_sms_client/models/__init__.py new file mode 100644 index 0000000..0a23dc1 --- /dev/null +++ b/twilio_sms_client/models/__init__.py @@ -0,0 +1,6 @@ +# coding: utf-8 +# Copyright 2017 OpenSynery Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import sms_gateway +from . import keychain diff --git a/twilio_sms_client/models/keychain.py b/twilio_sms_client/models/keychain.py new file mode 100644 index 0000000..f443838 --- /dev/null +++ b/twilio_sms_client/models/keychain.py @@ -0,0 +1,23 @@ +# coding: utf-8 +# Copyright 2017 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields + +TWILIO_KEYCHAIN_NAMESPACE = "twilio_provider" + + +class Keychain(models.Model): + _inherit = "keychain.account" + + namespace = fields.Selection( + selection_add=[ + (TWILIO_KEYCHAIN_NAMESPACE, "twilio_sms"), + ], + ) + + def _twilio_provider_init_data(self): + return {} + + def _twilio_provider_validate_data(self, data): + return True diff --git a/twilio_sms_client/models/sms_gateway.py b/twilio_sms_client/models/sms_gateway.py new file mode 100644 index 0000000..4370023 --- /dev/null +++ b/twilio_sms_client/models/sms_gateway.py @@ -0,0 +1,78 @@ +# coding: utf-8 +# Copyright 2017 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import api, models, fields +from ..models.keychain import TWILIO_KEYCHAIN_NAMESPACE +from twilio.rest import Client +import logging + +_logger = logging.getLogger(__name__) + + +class SmsClient(models.Model): + _inherit = "sms.gateway" + + method = fields.Selection( + selection_add=[ + ("twilio", "TWILIO"), + ], + ) + + @api.multi + def _provider_get_provider_conf(self): + for rec in self: + keychain = rec.env["keychain.account"] + if rec._check_permissions(): + retrieve = keychain.suspend_security().retrieve + else: + retrieve = keychain.retrieve + accounts = retrieve( + [["namespace", "=", TWILIO_KEYCHAIN_NAMESPACE]]) + return accounts[0] + + +class SmsSms(models.Model): + _inherit = "sms.sms" + + @api.model + def _prepare_twilio(self): + + keychain_account = self.gateway_id._provider_get_provider_conf() + params = { + "twilio_account": keychain_account["login"], + "twilio_token": keychain_account.get_password(), + "from": self.gateway_id.from_provider, + "to": self._convert_to_e164(self.mobile), + "message": self.message, + } + if self.nostop: + params["noStop"] = 1 + if self.deferred: + params["deferred"] = self.deferred + if self.classes: + params["class"] = self.classes + if self.tag: + params["tag"] = self.tag + if self.coding: + params["smsCoding"] = self.coding + return params + + @api.model + def _convert_to_e164(self, erp_number): + to_dial_number = erp_number.replace(u"\xa0", u"") + return to_dial_number + + @api.multi + def _send_twilio(self): + self.ensure_one() + params = self._prepare_twilio() + client = Client( + params["twilio_account"], + params["twilio_token"], + ) + client.messages.create( + to=params["to"], + from_=params["from"], + body=params["message"] + ) diff --git a/twilio_sms_client/static/description/icon.png b/twilio_sms_client/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/twilio_sms_client/static/description/icon.png differ