diff --git a/setup/sms_messagebird/odoo/addons/sms_messagebird b/setup/sms_messagebird/odoo/addons/sms_messagebird new file mode 120000 index 000000000..0c27a6b58 --- /dev/null +++ b/setup/sms_messagebird/odoo/addons/sms_messagebird @@ -0,0 +1 @@ +../../../../sms_messagebird \ No newline at end of file diff --git a/setup/sms_messagebird/setup.py b/setup/sms_messagebird/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sms_messagebird/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/sms_messagebird/README.rst b/sms_messagebird/README.rst new file mode 100644 index 000000000..03a061893 --- /dev/null +++ b/sms_messagebird/README.rst @@ -0,0 +1,98 @@ +========================= +SMS provider: Messagebird +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:211fd292e6cdc76561c38b96220576ac59ab58d5011a1ddfa7d5b7ef3bb13588 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github + :target: https://github.com/OCA/connector-telephony/tree/16.0/sms_messagebird + :alt: OCA/connector-telephony +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/connector-telephony-16-0/connector-telephony-16-0-sms_messagebird + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds messagebird as SMS provider. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +1. Go to Settings / Technical / Phone/SMS / SMS providers +2. Create a gateway of type Messagebird, fill in your api key + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Hunki Enterprises BV + +Contributors +------------ + +- Holger Brunn + (https://hunki-enterprises.com) + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px + :target: https://github.com/hbrunn + :alt: hbrunn + +Current `maintainer `__: + +|maintainer-hbrunn| + +This module is part of the `OCA/connector-telephony `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sms_messagebird/__init__.py b/sms_messagebird/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sms_messagebird/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sms_messagebird/__manifest__.py b/sms_messagebird/__manifest__.py new file mode 100644 index 000000000..c1ec36d30 --- /dev/null +++ b/sms_messagebird/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +{ + "name": "SMS provider: Messagebird", + "summary": "Send SMS via messagebird.com", + "version": "16.0.1.0.0", + "development_status": "Alpha", + "category": "Tools", + "website": "https://github.com/OCA/connector-telephony", + "author": "Hunki Enterprises BV, Odoo Community Association (OCA)", + "maintainers": ["hbrunn"], + "license": "AGPL-3", + "depends": [ + "sms_alternative_provider", + ], + "data": [ + "views/ir_sms_gateway.xml", + ], +} diff --git a/sms_messagebird/models/__init__.py b/sms_messagebird/models/__init__.py new file mode 100644 index 000000000..963133df2 --- /dev/null +++ b/sms_messagebird/models/__init__.py @@ -0,0 +1 @@ +from . import ir_sms_gateway diff --git a/sms_messagebird/models/ir_sms_gateway.py b/sms_messagebird/models/ir_sms_gateway.py new file mode 100644 index 000000000..fa7635e8b --- /dev/null +++ b/sms_messagebird/models/ir_sms_gateway.py @@ -0,0 +1,59 @@ +# Copyright 2024 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +import logging + +import requests + +from odoo import fields, models + +_logger = logging.getLogger(__name__) + + +class IrSmsGateway(models.Model): + + _inherit = "ir.sms.gateway" + + gateway_type = fields.Selection( + selection_add=[("messagebird", "Messagebird")], + ondelete={"messagebird": "cascade"}, + ) + messagebird_apikey = fields.Char("API key") + + def _send_messagebird(self, messages): + apikey = self.messagebird_apikey + result = [] + for message in messages: + # TODO: use batch api + response = requests.post( + "https://rest.messagebird.com/messages", + headers={ + "Authorization": "AccessKey %s" % apikey, + }, + data={ + "originator": self.env.user.company_id.phone + or self.env.user.company_id.name[:11], + "recipients": message["number"], + "body": message["content"], + }, + timeout=100, + ) + data = response.json() + _logger.debug(data) + if data.get("errors"): + _logger.error(data["errors"]) + result.append( + { + "id": message.get("id"), + "state": "error", + "failure_type": "sms_server", + } + ) + else: + result.append( + { + "id": message.get("id"), + "state": "sent", + } + ) + return result diff --git a/sms_messagebird/readme/CONFIGURE.md b/sms_messagebird/readme/CONFIGURE.md new file mode 100644 index 000000000..2ec312dab --- /dev/null +++ b/sms_messagebird/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +To configure this module, you need to: + +1. Go to Settings / Technical / Phone/SMS / SMS providers +2. Create a gateway of type Messagebird, fill in your api key diff --git a/sms_messagebird/readme/CONTRIBUTORS.md b/sms_messagebird/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..b28199e1f --- /dev/null +++ b/sms_messagebird/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Holger Brunn \ (https://hunki-enterprises.com) diff --git a/sms_messagebird/readme/DESCRIPTION.md b/sms_messagebird/readme/DESCRIPTION.md new file mode 100644 index 000000000..cd4694894 --- /dev/null +++ b/sms_messagebird/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module adds messagebird as SMS provider. diff --git a/sms_messagebird/security/ir.model.access.csv b/sms_messagebird/security/ir.model.access.csv new file mode 100644 index 000000000..97ff099f4 --- /dev/null +++ b/sms_messagebird/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_ir_sms_gateway,access_ir_sms_gateway,sms_alternative_provider.model_ir_sms_gateway,base.group_system,1,1,1,1 diff --git a/sms_messagebird/static/description/icon.png b/sms_messagebird/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sms_messagebird/static/description/icon.png differ diff --git a/sms_messagebird/static/description/index.html b/sms_messagebird/static/description/index.html new file mode 100644 index 000000000..4b1861cd5 --- /dev/null +++ b/sms_messagebird/static/description/index.html @@ -0,0 +1,438 @@ + + + + + +SMS provider: Messagebird + + + +
+

