django-sslwireless-sms 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_sslwireless_sms-0.1.0/.github/dependabot.yml +12 -0
- django_sslwireless_sms-0.1.0/.github/workflows/publish.yml +130 -0
- django_sslwireless_sms-0.1.0/.gitignore +10 -0
- django_sslwireless_sms-0.1.0/LICENSE +21 -0
- django_sslwireless_sms-0.1.0/PKG-INFO +217 -0
- django_sslwireless_sms-0.1.0/README.md +187 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/__init__.py +80 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/apps.py +9 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/backends/__init__.py +13 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/backends/api.py +66 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/backends/base.py +86 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/backends/console.py +22 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/backends/locmem.py +13 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/checks.py +34 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/client.py +178 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/conf.py +27 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/crypto.py +64 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/exceptions.py +80 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/py.typed +0 -0
- django_sslwireless_sms-0.1.0/django_sslwireless_sms/results.py +106 -0
- django_sslwireless_sms-0.1.0/pyproject.toml +61 -0
- django_sslwireless_sms-0.1.0/tests/__init__.py +0 -0
- django_sslwireless_sms-0.1.0/tests/conftest.py +18 -0
- django_sslwireless_sms-0.1.0/tests/settings.py +9 -0
- django_sslwireless_sms-0.1.0/tests/test_backends.py +164 -0
- django_sslwireless_sms-0.1.0/tests/test_checks.py +32 -0
- django_sslwireless_sms-0.1.0/tests/test_client.py +328 -0
- django_sslwireless_sms-0.1.0/tests/test_crypto.py +68 -0
- django_sslwireless_sms-0.1.0/tests/test_integration.py +87 -0
- django_sslwireless_sms-0.1.0/uv.lock +711 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Every push to main runs the tests and builds the package. It is published to
|
|
4
|
+
# TestPyPI and then PyPI only when __version__ is not on PyPI yet, so pushes
|
|
5
|
+
# without a version bump skip publishing.
|
|
6
|
+
#
|
|
7
|
+
# Trusted publishers on pypi.org and test.pypi.org must use this workflow
|
|
8
|
+
# filename (publish.yml) and the environments "pypi" and "testpypi".
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [main]
|
|
13
|
+
|
|
14
|
+
concurrency:
|
|
15
|
+
group: publish
|
|
16
|
+
cancel-in-progress: false
|
|
17
|
+
|
|
18
|
+
permissions: {}
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
test:
|
|
22
|
+
name: Test (Python ${{ matrix.python }}, Django ${{ matrix.django }})
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
permissions:
|
|
25
|
+
contents: read
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: false
|
|
28
|
+
matrix:
|
|
29
|
+
include:
|
|
30
|
+
- python: "3.10"
|
|
31
|
+
django: "4.2"
|
|
32
|
+
- python: "3.14"
|
|
33
|
+
django: "6.1"
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
36
|
+
with:
|
|
37
|
+
persist-credentials: false
|
|
38
|
+
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
|
|
39
|
+
with:
|
|
40
|
+
python-version: ${{ matrix.python }}
|
|
41
|
+
enable-cache: false
|
|
42
|
+
- name: Install dependencies
|
|
43
|
+
env:
|
|
44
|
+
DJANGO_VERSION: ${{ matrix.django }}
|
|
45
|
+
run: |
|
|
46
|
+
uv sync --locked
|
|
47
|
+
uv pip install "django~=${DJANGO_VERSION}.0"
|
|
48
|
+
- name: Run unit tests
|
|
49
|
+
run: uv run --no-sync pytest
|
|
50
|
+
|
|
51
|
+
build:
|
|
52
|
+
name: Build
|
|
53
|
+
needs: test
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
permissions:
|
|
56
|
+
contents: read
|
|
57
|
+
outputs:
|
|
58
|
+
version: ${{ steps.version.outputs.version }}
|
|
59
|
+
publish: ${{ steps.version.outputs.publish }}
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
62
|
+
with:
|
|
63
|
+
persist-credentials: false
|
|
64
|
+
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
|
|
65
|
+
with:
|
|
66
|
+
enable-cache: false
|
|
67
|
+
- name: Build
|
|
68
|
+
run: uv build
|
|
69
|
+
- name: Check distributions
|
|
70
|
+
run: uvx twine check dist/*
|
|
71
|
+
- name: Decide whether to publish
|
|
72
|
+
id: version
|
|
73
|
+
run: |
|
|
74
|
+
version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' django_sslwireless_sms/__init__.py)
|
|
75
|
+
test -f "dist/django_sslwireless_sms-${version}-py3-none-any.whl"
|
|
76
|
+
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
|
77
|
+
status=$(curl -s -o /dev/null -w '%{http_code}' "https://pypi.org/pypi/django-sslwireless-sms/${version}/json")
|
|
78
|
+
case "$status" in
|
|
79
|
+
404)
|
|
80
|
+
echo "publish=true" >> "$GITHUB_OUTPUT"
|
|
81
|
+
echo "::notice::Publishing django-sslwireless-sms ${version}" ;;
|
|
82
|
+
200)
|
|
83
|
+
echo "publish=false" >> "$GITHUB_OUTPUT"
|
|
84
|
+
echo "::notice::Version ${version} is already on PyPI, so publishing is skipped. Bump __version__ to release." ;;
|
|
85
|
+
*)
|
|
86
|
+
echo "::error::Could not check PyPI for version ${version} (HTTP ${status})"
|
|
87
|
+
exit 1 ;;
|
|
88
|
+
esac
|
|
89
|
+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
90
|
+
with:
|
|
91
|
+
name: dist
|
|
92
|
+
path: dist/
|
|
93
|
+
|
|
94
|
+
publish-testpypi:
|
|
95
|
+
name: Publish to TestPyPI
|
|
96
|
+
needs: build
|
|
97
|
+
if: needs.build.outputs.publish == 'true'
|
|
98
|
+
runs-on: ubuntu-latest
|
|
99
|
+
environment:
|
|
100
|
+
name: testpypi
|
|
101
|
+
url: https://test.pypi.org/project/django-sslwireless-sms/${{ needs.build.outputs.version }}/
|
|
102
|
+
permissions:
|
|
103
|
+
id-token: write
|
|
104
|
+
steps:
|
|
105
|
+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
106
|
+
with:
|
|
107
|
+
name: dist
|
|
108
|
+
path: dist/
|
|
109
|
+
- uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
|
|
110
|
+
with:
|
|
111
|
+
repository-url: https://test.pypi.org/legacy/
|
|
112
|
+
# Lets a re-run continue to PyPI if TestPyPI already has this version.
|
|
113
|
+
skip-existing: true
|
|
114
|
+
|
|
115
|
+
publish-pypi:
|
|
116
|
+
name: Publish to PyPI
|
|
117
|
+
needs: [build, publish-testpypi]
|
|
118
|
+
if: needs.build.outputs.publish == 'true'
|
|
119
|
+
runs-on: ubuntu-latest
|
|
120
|
+
environment:
|
|
121
|
+
name: pypi
|
|
122
|
+
url: https://pypi.org/project/django-sslwireless-sms/${{ needs.build.outputs.version }}/
|
|
123
|
+
permissions:
|
|
124
|
+
id-token: write
|
|
125
|
+
steps:
|
|
126
|
+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
127
|
+
with:
|
|
128
|
+
name: dist
|
|
129
|
+
path: dist/
|
|
130
|
+
- uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anik Sharif
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: django-sslwireless-sms
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Django integration for the SSL Wireless ISMS Plus SMS API v3: single, bulk, dynamic and secure OTP messages.
|
|
5
|
+
Project-URL: Homepage, https://github.com/aniksharif/django-sslwireless-sms
|
|
6
|
+
Project-URL: Repository, https://github.com/aniksharif/django-sslwireless-sms
|
|
7
|
+
Project-URL: Issues, https://github.com/aniksharif/django-sslwireless-sms/issues
|
|
8
|
+
Project-URL: API documentation, https://ismsplus.sslwireless.com/api-documentation
|
|
9
|
+
Author-email: Anik Sharif <aniksharif@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: bangladesh,django,isms plus,otp,sms,ssl wireless
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Web Environment
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Framework :: Django :: 4.2
|
|
17
|
+
Classifier: Framework :: Django :: 5.2
|
|
18
|
+
Classifier: Framework :: Django :: 6.0
|
|
19
|
+
Classifier: Framework :: Django :: 6.1
|
|
20
|
+
Classifier: Intended Audience :: Developers
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Topic :: Communications :: Telephony
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: cryptography>=41
|
|
27
|
+
Requires-Dist: django>=4.2
|
|
28
|
+
Requires-Dist: requests>=2.28
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# django-sslwireless-sms
|
|
32
|
+
|
|
33
|
+
Django integration for the [SSL Wireless ISMS Plus SMS API v3](https://ismsplus.sslwireless.com/api-documentation).
|
|
34
|
+
|
|
35
|
+
| Function | Endpoint | Use for |
|
|
36
|
+
| ------------------ | ------------------------ | ------------------------------------------------- |
|
|
37
|
+
| `send_sms` | `POST /send-sms` | One message to one recipient |
|
|
38
|
+
| `send_bulk_sms` | `POST /send-sms/bulk` | The same message to up to 100 recipients |
|
|
39
|
+
| `send_dynamic_sms` | `POST /send-sms/dynamic` | Up to 100 different messages in one request |
|
|
40
|
+
| `send_otp` | `POST /secure/otp-sms` | OTPs: AES-256-CBC encrypted body + `X-Signature` |
|
|
41
|
+
|
|
42
|
+
Requires Python 3.10+ and Django 4.2+.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install django-sslwireless-sms
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
# settings.py
|
|
52
|
+
INSTALLED_APPS = [
|
|
53
|
+
# ...
|
|
54
|
+
"django_sslwireless_sms", # optional; enables system checks for the settings below
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
SSLWIRELESS_SMS = {
|
|
58
|
+
"API_TOKEN": os.environ["SSLWIRELESS_SMS_API_TOKEN"],
|
|
59
|
+
"SID": os.environ["SSLWIRELESS_SMS_SID"],
|
|
60
|
+
"SECRET_KEY": os.environ.get("SSLWIRELESS_SMS_SECRET_KEY", ""), # only needed for send_otp
|
|
61
|
+
# Optional. Empty or unset uses https://smsplus.sslwireless.com/api/v3
|
|
62
|
+
"BASE_URL": os.environ.get("SSLWIRELESS_SMS_BASE_URL", ""),
|
|
63
|
+
"TIMEOUT": os.environ.get("SSLWIRELESS_SMS_TIMEOUT", 10), # seconds
|
|
64
|
+
# "BACKEND": "django_sslwireless_sms.backends.api.SSLWirelessBackend", # default
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The API only accepts requests from IPs whitelisted in the ISMS Plus portal.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from django_sslwireless_sms import send_sms, send_bulk_sms, send_dynamic_sms, send_otp
|
|
74
|
+
|
|
75
|
+
send_sms("8801712345678", "Your order has shipped", csms_id="order-1042")
|
|
76
|
+
|
|
77
|
+
send_bulk_sms(["8801712345678", "8801812345678"], "We are closed on Friday")
|
|
78
|
+
|
|
79
|
+
send_dynamic_sms([
|
|
80
|
+
{"msisdn": "8801712345678", "text": "Hi John, your balance is 120 BDT"},
|
|
81
|
+
{"msisdn": "8801812345678", "text": "Hi Jane, your balance is 80 BDT", "csms_id": "bal-2"},
|
|
82
|
+
])
|
|
83
|
+
|
|
84
|
+
send_otp("8801712345678", "Your login code is 482913")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`csms_id` is your unique reference for a message (at most 20 characters). If you leave it
|
|
88
|
+
out, a random one is generated. Batch size (100) and `csms_id` length are checked before
|
|
89
|
+
anything is sent, and violations raise `ValueError`.
|
|
90
|
+
|
|
91
|
+
### Results
|
|
92
|
+
|
|
93
|
+
Every call returns a `SendResult`:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
result = send_bulk_sms(numbers, "Hello")
|
|
97
|
+
result.status_code # 200
|
|
98
|
+
for info in result.smsinfo: # one SMSInfo per recipient
|
|
99
|
+
info.msisdn, info.sms_status, info.csms_id, info.reference_id
|
|
100
|
+
result.failed # recipients the API did not accept
|
|
101
|
+
result.raw # the decoded JSON
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Errors
|
|
105
|
+
|
|
106
|
+
When the API answers `"status": "FAILED"`, the call raises a subclass of `SSLWirelessAPIError`.
|
|
107
|
+
The error carries `.status_code`, `.error_message`, and the parsed `.result`.
|
|
108
|
+
|
|
109
|
+
| Exception | Status codes |
|
|
110
|
+
| ----------------------- | -------------------------------------------------------- |
|
|
111
|
+
| `AuthenticationError` | 4001 unauthorized, 4002 SID not permitted, 4003 IP not whitelisted |
|
|
112
|
+
| `RateLimitError` | 4029, 4031 TPS, 4033 too many OTPs to one recipient |
|
|
113
|
+
| `SignatureError` | 4034 can't decrypt SMS, 4035 signature mismatch |
|
|
114
|
+
| `ServerError` | 5000 |
|
|
115
|
+
| `InvalidRequestError` | Any other 4xxx (invalid MSISDN, duplicate `csms_id`, ...) |
|
|
116
|
+
|
|
117
|
+
The other errors are:
|
|
118
|
+
- `SSLWirelessConnectionError`: the API could not be reached.
|
|
119
|
+
- `SSLWirelessResponseError`: the API returned something other than a JSON result.
|
|
120
|
+
|
|
121
|
+
All of these errors inherit from `SSLWirelessError`. `StatusCode` lists every documented code.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from django_sslwireless_sms import RateLimitError, SSLWirelessError, StatusCode, send_otp
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
send_otp(phone, f"Your code is {code}")
|
|
128
|
+
except RateLimitError:
|
|
129
|
+
... # ask the user to wait
|
|
130
|
+
except SSLWirelessError:
|
|
131
|
+
logger.exception("OTP delivery failed")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Without Django settings
|
|
135
|
+
|
|
136
|
+
`SSLWirelessClient` has no Django dependency:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from django_sslwireless_sms import SSLWirelessClient
|
|
140
|
+
|
|
141
|
+
client = SSLWirelessClient(api_token, sid, secret_key=secret_key, timeout=5)
|
|
142
|
+
client.send_sms("8801712345678", "Hello")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Backends
|
|
146
|
+
|
|
147
|
+
Backends work like Django's email backends. Choose one with `SSLWIRELESS_SMS["BACKEND"]`, or pass
|
|
148
|
+
`backend="dotted.path"` to any `send_*` function.
|
|
149
|
+
|
|
150
|
+
| Backend | Behaviour |
|
|
151
|
+
| -------------------------------------------------------- | ---------------------------------------------------------- |
|
|
152
|
+
| `django_sslwireless_sms.backends.api.SSLWirelessBackend` | Sends through the API (default) |
|
|
153
|
+
| `django_sslwireless_sms.backends.locmem.LocmemBackend` | Stores messages in `django_sslwireless_sms.outbox` instead |
|
|
154
|
+
| `django_sslwireless_sms.backends.console.ConsoleBackend` | Prints messages to stdout instead |
|
|
155
|
+
|
|
156
|
+
The simulated backends validate input the same way the API client does. They return a
|
|
157
|
+
successful `SendResult` and need no credentials.
|
|
158
|
+
|
|
159
|
+
### Testing your project
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import django_sslwireless_sms
|
|
163
|
+
from django.test import TestCase, override_settings
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@override_settings(SSLWIRELESS_SMS={"BACKEND": "django_sslwireless_sms.backends.locmem.LocmemBackend"})
|
|
167
|
+
class SignupTests(TestCase):
|
|
168
|
+
def setUp(self):
|
|
169
|
+
django_sslwireless_sms.outbox.clear()
|
|
170
|
+
|
|
171
|
+
def test_sends_otp(self):
|
|
172
|
+
self.client.post("/signup/", {"phone": "8801712345678"})
|
|
173
|
+
[sms] = django_sslwireless_sms.outbox
|
|
174
|
+
assert sms.kind == "otp" and sms.msisdn == "8801712345678"
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
For local development, set `"BACKEND": "django_sslwireless_sms.backends.console.ConsoleBackend"`.
|
|
178
|
+
|
|
179
|
+
## Development
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
uv sync
|
|
183
|
+
uv run pytest # unit tests; HTTP is mocked, nothing leaves the machine
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The unit tests mock HTTP with [`responses`](https://github.com/getsentry/responses) and check
|
|
187
|
+
request payloads against the API documentation. The OTP encryption and signature are compared
|
|
188
|
+
with known-answer vectors from the official Python and Node.js samples.
|
|
189
|
+
|
|
190
|
+
Integration tests call the real API and are deselected by default:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
uv run pytest -m integration # without credentials: only checks that a bad token is rejected
|
|
194
|
+
|
|
195
|
+
export SSLWIRELESS_SMS_API_TOKEN=... SSLWIRELESS_SMS_SID=... SSLWIRELESS_SMS_TEST_MSISDN=8801XXXXXXXXX
|
|
196
|
+
export SSLWIRELESS_SMS_SECRET_KEY=... # optional, enables the OTP test
|
|
197
|
+
export SSLWIRELESS_SMS_BASE_URL=... # optional, overrides the default API host
|
|
198
|
+
uv run pytest -m integration # sends real SMS to SSLWIRELESS_SMS_TEST_MSISDN (uses credit)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Run the tests from a whitelisted IP.
|
|
202
|
+
|
|
203
|
+
### Releasing
|
|
204
|
+
|
|
205
|
+
Every push to `main` runs [`.github/workflows/publish.yml`](.github/workflows/publish.yml):
|
|
206
|
+
|
|
207
|
+
1. Runs the unit tests on Python 3.10 with Django 4.2 and on Python 3.14 with Django 6.1.
|
|
208
|
+
2. Builds the package and checks it with `twine check`.
|
|
209
|
+
3. Checks PyPI for `__version__` from `django_sslwireless_sms/__init__.py`. If that version isn't
|
|
210
|
+
there yet, it uploads to TestPyPI and then PyPI using trusted publishing. Otherwise it skips
|
|
211
|
+
publishing.
|
|
212
|
+
|
|
213
|
+
To release, bump `__version__` and push to `main`.
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# django-sslwireless-sms
|
|
2
|
+
|
|
3
|
+
Django integration for the [SSL Wireless ISMS Plus SMS API v3](https://ismsplus.sslwireless.com/api-documentation).
|
|
4
|
+
|
|
5
|
+
| Function | Endpoint | Use for |
|
|
6
|
+
| ------------------ | ------------------------ | ------------------------------------------------- |
|
|
7
|
+
| `send_sms` | `POST /send-sms` | One message to one recipient |
|
|
8
|
+
| `send_bulk_sms` | `POST /send-sms/bulk` | The same message to up to 100 recipients |
|
|
9
|
+
| `send_dynamic_sms` | `POST /send-sms/dynamic` | Up to 100 different messages in one request |
|
|
10
|
+
| `send_otp` | `POST /secure/otp-sms` | OTPs: AES-256-CBC encrypted body + `X-Signature` |
|
|
11
|
+
|
|
12
|
+
Requires Python 3.10+ and Django 4.2+.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install django-sslwireless-sms
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
# settings.py
|
|
22
|
+
INSTALLED_APPS = [
|
|
23
|
+
# ...
|
|
24
|
+
"django_sslwireless_sms", # optional; enables system checks for the settings below
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
SSLWIRELESS_SMS = {
|
|
28
|
+
"API_TOKEN": os.environ["SSLWIRELESS_SMS_API_TOKEN"],
|
|
29
|
+
"SID": os.environ["SSLWIRELESS_SMS_SID"],
|
|
30
|
+
"SECRET_KEY": os.environ.get("SSLWIRELESS_SMS_SECRET_KEY", ""), # only needed for send_otp
|
|
31
|
+
# Optional. Empty or unset uses https://smsplus.sslwireless.com/api/v3
|
|
32
|
+
"BASE_URL": os.environ.get("SSLWIRELESS_SMS_BASE_URL", ""),
|
|
33
|
+
"TIMEOUT": os.environ.get("SSLWIRELESS_SMS_TIMEOUT", 10), # seconds
|
|
34
|
+
# "BACKEND": "django_sslwireless_sms.backends.api.SSLWirelessBackend", # default
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The API only accepts requests from IPs whitelisted in the ISMS Plus portal.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from django_sslwireless_sms import send_sms, send_bulk_sms, send_dynamic_sms, send_otp
|
|
44
|
+
|
|
45
|
+
send_sms("8801712345678", "Your order has shipped", csms_id="order-1042")
|
|
46
|
+
|
|
47
|
+
send_bulk_sms(["8801712345678", "8801812345678"], "We are closed on Friday")
|
|
48
|
+
|
|
49
|
+
send_dynamic_sms([
|
|
50
|
+
{"msisdn": "8801712345678", "text": "Hi John, your balance is 120 BDT"},
|
|
51
|
+
{"msisdn": "8801812345678", "text": "Hi Jane, your balance is 80 BDT", "csms_id": "bal-2"},
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
send_otp("8801712345678", "Your login code is 482913")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`csms_id` is your unique reference for a message (at most 20 characters). If you leave it
|
|
58
|
+
out, a random one is generated. Batch size (100) and `csms_id` length are checked before
|
|
59
|
+
anything is sent, and violations raise `ValueError`.
|
|
60
|
+
|
|
61
|
+
### Results
|
|
62
|
+
|
|
63
|
+
Every call returns a `SendResult`:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
result = send_bulk_sms(numbers, "Hello")
|
|
67
|
+
result.status_code # 200
|
|
68
|
+
for info in result.smsinfo: # one SMSInfo per recipient
|
|
69
|
+
info.msisdn, info.sms_status, info.csms_id, info.reference_id
|
|
70
|
+
result.failed # recipients the API did not accept
|
|
71
|
+
result.raw # the decoded JSON
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Errors
|
|
75
|
+
|
|
76
|
+
When the API answers `"status": "FAILED"`, the call raises a subclass of `SSLWirelessAPIError`.
|
|
77
|
+
The error carries `.status_code`, `.error_message`, and the parsed `.result`.
|
|
78
|
+
|
|
79
|
+
| Exception | Status codes |
|
|
80
|
+
| ----------------------- | -------------------------------------------------------- |
|
|
81
|
+
| `AuthenticationError` | 4001 unauthorized, 4002 SID not permitted, 4003 IP not whitelisted |
|
|
82
|
+
| `RateLimitError` | 4029, 4031 TPS, 4033 too many OTPs to one recipient |
|
|
83
|
+
| `SignatureError` | 4034 can't decrypt SMS, 4035 signature mismatch |
|
|
84
|
+
| `ServerError` | 5000 |
|
|
85
|
+
| `InvalidRequestError` | Any other 4xxx (invalid MSISDN, duplicate `csms_id`, ...) |
|
|
86
|
+
|
|
87
|
+
The other errors are:
|
|
88
|
+
- `SSLWirelessConnectionError`: the API could not be reached.
|
|
89
|
+
- `SSLWirelessResponseError`: the API returned something other than a JSON result.
|
|
90
|
+
|
|
91
|
+
All of these errors inherit from `SSLWirelessError`. `StatusCode` lists every documented code.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from django_sslwireless_sms import RateLimitError, SSLWirelessError, StatusCode, send_otp
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
send_otp(phone, f"Your code is {code}")
|
|
98
|
+
except RateLimitError:
|
|
99
|
+
... # ask the user to wait
|
|
100
|
+
except SSLWirelessError:
|
|
101
|
+
logger.exception("OTP delivery failed")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Without Django settings
|
|
105
|
+
|
|
106
|
+
`SSLWirelessClient` has no Django dependency:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from django_sslwireless_sms import SSLWirelessClient
|
|
110
|
+
|
|
111
|
+
client = SSLWirelessClient(api_token, sid, secret_key=secret_key, timeout=5)
|
|
112
|
+
client.send_sms("8801712345678", "Hello")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Backends
|
|
116
|
+
|
|
117
|
+
Backends work like Django's email backends. Choose one with `SSLWIRELESS_SMS["BACKEND"]`, or pass
|
|
118
|
+
`backend="dotted.path"` to any `send_*` function.
|
|
119
|
+
|
|
120
|
+
| Backend | Behaviour |
|
|
121
|
+
| -------------------------------------------------------- | ---------------------------------------------------------- |
|
|
122
|
+
| `django_sslwireless_sms.backends.api.SSLWirelessBackend` | Sends through the API (default) |
|
|
123
|
+
| `django_sslwireless_sms.backends.locmem.LocmemBackend` | Stores messages in `django_sslwireless_sms.outbox` instead |
|
|
124
|
+
| `django_sslwireless_sms.backends.console.ConsoleBackend` | Prints messages to stdout instead |
|
|
125
|
+
|
|
126
|
+
The simulated backends validate input the same way the API client does. They return a
|
|
127
|
+
successful `SendResult` and need no credentials.
|
|
128
|
+
|
|
129
|
+
### Testing your project
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import django_sslwireless_sms
|
|
133
|
+
from django.test import TestCase, override_settings
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@override_settings(SSLWIRELESS_SMS={"BACKEND": "django_sslwireless_sms.backends.locmem.LocmemBackend"})
|
|
137
|
+
class SignupTests(TestCase):
|
|
138
|
+
def setUp(self):
|
|
139
|
+
django_sslwireless_sms.outbox.clear()
|
|
140
|
+
|
|
141
|
+
def test_sends_otp(self):
|
|
142
|
+
self.client.post("/signup/", {"phone": "8801712345678"})
|
|
143
|
+
[sms] = django_sslwireless_sms.outbox
|
|
144
|
+
assert sms.kind == "otp" and sms.msisdn == "8801712345678"
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
For local development, set `"BACKEND": "django_sslwireless_sms.backends.console.ConsoleBackend"`.
|
|
148
|
+
|
|
149
|
+
## Development
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
uv sync
|
|
153
|
+
uv run pytest # unit tests; HTTP is mocked, nothing leaves the machine
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The unit tests mock HTTP with [`responses`](https://github.com/getsentry/responses) and check
|
|
157
|
+
request payloads against the API documentation. The OTP encryption and signature are compared
|
|
158
|
+
with known-answer vectors from the official Python and Node.js samples.
|
|
159
|
+
|
|
160
|
+
Integration tests call the real API and are deselected by default:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
uv run pytest -m integration # without credentials: only checks that a bad token is rejected
|
|
164
|
+
|
|
165
|
+
export SSLWIRELESS_SMS_API_TOKEN=... SSLWIRELESS_SMS_SID=... SSLWIRELESS_SMS_TEST_MSISDN=8801XXXXXXXXX
|
|
166
|
+
export SSLWIRELESS_SMS_SECRET_KEY=... # optional, enables the OTP test
|
|
167
|
+
export SSLWIRELESS_SMS_BASE_URL=... # optional, overrides the default API host
|
|
168
|
+
uv run pytest -m integration # sends real SMS to SSLWIRELESS_SMS_TEST_MSISDN (uses credit)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Run the tests from a whitelisted IP.
|
|
172
|
+
|
|
173
|
+
### Releasing
|
|
174
|
+
|
|
175
|
+
Every push to `main` runs [`.github/workflows/publish.yml`](.github/workflows/publish.yml):
|
|
176
|
+
|
|
177
|
+
1. Runs the unit tests on Python 3.10 with Django 4.2 and on Python 3.14 with Django 6.1.
|
|
178
|
+
2. Builds the package and checks it with `twine check`.
|
|
179
|
+
3. Checks PyPI for `__version__` from `django_sslwireless_sms/__init__.py`. If that version isn't
|
|
180
|
+
there yet, it uploads to TestPyPI and then PyPI using trusted publishing. Otherwise it skips
|
|
181
|
+
publishing.
|
|
182
|
+
|
|
183
|
+
To release, bump `__version__` and push to `main`.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Django integration for the SSL Wireless ISMS Plus SMS API (v3)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable, Mapping
|
|
6
|
+
|
|
7
|
+
from .backends import get_backend
|
|
8
|
+
from .backends.base import SentSMS
|
|
9
|
+
from .backends.locmem import outbox
|
|
10
|
+
from .client import SSLWirelessClient
|
|
11
|
+
from .exceptions import (
|
|
12
|
+
AuthenticationError,
|
|
13
|
+
InvalidRequestError,
|
|
14
|
+
RateLimitError,
|
|
15
|
+
ServerError,
|
|
16
|
+
SignatureError,
|
|
17
|
+
SSLWirelessAPIError,
|
|
18
|
+
SSLWirelessConnectionError,
|
|
19
|
+
SSLWirelessError,
|
|
20
|
+
SSLWirelessResponseError,
|
|
21
|
+
)
|
|
22
|
+
from .results import SendResult, SMSInfo, SMSStatus, StatusCode
|
|
23
|
+
|
|
24
|
+
__version__ = "0.1.0"
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"AuthenticationError",
|
|
28
|
+
"InvalidRequestError",
|
|
29
|
+
"RateLimitError",
|
|
30
|
+
"SMSInfo",
|
|
31
|
+
"SMSStatus",
|
|
32
|
+
"SSLWirelessAPIError",
|
|
33
|
+
"SSLWirelessClient",
|
|
34
|
+
"SSLWirelessConnectionError",
|
|
35
|
+
"SSLWirelessError",
|
|
36
|
+
"SSLWirelessResponseError",
|
|
37
|
+
"SendResult",
|
|
38
|
+
"SentSMS",
|
|
39
|
+
"ServerError",
|
|
40
|
+
"SignatureError",
|
|
41
|
+
"StatusCode",
|
|
42
|
+
"get_backend",
|
|
43
|
+
"outbox",
|
|
44
|
+
"send_bulk_sms",
|
|
45
|
+
"send_dynamic_sms",
|
|
46
|
+
"send_otp",
|
|
47
|
+
"send_sms",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def send_sms(
|
|
52
|
+
msisdn: str | int, text: str, *, csms_id: str | None = None, backend: str | None = None
|
|
53
|
+
) -> SendResult:
|
|
54
|
+
"""Send one SMS to one recipient."""
|
|
55
|
+
return get_backend(backend).send_sms(msisdn, text, csms_id=csms_id)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def send_bulk_sms(
|
|
59
|
+
msisdns: Iterable[str | int],
|
|
60
|
+
text: str,
|
|
61
|
+
*,
|
|
62
|
+
batch_csms_id: str | None = None,
|
|
63
|
+
backend: str | None = None,
|
|
64
|
+
) -> SendResult:
|
|
65
|
+
"""Send the same SMS to up to 100 recipients."""
|
|
66
|
+
return get_backend(backend).send_bulk_sms(msisdns, text, batch_csms_id=batch_csms_id)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def send_dynamic_sms(
|
|
70
|
+
messages: Iterable[Mapping[str, str]], *, backend: str | None = None
|
|
71
|
+
) -> SendResult:
|
|
72
|
+
"""Send up to 100 personalised messages (``{"msisdn", "text", "csms_id"?}`` mappings)."""
|
|
73
|
+
return get_backend(backend).send_dynamic_sms(messages)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def send_otp(
|
|
77
|
+
msisdn: str | int, text: str, *, csms_id: str | None = None, backend: str | None = None
|
|
78
|
+
) -> SendResult:
|
|
79
|
+
"""Send an OTP through the encrypted, signed ``secure/otp-sms`` endpoint."""
|
|
80
|
+
return get_backend(backend).send_otp(msisdn, text, csms_id=csms_id)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from django.utils.module_loading import import_string
|
|
6
|
+
|
|
7
|
+
from ..conf import get_settings
|
|
8
|
+
from .base import BaseSMSBackend
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_backend(backend: str | None = None, **options: Any) -> BaseSMSBackend:
|
|
12
|
+
"""Instantiate ``backend`` (a dotted path), defaulting to ``SSLWIRELESS_SMS['BACKEND']``."""
|
|
13
|
+
return import_string(backend or get_settings()["BACKEND"])(**options)
|