Andhitia Rama
7 years ago
8 changed files with 202 additions and 0 deletions
-
54twilio_sms_client/README.rst
-
5twilio_sms_client/__init__.py
-
26twilio_sms_client/__openerp__.py
-
10twilio_sms_client/data/keychain.xml
-
6twilio_sms_client/models/__init__.py
-
23twilio_sms_client/models/keychain.py
-
78twilio_sms_client/models/sms_gateway.py
-
BINtwilio_sms_client/static/description/icon.png
@ -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 <https://github.com/OCA/ovh_sms_client/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 <yvan@julius.fr> |
|||
* MonsieurB <monsieurb@saaslys.com> |
|||
|
|||
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. |
|||
|
@ -0,0 +1,5 @@ |
|||
# coding: utf-8 |
|||
# Copyright 2017 OpenSynergy Indonesia <https://opensynergy-indonesia.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import models |
@ -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, |
|||
} |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data noupdate="1"> |
|||
<record id="keychain_twilio" model="keychain.account"> |
|||
<field name="name">Twilio sms default</field> |
|||
<field name="namespace">twilio_provider</field> |
|||
<field name="technical_name">twilio_default_account</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
@ -0,0 +1,6 @@ |
|||
# coding: utf-8 |
|||
# Copyright 2017 OpenSynery Indonesia <https://opensynergy-indonesia.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import sms_gateway |
|||
from . import keychain |
@ -0,0 +1,23 @@ |
|||
# coding: utf-8 |
|||
# Copyright 2017 OpenSynergy Indonesia <https://opensynergy-indonesia.com> |
|||
# 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 |
@ -0,0 +1,78 @@ |
|||
# coding: utf-8 |
|||
# Copyright 2017 OpenSynergy Indonesia <https://opensynergy-indonesia.com> |
|||
# 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"] |
|||
) |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
Write
Preview
Loading…
Cancel
Save
Reference in new issue