SMS provider: Messagebird

+ + +

Alpha License: AGPL-3 OCA/connector-telephony Translate me on Weblate Try me on Runboat

+

This module adds messagebird as SMS provider.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to Settings / Technical / Phone/SMS / SMS providers
  2. +
  3. Create a gateway of type Messagebird, fill in your api key
  4. +
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Hunki Enterprises BV
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

hbrunn

+

This module is part of the OCA/connector-telephony project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sms_messagebird/tests/__init__.py b/sms_messagebird/tests/__init__.py new file mode 100644 index 000000000..23666c2ef --- /dev/null +++ b/sms_messagebird/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sms_messagebird diff --git a/sms_messagebird/tests/test_sms_messagebird.py b/sms_messagebird/tests/test_sms_messagebird.py new file mode 100644 index 000000000..74f6535f5 --- /dev/null +++ b/sms_messagebird/tests/test_sms_messagebird.py @@ -0,0 +1,50 @@ +# Copyright 2024 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from unittest.mock import patch + +from odoo.tests.common import TransactionCase + +from odoo.addons.sms_alternative_provider.tests.test_sms_alternative_provider import ( + iap_post as messagebird_post, +) + + +@patch("odoo.addons.sms_messagebird.models.ir_sms_gateway.requests.post") +class TestSmsMessagebird(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env["ir.sms.gateway"].search([]).unlink() + cls.provider = cls.env["ir.sms.gateway"].create( + { + "name": "messagebird test provider", + "gateway_type": "messagebird", + "messagebird_apikey": "42", + } + ) + + def test_success(self, patched_post): + """Test sending an SMS successfully""" + sms = self.env["sms.sms"].create({"number": "424242", "body": "hello world"}) + patched_post.side_effect = messagebird_post( + {"recipients": {"items": [{"recipient": "424242", "status": "sent"}]}} + ) + sms.send(unlink_sent=False) + self.assertEqual(sms.state, "sent") + self.assertEqual(sms.sms_gateway_id, self.provider) + + def test_failure(self, patched_post): + """Test sending an SMS with errors""" + sms = self.env["sms.sms"].create({"number": "+1 424242", "body": "hello world"}) + patched_post.side_effect = messagebird_post( + {"errors": {"description": "messagebird error"}}, + ) + + with self.assertLogs( + "odoo.addons.sms_messagebird.models.ir_sms_gateway" + ) as sms_logs: + sms.send() + self.assertTrue(any("messagebird error" in log for log in sms_logs.output)) + self.assertEqual(sms.state, "error") + self.assertEqual(sms.failure_type, "sms_server") diff --git a/sms_messagebird/views/ir_sms_gateway.xml b/sms_messagebird/views/ir_sms_gateway.xml new file mode 100644 index 000000000..e035df030 --- /dev/null +++ b/sms_messagebird/views/ir_sms_gateway.xml @@ -0,0 +1,26 @@ + + + + + ir.sms.gateway + + + + + + + + + +